From 9c3d4ef2a6406a7d7f1af390649e55ab05fcd047 Mon Sep 17 00:00:00 2001 From: Aliaksei Zhuk Date: Tue, 4 Jan 2022 12:55:18 +0300 Subject: [PATCH] Parse integer array query parameters. Fix typos (#11105) --- .../src/main/resources/go-server/api.mustache | 2 +- .../go-server/controller-api.mustache | 27 +++++++++++++++++-- .../main/resources/go-server/helpers.mustache | 4 +-- .../main/resources/go-server/impl.mustache | 2 +- .../server/petstore/go-api-server/go/api.go | 6 ++--- .../petstore/go-api-server/go/api_pet.go | 2 +- .../petstore/go-api-server/go/api_store.go | 2 +- .../petstore/go-api-server/go/api_user.go | 2 +- .../petstore/go-api-server/go/helpers.go | 4 +-- .../server/petstore/go-api-server/go/impl.go | 2 +- .../server/petstore/go-chi-server/go/api.go | 6 ++--- .../petstore/go-chi-server/go/api_pet.go | 2 +- .../petstore/go-chi-server/go/api_store.go | 2 +- .../petstore/go-chi-server/go/api_user.go | 2 +- .../petstore/go-chi-server/go/helpers.go | 4 +-- .../server/petstore/go-chi-server/go/impl.go | 2 +- .../petstore/go-server-required/go/api.go | 6 ++--- .../petstore/go-server-required/go/api_pet.go | 2 +- .../go-server-required/go/api_store.go | 2 +- .../go-server-required/go/api_user.go | 2 +- .../petstore/go-server-required/go/helpers.go | 4 +-- .../petstore/go-server-required/go/impl.go | 2 +- 22 files changed, 56 insertions(+), 33 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/go-server/api.mustache b/modules/openapi-generator/src/main/resources/go-server/api.mustache index b0ae118950dc..da459dc40e0f 100644 --- a/modules/openapi-generator/src/main/resources/go-server/api.mustache +++ b/modules/openapi-generator/src/main/resources/go-server/api.mustache @@ -22,7 +22,7 @@ type {{classname}}Router interface { {{#operations}}{{#operation}} // {{classname}}Servicer defines the api actions for the {{classname}} service // This interface intended to stay up to date with the openapi yaml used to generate it, -// while the service implementation can ignored with the .openapi-generator-ignore file +// while the service implementation can be ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. type {{classname}}Servicer interface { {{#operations}}{{#operation}} {{#isDeprecated}} diff --git a/modules/openapi-generator/src/main/resources/go-server/controller-api.mustache b/modules/openapi-generator/src/main/resources/go-server/controller-api.mustache index dfc0fd049a28..f7b32e623d4d 100644 --- a/modules/openapi-generator/src/main/resources/go-server/controller-api.mustache +++ b/modules/openapi-generator/src/main/resources/go-server/controller-api.mustache @@ -46,7 +46,7 @@ func New{{classname}}Controller(s {{classname}}Servicer, opts ...{{classname}}Op return controller } -// Routes returns all of the api route for the {{classname}}Controller +// Routes returns all the api routes for the {{classname}}Controller func (c *{{classname}}Controller) Routes() Routes { return Routes{ {{#operations}}{{#operation}} { @@ -130,10 +130,33 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re return } {{/isBoolean}} + {{#isArray}} + {{#items.isLong}} + {{paramName}}Param, err := parseInt64ArrayParameter(query.Get("{{baseName}}"), ",", {{required}}) + if err != nil { + c.errorHandler(w, r, &ParsingError{Err: err}, nil) + return + } + {{/items.isLong}} + {{#items.isInteger}} + {{paramName}}Param, err := parseInt32ArrayParameter(query.Get("{{baseName}}"), ",", {{required}}) + if err != nil { + c.errorHandler(w, r, &ParsingError{Err: err}, nil) + return + } + {{/items.isInteger}} + {{^items.isLong}} + {{^items.isInteger}} + {{paramName}}Param := strings.Split(query.Get("{{baseName}}"), ",") + {{/items.isInteger}} + {{/items.isLong}} + {{/isArray}} {{^isLong}} {{^isInteger}} {{^isBoolean}} - {{paramName}}Param := {{#isArray}}strings.Split({{/isArray}}query.Get("{{baseName}}"){{#isArray}}, ","){{/isArray}} + {{^isArray}} + {{paramName}}Param := query.Get("{{baseName}}") + {{/isArray}} {{/isBoolean}} {{/isInteger}} {{/isLong}} diff --git a/modules/openapi-generator/src/main/resources/go-server/helpers.mustache b/modules/openapi-generator/src/main/resources/go-server/helpers.mustache index 63b91ebb9911..6de33d11437d 100644 --- a/modules/openapi-generator/src/main/resources/go-server/helpers.mustache +++ b/modules/openapi-generator/src/main/resources/go-server/helpers.mustache @@ -32,13 +32,13 @@ func IsZeroValue(val interface{}) bool { return val == nil || reflect.DeepEqual(val, reflect.Zero(reflect.TypeOf(val)).Interface()) } -// AssertInterfaceRequired recursively checks each struct in a slice against the callback. +// AssertRecurseInterfaceRequired recursively checks each struct in a slice against the callback. // This method traverse nested slices in a preorder fashion. func AssertRecurseInterfaceRequired(obj interface{}, callback func(interface{}) error) error { return AssertRecurseValueRequired(reflect.ValueOf(obj), callback) } -// AssertNestedValueRequired checks each struct in the nested slice against the callback. +// AssertRecurseValueRequired checks each struct in the nested slice against the callback. // This method traverse nested slices in a preorder fashion. func AssertRecurseValueRequired(value reflect.Value, callback func(interface{}) error) error { switch value.Kind() { diff --git a/modules/openapi-generator/src/main/resources/go-server/impl.mustache b/modules/openapi-generator/src/main/resources/go-server/impl.mustache index 48d5a3e5e5cd..81c25ffb9739 100644 --- a/modules/openapi-generator/src/main/resources/go-server/impl.mustache +++ b/modules/openapi-generator/src/main/resources/go-server/impl.mustache @@ -1,7 +1,7 @@ {{>partial_header}} package {{packageName}} -//Implementation response defines an error code with the associated body +// ImplResponse response defines an error code with the associated body type ImplResponse struct { Code int {{#addResponseHeaders}} diff --git a/samples/server/petstore/go-api-server/go/api.go b/samples/server/petstore/go-api-server/go/api.go index c936f0b5efeb..bedb0f7985e5 100644 --- a/samples/server/petstore/go-api-server/go/api.go +++ b/samples/server/petstore/go-api-server/go/api.go @@ -57,7 +57,7 @@ type UserApiRouter interface { // PetApiServicer defines the api actions for the PetApi service // This interface intended to stay up to date with the openapi yaml used to generate it, -// while the service implementation can ignored with the .openapi-generator-ignore file +// while the service implementation can be ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. type PetApiServicer interface { AddPet(context.Context, Pet) (ImplResponse, error) @@ -74,7 +74,7 @@ type PetApiServicer interface { // StoreApiServicer defines the api actions for the StoreApi service // This interface intended to stay up to date with the openapi yaml used to generate it, -// while the service implementation can ignored with the .openapi-generator-ignore file +// while the service implementation can be ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. type StoreApiServicer interface { DeleteOrder(context.Context, string) (ImplResponse, error) @@ -86,7 +86,7 @@ type StoreApiServicer interface { // UserApiServicer defines the api actions for the UserApi service // This interface intended to stay up to date with the openapi yaml used to generate it, -// while the service implementation can ignored with the .openapi-generator-ignore file +// while the service implementation can be ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. type UserApiServicer interface { CreateUser(context.Context, User) (ImplResponse, error) diff --git a/samples/server/petstore/go-api-server/go/api_pet.go b/samples/server/petstore/go-api-server/go/api_pet.go index 537cdb586954..fb8041ee7301 100644 --- a/samples/server/petstore/go-api-server/go/api_pet.go +++ b/samples/server/petstore/go-api-server/go/api_pet.go @@ -47,7 +47,7 @@ func NewPetApiController(s PetApiServicer, opts ...PetApiOption) Router { return controller } -// Routes returns all of the api route for the PetApiController +// Routes returns all the api routes for the PetApiController func (c *PetApiController) Routes() Routes { return Routes{ { diff --git a/samples/server/petstore/go-api-server/go/api_store.go b/samples/server/petstore/go-api-server/go/api_store.go index 8c40f3e79d01..b0df49b92d31 100644 --- a/samples/server/petstore/go-api-server/go/api_store.go +++ b/samples/server/petstore/go-api-server/go/api_store.go @@ -47,7 +47,7 @@ func NewStoreApiController(s StoreApiServicer, opts ...StoreApiOption) Router { return controller } -// Routes returns all of the api route for the StoreApiController +// Routes returns all the api routes for the StoreApiController func (c *StoreApiController) Routes() Routes { return Routes{ { diff --git a/samples/server/petstore/go-api-server/go/api_user.go b/samples/server/petstore/go-api-server/go/api_user.go index 02e23c6637d8..5eb1f57d4bef 100644 --- a/samples/server/petstore/go-api-server/go/api_user.go +++ b/samples/server/petstore/go-api-server/go/api_user.go @@ -47,7 +47,7 @@ func NewUserApiController(s UserApiServicer, opts ...UserApiOption) Router { return controller } -// Routes returns all of the api route for the UserApiController +// Routes returns all the api routes for the UserApiController func (c *UserApiController) Routes() Routes { return Routes{ { diff --git a/samples/server/petstore/go-api-server/go/helpers.go b/samples/server/petstore/go-api-server/go/helpers.go index ef41ca1c8975..f18a261018dd 100644 --- a/samples/server/petstore/go-api-server/go/helpers.go +++ b/samples/server/petstore/go-api-server/go/helpers.go @@ -36,13 +36,13 @@ func IsZeroValue(val interface{}) bool { return val == nil || reflect.DeepEqual(val, reflect.Zero(reflect.TypeOf(val)).Interface()) } -// AssertInterfaceRequired recursively checks each struct in a slice against the callback. +// AssertRecurseInterfaceRequired recursively checks each struct in a slice against the callback. // This method traverse nested slices in a preorder fashion. func AssertRecurseInterfaceRequired(obj interface{}, callback func(interface{}) error) error { return AssertRecurseValueRequired(reflect.ValueOf(obj), callback) } -// AssertNestedValueRequired checks each struct in the nested slice against the callback. +// AssertRecurseValueRequired checks each struct in the nested slice against the callback. // This method traverse nested slices in a preorder fashion. func AssertRecurseValueRequired(value reflect.Value, callback func(interface{}) error) error { switch value.Kind() { diff --git a/samples/server/petstore/go-api-server/go/impl.go b/samples/server/petstore/go-api-server/go/impl.go index 1da96f41252a..8c72e26a342a 100644 --- a/samples/server/petstore/go-api-server/go/impl.go +++ b/samples/server/petstore/go-api-server/go/impl.go @@ -9,7 +9,7 @@ package petstoreserver -//Implementation response defines an error code with the associated body +// ImplResponse response defines an error code with the associated body type ImplResponse struct { Code int Headers map[string][]string diff --git a/samples/server/petstore/go-chi-server/go/api.go b/samples/server/petstore/go-chi-server/go/api.go index c936f0b5efeb..bedb0f7985e5 100644 --- a/samples/server/petstore/go-chi-server/go/api.go +++ b/samples/server/petstore/go-chi-server/go/api.go @@ -57,7 +57,7 @@ type UserApiRouter interface { // PetApiServicer defines the api actions for the PetApi service // This interface intended to stay up to date with the openapi yaml used to generate it, -// while the service implementation can ignored with the .openapi-generator-ignore file +// while the service implementation can be ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. type PetApiServicer interface { AddPet(context.Context, Pet) (ImplResponse, error) @@ -74,7 +74,7 @@ type PetApiServicer interface { // StoreApiServicer defines the api actions for the StoreApi service // This interface intended to stay up to date with the openapi yaml used to generate it, -// while the service implementation can ignored with the .openapi-generator-ignore file +// while the service implementation can be ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. type StoreApiServicer interface { DeleteOrder(context.Context, string) (ImplResponse, error) @@ -86,7 +86,7 @@ type StoreApiServicer interface { // UserApiServicer defines the api actions for the UserApi service // This interface intended to stay up to date with the openapi yaml used to generate it, -// while the service implementation can ignored with the .openapi-generator-ignore file +// while the service implementation can be ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. type UserApiServicer interface { CreateUser(context.Context, User) (ImplResponse, error) diff --git a/samples/server/petstore/go-chi-server/go/api_pet.go b/samples/server/petstore/go-chi-server/go/api_pet.go index 5fc093d2ef9c..2202804fb200 100644 --- a/samples/server/petstore/go-chi-server/go/api_pet.go +++ b/samples/server/petstore/go-chi-server/go/api_pet.go @@ -47,7 +47,7 @@ func NewPetApiController(s PetApiServicer, opts ...PetApiOption) Router { return controller } -// Routes returns all of the api route for the PetApiController +// Routes returns all the api routes for the PetApiController func (c *PetApiController) Routes() Routes { return Routes{ { diff --git a/samples/server/petstore/go-chi-server/go/api_store.go b/samples/server/petstore/go-chi-server/go/api_store.go index bbf7cd72a291..67a30090afb3 100644 --- a/samples/server/petstore/go-chi-server/go/api_store.go +++ b/samples/server/petstore/go-chi-server/go/api_store.go @@ -47,7 +47,7 @@ func NewStoreApiController(s StoreApiServicer, opts ...StoreApiOption) Router { return controller } -// Routes returns all of the api route for the StoreApiController +// Routes returns all the api routes for the StoreApiController func (c *StoreApiController) Routes() Routes { return Routes{ { diff --git a/samples/server/petstore/go-chi-server/go/api_user.go b/samples/server/petstore/go-chi-server/go/api_user.go index 872c306992b8..a48ab1c454a4 100644 --- a/samples/server/petstore/go-chi-server/go/api_user.go +++ b/samples/server/petstore/go-chi-server/go/api_user.go @@ -47,7 +47,7 @@ func NewUserApiController(s UserApiServicer, opts ...UserApiOption) Router { return controller } -// Routes returns all of the api route for the UserApiController +// Routes returns all the api routes for the UserApiController func (c *UserApiController) Routes() Routes { return Routes{ { diff --git a/samples/server/petstore/go-chi-server/go/helpers.go b/samples/server/petstore/go-chi-server/go/helpers.go index ef41ca1c8975..f18a261018dd 100644 --- a/samples/server/petstore/go-chi-server/go/helpers.go +++ b/samples/server/petstore/go-chi-server/go/helpers.go @@ -36,13 +36,13 @@ func IsZeroValue(val interface{}) bool { return val == nil || reflect.DeepEqual(val, reflect.Zero(reflect.TypeOf(val)).Interface()) } -// AssertInterfaceRequired recursively checks each struct in a slice against the callback. +// AssertRecurseInterfaceRequired recursively checks each struct in a slice against the callback. // This method traverse nested slices in a preorder fashion. func AssertRecurseInterfaceRequired(obj interface{}, callback func(interface{}) error) error { return AssertRecurseValueRequired(reflect.ValueOf(obj), callback) } -// AssertNestedValueRequired checks each struct in the nested slice against the callback. +// AssertRecurseValueRequired checks each struct in the nested slice against the callback. // This method traverse nested slices in a preorder fashion. func AssertRecurseValueRequired(value reflect.Value, callback func(interface{}) error) error { switch value.Kind() { diff --git a/samples/server/petstore/go-chi-server/go/impl.go b/samples/server/petstore/go-chi-server/go/impl.go index 1da96f41252a..8c72e26a342a 100644 --- a/samples/server/petstore/go-chi-server/go/impl.go +++ b/samples/server/petstore/go-chi-server/go/impl.go @@ -9,7 +9,7 @@ package petstoreserver -//Implementation response defines an error code with the associated body +// ImplResponse response defines an error code with the associated body type ImplResponse struct { Code int Headers map[string][]string diff --git a/samples/server/petstore/go-server-required/go/api.go b/samples/server/petstore/go-server-required/go/api.go index c936f0b5efeb..bedb0f7985e5 100644 --- a/samples/server/petstore/go-server-required/go/api.go +++ b/samples/server/petstore/go-server-required/go/api.go @@ -57,7 +57,7 @@ type UserApiRouter interface { // PetApiServicer defines the api actions for the PetApi service // This interface intended to stay up to date with the openapi yaml used to generate it, -// while the service implementation can ignored with the .openapi-generator-ignore file +// while the service implementation can be ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. type PetApiServicer interface { AddPet(context.Context, Pet) (ImplResponse, error) @@ -74,7 +74,7 @@ type PetApiServicer interface { // StoreApiServicer defines the api actions for the StoreApi service // This interface intended to stay up to date with the openapi yaml used to generate it, -// while the service implementation can ignored with the .openapi-generator-ignore file +// while the service implementation can be ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. type StoreApiServicer interface { DeleteOrder(context.Context, string) (ImplResponse, error) @@ -86,7 +86,7 @@ type StoreApiServicer interface { // UserApiServicer defines the api actions for the UserApi service // This interface intended to stay up to date with the openapi yaml used to generate it, -// while the service implementation can ignored with the .openapi-generator-ignore file +// while the service implementation can be ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. type UserApiServicer interface { CreateUser(context.Context, User) (ImplResponse, error) diff --git a/samples/server/petstore/go-server-required/go/api_pet.go b/samples/server/petstore/go-server-required/go/api_pet.go index 5fc093d2ef9c..2202804fb200 100644 --- a/samples/server/petstore/go-server-required/go/api_pet.go +++ b/samples/server/petstore/go-server-required/go/api_pet.go @@ -47,7 +47,7 @@ func NewPetApiController(s PetApiServicer, opts ...PetApiOption) Router { return controller } -// Routes returns all of the api route for the PetApiController +// Routes returns all the api routes for the PetApiController func (c *PetApiController) Routes() Routes { return Routes{ { diff --git a/samples/server/petstore/go-server-required/go/api_store.go b/samples/server/petstore/go-server-required/go/api_store.go index bbf7cd72a291..67a30090afb3 100644 --- a/samples/server/petstore/go-server-required/go/api_store.go +++ b/samples/server/petstore/go-server-required/go/api_store.go @@ -47,7 +47,7 @@ func NewStoreApiController(s StoreApiServicer, opts ...StoreApiOption) Router { return controller } -// Routes returns all of the api route for the StoreApiController +// Routes returns all the api routes for the StoreApiController func (c *StoreApiController) Routes() Routes { return Routes{ { diff --git a/samples/server/petstore/go-server-required/go/api_user.go b/samples/server/petstore/go-server-required/go/api_user.go index 872c306992b8..a48ab1c454a4 100644 --- a/samples/server/petstore/go-server-required/go/api_user.go +++ b/samples/server/petstore/go-server-required/go/api_user.go @@ -47,7 +47,7 @@ func NewUserApiController(s UserApiServicer, opts ...UserApiOption) Router { return controller } -// Routes returns all of the api route for the UserApiController +// Routes returns all the api routes for the UserApiController func (c *UserApiController) Routes() Routes { return Routes{ { diff --git a/samples/server/petstore/go-server-required/go/helpers.go b/samples/server/petstore/go-server-required/go/helpers.go index ef41ca1c8975..f18a261018dd 100644 --- a/samples/server/petstore/go-server-required/go/helpers.go +++ b/samples/server/petstore/go-server-required/go/helpers.go @@ -36,13 +36,13 @@ func IsZeroValue(val interface{}) bool { return val == nil || reflect.DeepEqual(val, reflect.Zero(reflect.TypeOf(val)).Interface()) } -// AssertInterfaceRequired recursively checks each struct in a slice against the callback. +// AssertRecurseInterfaceRequired recursively checks each struct in a slice against the callback. // This method traverse nested slices in a preorder fashion. func AssertRecurseInterfaceRequired(obj interface{}, callback func(interface{}) error) error { return AssertRecurseValueRequired(reflect.ValueOf(obj), callback) } -// AssertNestedValueRequired checks each struct in the nested slice against the callback. +// AssertRecurseValueRequired checks each struct in the nested slice against the callback. // This method traverse nested slices in a preorder fashion. func AssertRecurseValueRequired(value reflect.Value, callback func(interface{}) error) error { switch value.Kind() { diff --git a/samples/server/petstore/go-server-required/go/impl.go b/samples/server/petstore/go-server-required/go/impl.go index 1da96f41252a..8c72e26a342a 100644 --- a/samples/server/petstore/go-server-required/go/impl.go +++ b/samples/server/petstore/go-server-required/go/impl.go @@ -9,7 +9,7 @@ package petstoreserver -//Implementation response defines an error code with the associated body +// ImplResponse response defines an error code with the associated body type ImplResponse struct { Code int Headers map[string][]string