Parse integer array query parameters. Fix typos (#11105)

This commit is contained in:
Aliaksei Zhuk 2022-01-04 12:55:18 +03:00 committed by GitHub
parent 161de2cfdf
commit 9c3d4ef2a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 56 additions and 33 deletions

View File

@ -22,7 +22,7 @@ type {{classname}}Router interface { {{#operations}}{{#operation}}
// {{classname}}Servicer defines the api actions for the {{classname}} service // {{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, // 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. // and updated with the logic required for the API.
type {{classname}}Servicer interface { {{#operations}}{{#operation}} type {{classname}}Servicer interface { {{#operations}}{{#operation}}
{{#isDeprecated}} {{#isDeprecated}}

View File

@ -46,7 +46,7 @@ func New{{classname}}Controller(s {{classname}}Servicer, opts ...{{classname}}Op
return controller 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 { func (c *{{classname}}Controller) Routes() Routes {
return Routes{ {{#operations}}{{#operation}} return Routes{ {{#operations}}{{#operation}}
{ {
@ -130,10 +130,33 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re
return return
} }
{{/isBoolean}} {{/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}} {{^isLong}}
{{^isInteger}} {{^isInteger}}
{{^isBoolean}} {{^isBoolean}}
{{paramName}}Param := {{#isArray}}strings.Split({{/isArray}}query.Get("{{baseName}}"){{#isArray}}, ","){{/isArray}} {{^isArray}}
{{paramName}}Param := query.Get("{{baseName}}")
{{/isArray}}
{{/isBoolean}} {{/isBoolean}}
{{/isInteger}} {{/isInteger}}
{{/isLong}} {{/isLong}}

View File

@ -32,13 +32,13 @@ func IsZeroValue(val interface{}) bool {
return val == nil || reflect.DeepEqual(val, reflect.Zero(reflect.TypeOf(val)).Interface()) 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. // This method traverse nested slices in a preorder fashion.
func AssertRecurseInterfaceRequired(obj interface{}, callback func(interface{}) error) error { func AssertRecurseInterfaceRequired(obj interface{}, callback func(interface{}) error) error {
return AssertRecurseValueRequired(reflect.ValueOf(obj), callback) 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. // This method traverse nested slices in a preorder fashion.
func AssertRecurseValueRequired(value reflect.Value, callback func(interface{}) error) error { func AssertRecurseValueRequired(value reflect.Value, callback func(interface{}) error) error {
switch value.Kind() { switch value.Kind() {

View File

@ -1,7 +1,7 @@
{{>partial_header}} {{>partial_header}}
package {{packageName}} 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 { type ImplResponse struct {
Code int Code int
{{#addResponseHeaders}} {{#addResponseHeaders}}

View File

@ -57,7 +57,7 @@ type UserApiRouter interface {
// PetApiServicer defines the api actions for the PetApi service // 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, // 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. // and updated with the logic required for the API.
type PetApiServicer interface { type PetApiServicer interface {
AddPet(context.Context, Pet) (ImplResponse, error) AddPet(context.Context, Pet) (ImplResponse, error)
@ -74,7 +74,7 @@ type PetApiServicer interface {
// StoreApiServicer defines the api actions for the StoreApi service // 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, // 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. // and updated with the logic required for the API.
type StoreApiServicer interface { type StoreApiServicer interface {
DeleteOrder(context.Context, string) (ImplResponse, error) DeleteOrder(context.Context, string) (ImplResponse, error)
@ -86,7 +86,7 @@ type StoreApiServicer interface {
// UserApiServicer defines the api actions for the UserApi service // 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, // 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. // and updated with the logic required for the API.
type UserApiServicer interface { type UserApiServicer interface {
CreateUser(context.Context, User) (ImplResponse, error) CreateUser(context.Context, User) (ImplResponse, error)

View File

@ -47,7 +47,7 @@ func NewPetApiController(s PetApiServicer, opts ...PetApiOption) Router {
return controller 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 { func (c *PetApiController) Routes() Routes {
return Routes{ return Routes{
{ {

View File

@ -47,7 +47,7 @@ func NewStoreApiController(s StoreApiServicer, opts ...StoreApiOption) Router {
return controller 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 { func (c *StoreApiController) Routes() Routes {
return Routes{ return Routes{
{ {

View File

@ -47,7 +47,7 @@ func NewUserApiController(s UserApiServicer, opts ...UserApiOption) Router {
return controller 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 { func (c *UserApiController) Routes() Routes {
return Routes{ return Routes{
{ {

View File

@ -36,13 +36,13 @@ func IsZeroValue(val interface{}) bool {
return val == nil || reflect.DeepEqual(val, reflect.Zero(reflect.TypeOf(val)).Interface()) 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. // This method traverse nested slices in a preorder fashion.
func AssertRecurseInterfaceRequired(obj interface{}, callback func(interface{}) error) error { func AssertRecurseInterfaceRequired(obj interface{}, callback func(interface{}) error) error {
return AssertRecurseValueRequired(reflect.ValueOf(obj), callback) 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. // This method traverse nested slices in a preorder fashion.
func AssertRecurseValueRequired(value reflect.Value, callback func(interface{}) error) error { func AssertRecurseValueRequired(value reflect.Value, callback func(interface{}) error) error {
switch value.Kind() { switch value.Kind() {

View File

@ -9,7 +9,7 @@
package petstoreserver 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 { type ImplResponse struct {
Code int Code int
Headers map[string][]string Headers map[string][]string

View File

@ -57,7 +57,7 @@ type UserApiRouter interface {
// PetApiServicer defines the api actions for the PetApi service // 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, // 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. // and updated with the logic required for the API.
type PetApiServicer interface { type PetApiServicer interface {
AddPet(context.Context, Pet) (ImplResponse, error) AddPet(context.Context, Pet) (ImplResponse, error)
@ -74,7 +74,7 @@ type PetApiServicer interface {
// StoreApiServicer defines the api actions for the StoreApi service // 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, // 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. // and updated with the logic required for the API.
type StoreApiServicer interface { type StoreApiServicer interface {
DeleteOrder(context.Context, string) (ImplResponse, error) DeleteOrder(context.Context, string) (ImplResponse, error)
@ -86,7 +86,7 @@ type StoreApiServicer interface {
// UserApiServicer defines the api actions for the UserApi service // 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, // 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. // and updated with the logic required for the API.
type UserApiServicer interface { type UserApiServicer interface {
CreateUser(context.Context, User) (ImplResponse, error) CreateUser(context.Context, User) (ImplResponse, error)

View File

@ -47,7 +47,7 @@ func NewPetApiController(s PetApiServicer, opts ...PetApiOption) Router {
return controller 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 { func (c *PetApiController) Routes() Routes {
return Routes{ return Routes{
{ {

View File

@ -47,7 +47,7 @@ func NewStoreApiController(s StoreApiServicer, opts ...StoreApiOption) Router {
return controller 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 { func (c *StoreApiController) Routes() Routes {
return Routes{ return Routes{
{ {

View File

@ -47,7 +47,7 @@ func NewUserApiController(s UserApiServicer, opts ...UserApiOption) Router {
return controller 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 { func (c *UserApiController) Routes() Routes {
return Routes{ return Routes{
{ {

View File

@ -36,13 +36,13 @@ func IsZeroValue(val interface{}) bool {
return val == nil || reflect.DeepEqual(val, reflect.Zero(reflect.TypeOf(val)).Interface()) 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. // This method traverse nested slices in a preorder fashion.
func AssertRecurseInterfaceRequired(obj interface{}, callback func(interface{}) error) error { func AssertRecurseInterfaceRequired(obj interface{}, callback func(interface{}) error) error {
return AssertRecurseValueRequired(reflect.ValueOf(obj), callback) 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. // This method traverse nested slices in a preorder fashion.
func AssertRecurseValueRequired(value reflect.Value, callback func(interface{}) error) error { func AssertRecurseValueRequired(value reflect.Value, callback func(interface{}) error) error {
switch value.Kind() { switch value.Kind() {

View File

@ -9,7 +9,7 @@
package petstoreserver 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 { type ImplResponse struct {
Code int Code int
Headers map[string][]string Headers map[string][]string

View File

@ -57,7 +57,7 @@ type UserApiRouter interface {
// PetApiServicer defines the api actions for the PetApi service // 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, // 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. // and updated with the logic required for the API.
type PetApiServicer interface { type PetApiServicer interface {
AddPet(context.Context, Pet) (ImplResponse, error) AddPet(context.Context, Pet) (ImplResponse, error)
@ -74,7 +74,7 @@ type PetApiServicer interface {
// StoreApiServicer defines the api actions for the StoreApi service // 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, // 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. // and updated with the logic required for the API.
type StoreApiServicer interface { type StoreApiServicer interface {
DeleteOrder(context.Context, string) (ImplResponse, error) DeleteOrder(context.Context, string) (ImplResponse, error)
@ -86,7 +86,7 @@ type StoreApiServicer interface {
// UserApiServicer defines the api actions for the UserApi service // 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, // 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. // and updated with the logic required for the API.
type UserApiServicer interface { type UserApiServicer interface {
CreateUser(context.Context, User) (ImplResponse, error) CreateUser(context.Context, User) (ImplResponse, error)

View File

@ -47,7 +47,7 @@ func NewPetApiController(s PetApiServicer, opts ...PetApiOption) Router {
return controller 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 { func (c *PetApiController) Routes() Routes {
return Routes{ return Routes{
{ {

View File

@ -47,7 +47,7 @@ func NewStoreApiController(s StoreApiServicer, opts ...StoreApiOption) Router {
return controller 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 { func (c *StoreApiController) Routes() Routes {
return Routes{ return Routes{
{ {

View File

@ -47,7 +47,7 @@ func NewUserApiController(s UserApiServicer, opts ...UserApiOption) Router {
return controller 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 { func (c *UserApiController) Routes() Routes {
return Routes{ return Routes{
{ {

View File

@ -36,13 +36,13 @@ func IsZeroValue(val interface{}) bool {
return val == nil || reflect.DeepEqual(val, reflect.Zero(reflect.TypeOf(val)).Interface()) 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. // This method traverse nested slices in a preorder fashion.
func AssertRecurseInterfaceRequired(obj interface{}, callback func(interface{}) error) error { func AssertRecurseInterfaceRequired(obj interface{}, callback func(interface{}) error) error {
return AssertRecurseValueRequired(reflect.ValueOf(obj), callback) 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. // This method traverse nested slices in a preorder fashion.
func AssertRecurseValueRequired(value reflect.Value, callback func(interface{}) error) error { func AssertRecurseValueRequired(value reflect.Value, callback func(interface{}) error) error {
switch value.Kind() { switch value.Kind() {

View File

@ -9,7 +9,7 @@
package petstoreserver 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 { type ImplResponse struct {
Code int Code int
Headers map[string][]string Headers map[string][]string