more autogen code and slightly better test

feature-refactor
lhz 3 years ago
parent b55b239c69
commit 8ad7c50813

@ -13,7 +13,7 @@ import (
"microsrv/client/client/products"
)
// Default product client HTTP client.
// Default client HTTP client.
var Default = NewHTTPClient(nil)
const (
@ -28,14 +28,14 @@ const (
// DefaultSchemes are the default schemes found in Meta (info) section of spec file
var DefaultSchemes = []string{"http"}
// NewHTTPClient creates a new product client HTTP client.
func NewHTTPClient(formats strfmt.Registry) *ProductClient {
// NewHTTPClient creates a new client HTTP client.
func NewHTTPClient(formats strfmt.Registry) *Client {
return NewHTTPClientWithConfig(formats, nil)
}
// NewHTTPClientWithConfig creates a new product client HTTP client,
// NewHTTPClientWithConfig creates a new client HTTP client,
// using a customizable transport config.
func NewHTTPClientWithConfig(formats strfmt.Registry, cfg *TransportConfig) *ProductClient {
func NewHTTPClientWithConfig(formats strfmt.Registry, cfg *TransportConfig) *Client {
// ensure nullable parameters have default
if cfg == nil {
cfg = DefaultTransportConfig()
@ -46,14 +46,14 @@ func NewHTTPClientWithConfig(formats strfmt.Registry, cfg *TransportConfig) *Pro
return New(transport, formats)
}
// New creates a new product client client
func New(transport runtime.ClientTransport, formats strfmt.Registry) *ProductClient {
// New creates a new client client
func New(transport runtime.ClientTransport, formats strfmt.Registry) *Client {
// ensure nullable parameters have default
if formats == nil {
formats = strfmt.Default
}
cli := new(ProductClient)
cli := new(Client)
cli.Transport = transport
cli.Products = products.New(transport, formats)
return cli
@ -98,15 +98,15 @@ func (cfg *TransportConfig) WithSchemes(schemes []string) *TransportConfig {
return cfg
}
// ProductClient is a client for product client
type ProductClient struct {
// Client is a client for client
type Client struct {
Products products.ClientService
Transport runtime.ClientTransport
}
// SetTransport changes the transport on the client and all its subresources
func (c *ProductClient) SetTransport(transport runtime.ClientTransport) {
func (c *Client) SetTransport(transport runtime.ClientTransport) {
c.Transport = transport
c.Products.SetTransport(transport)
}

@ -15,6 +15,8 @@ import (
cr "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"microsrv/client/models"
)
// NewGetProductParams creates a new GetProductParams object
@ -61,6 +63,12 @@ for the get product operation typically these are written to a http.Request
*/
type GetProductParams struct {
/*Body
Product data structure to Update or Add.
Note: the id field is ignored by update and create operations
*/
Body *models.Product
/*ID
The id of the product that is operated on
@ -105,6 +113,17 @@ func (o *GetProductParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithBody adds the body to the get product params
func (o *GetProductParams) WithBody(body *models.Product) *GetProductParams {
o.SetBody(body)
return o
}
// SetBody adds the body to the get product params
func (o *GetProductParams) SetBody(body *models.Product) {
o.Body = body
}
// WithID adds the id to the get product params
func (o *GetProductParams) WithID(id int64) *GetProductParams {
o.SetID(id)
@ -124,6 +143,12 @@ func (o *GetProductParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Re
}
var res []error
if o.Body != nil {
if err := r.SetBodyParam(o.Body); err != nil {
return err
}
}
// path param id
if err := r.SetPathParam("id", swag.FormatInt64(o.ID)); err != nil {
return err

@ -10,7 +10,7 @@ import (
"github.com/go-openapi/swag"
)
// GenericError GenericError GenericError is a generic error message returned by the server
// GenericError GenericError GenericError GenericError GenericError is a generic error message returned by the server
//
// swagger:model GenericError
type GenericError struct {

@ -12,7 +12,7 @@ import (
"github.com/go-openapi/validate"
)
// Product Product product
// Product Product Product Product product
//
// swagger:model Product
type Product struct {

@ -10,7 +10,7 @@ import (
"github.com/go-openapi/swag"
)
// ValidationError ValidationError ValidationError is a collection of validation error messages
// ValidationError ValidationError ValidationError ValidationError ValidationError is a collection of validation error messages
//
// swagger:model ValidationError
type ValidationError struct {

@ -60,7 +60,7 @@ type productResponseWrapper struct {
type noContentResponseWrapper struct {
}
// swagger:parameters addProduct deleteProduct
// swagger:parameters addProduct deleteProduct getProduct
type productParamsWrapper struct {
// Product data structure to Update or Add.
// Note: the id field is ignored by update and create operations

@ -36,6 +36,8 @@ func (p *Products) GetProduct(rw http.ResponseWriter, r *http.Request) {
p.l.Println("[DEBUG] get record id", id)
rw.Header().Add("Content-Type", "application/json")
prod, err := data.GetProductByID(id)
switch err {

@ -11,13 +11,28 @@ func TestClient(t *testing.T) {
cfg := client.DefaultTransportConfig().WithHost("localhost:9090")
c := client.NewHTTPClientWithConfig(nil, cfg)
params := products.NewGetProductsParams()
prod, err := c.Products.GetProducts(params)
prodParams := products.NewGetProductParams()
prod, err := c.Products.GetProduct(prodParams)
if err != nil {
t.Fatal(err)
}
prodsParams := products.NewGetProductsParams()
prods, errs := c.Products.GetProducts(prodsParams)
if errs != nil {
t.Fatal(err)
}
fmt.Println(prod)
fmt.Printf("%#v", prod.GetPayload()[0])
//t.Fail()
fmt.Println(prods)
fmt.Printf("%#v", prod.GetPayload())
fmt.Println("")
fmt.Printf("%#v", prods.GetPayload()[3])
fmt.Println("")
//Remove if you don't want to debug
//Aka if you actually want to test
//Lmao
//Nobody tests
t.Fail()
}

@ -3,8 +3,8 @@ consumes:
- application/json
definitions:
GenericError:
description: GenericError GenericError is a generic error message returned by
the server
description: GenericError GenericError GenericError GenericError is a generic
error message returned by the server
properties:
message:
description: message
@ -13,7 +13,7 @@ definitions:
type: object
x-go-package: microsrv/client/models
Product:
description: Product product
description: Product Product Product product
properties:
desc:
description: the description for the coffee
@ -50,8 +50,8 @@ definitions:
type: object
x-go-package: microsrv/client/models
ValidationError:
description: ValidationError ValidationError is a collection of validation error
messages
description: ValidationError ValidationError ValidationError ValidationError is
a collection of validation error messages
properties:
messages:
description: messages
@ -141,6 +141,14 @@ paths:
description: Return a single product from the data store
operationId: getProduct
parameters:
- description: |-
Product data structure to Update or Add.
Note: the id field is ignored by update and create operations
in: body
name: Body
required: true
schema:
$ref: '#/definitions/Product'
- description: The id of the product that is operated on
format: int64
in: path

Loading…
Cancel
Save