Skip to content

Commit 9c3d4ef

Browse files
authored
Parse integer array query parameters. Fix typos (#11105)
1 parent 161de2c commit 9c3d4ef

File tree

22 files changed

+56
-33
lines changed

22 files changed

+56
-33
lines changed

modules/openapi-generator/src/main/resources/go-server/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type {{classname}}Router interface { {{#operations}}{{#operation}}
2222

2323
// {{classname}}Servicer defines the api actions for the {{classname}} service
2424
// This interface intended to stay up to date with the openapi yaml used to generate it,
25-
// while the service implementation can ignored with the .openapi-generator-ignore file
25+
// while the service implementation can be ignored with the .openapi-generator-ignore file
2626
// and updated with the logic required for the API.
2727
type {{classname}}Servicer interface { {{#operations}}{{#operation}}
2828
{{#isDeprecated}}

modules/openapi-generator/src/main/resources/go-server/controller-api.mustache

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func New{{classname}}Controller(s {{classname}}Servicer, opts ...{{classname}}Op
4646
return controller
4747
}
4848

49-
// Routes returns all of the api route for the {{classname}}Controller
49+
// Routes returns all the api routes for the {{classname}}Controller
5050
func (c *{{classname}}Controller) Routes() Routes {
5151
return Routes{ {{#operations}}{{#operation}}
5252
{
@@ -130,10 +130,33 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re
130130
return
131131
}
132132
{{/isBoolean}}
133+
{{#isArray}}
134+
{{#items.isLong}}
135+
{{paramName}}Param, err := parseInt64ArrayParameter(query.Get("{{baseName}}"), ",", {{required}})
136+
if err != nil {
137+
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
138+
return
139+
}
140+
{{/items.isLong}}
141+
{{#items.isInteger}}
142+
{{paramName}}Param, err := parseInt32ArrayParameter(query.Get("{{baseName}}"), ",", {{required}})
143+
if err != nil {
144+
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
145+
return
146+
}
147+
{{/items.isInteger}}
148+
{{^items.isLong}}
149+
{{^items.isInteger}}
150+
{{paramName}}Param := strings.Split(query.Get("{{baseName}}"), ",")
151+
{{/items.isInteger}}
152+
{{/items.isLong}}
153+
{{/isArray}}
133154
{{^isLong}}
134155
{{^isInteger}}
135156
{{^isBoolean}}
136-
{{paramName}}Param := {{#isArray}}strings.Split({{/isArray}}query.Get("{{baseName}}"){{#isArray}}, ","){{/isArray}}
157+
{{^isArray}}
158+
{{paramName}}Param := query.Get("{{baseName}}")
159+
{{/isArray}}
137160
{{/isBoolean}}
138161
{{/isInteger}}
139162
{{/isLong}}

modules/openapi-generator/src/main/resources/go-server/helpers.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ func IsZeroValue(val interface{}) bool {
3232
return val == nil || reflect.DeepEqual(val, reflect.Zero(reflect.TypeOf(val)).Interface())
3333
}
3434

35-
// AssertInterfaceRequired recursively checks each struct in a slice against the callback.
35+
// AssertRecurseInterfaceRequired recursively checks each struct in a slice against the callback.
3636
// This method traverse nested slices in a preorder fashion.
3737
func AssertRecurseInterfaceRequired(obj interface{}, callback func(interface{}) error) error {
3838
return AssertRecurseValueRequired(reflect.ValueOf(obj), callback)
3939
}
4040

41-
// AssertNestedValueRequired checks each struct in the nested slice against the callback.
41+
// AssertRecurseValueRequired checks each struct in the nested slice against the callback.
4242
// This method traverse nested slices in a preorder fashion.
4343
func AssertRecurseValueRequired(value reflect.Value, callback func(interface{}) error) error {
4444
switch value.Kind() {

modules/openapi-generator/src/main/resources/go-server/impl.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{>partial_header}}
22
package {{packageName}}
33

4-
//Implementation response defines an error code with the associated body
4+
// ImplResponse response defines an error code with the associated body
55
type ImplResponse struct {
66
Code int
77
{{#addResponseHeaders}}

samples/server/petstore/go-api-server/go/api.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type UserApiRouter interface {
5757

5858
// PetApiServicer defines the api actions for the PetApi service
5959
// This interface intended to stay up to date with the openapi yaml used to generate it,
60-
// while the service implementation can ignored with the .openapi-generator-ignore file
60+
// while the service implementation can be ignored with the .openapi-generator-ignore file
6161
// and updated with the logic required for the API.
6262
type PetApiServicer interface {
6363
AddPet(context.Context, Pet) (ImplResponse, error)
@@ -74,7 +74,7 @@ type PetApiServicer interface {
7474

7575
// StoreApiServicer defines the api actions for the StoreApi service
7676
// This interface intended to stay up to date with the openapi yaml used to generate it,
77-
// while the service implementation can ignored with the .openapi-generator-ignore file
77+
// while the service implementation can be ignored with the .openapi-generator-ignore file
7878
// and updated with the logic required for the API.
7979
type StoreApiServicer interface {
8080
DeleteOrder(context.Context, string) (ImplResponse, error)
@@ -86,7 +86,7 @@ type StoreApiServicer interface {
8686

8787
// UserApiServicer defines the api actions for the UserApi service
8888
// This interface intended to stay up to date with the openapi yaml used to generate it,
89-
// while the service implementation can ignored with the .openapi-generator-ignore file
89+
// while the service implementation can be ignored with the .openapi-generator-ignore file
9090
// and updated with the logic required for the API.
9191
type UserApiServicer interface {
9292
CreateUser(context.Context, User) (ImplResponse, error)

samples/server/petstore/go-api-server/go/api_pet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func NewPetApiController(s PetApiServicer, opts ...PetApiOption) Router {
4747
return controller
4848
}
4949

50-
// Routes returns all of the api route for the PetApiController
50+
// Routes returns all the api routes for the PetApiController
5151
func (c *PetApiController) Routes() Routes {
5252
return Routes{
5353
{

samples/server/petstore/go-api-server/go/api_store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func NewStoreApiController(s StoreApiServicer, opts ...StoreApiOption) Router {
4747
return controller
4848
}
4949

50-
// Routes returns all of the api route for the StoreApiController
50+
// Routes returns all the api routes for the StoreApiController
5151
func (c *StoreApiController) Routes() Routes {
5252
return Routes{
5353
{

samples/server/petstore/go-api-server/go/api_user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func NewUserApiController(s UserApiServicer, opts ...UserApiOption) Router {
4747
return controller
4848
}
4949

50-
// Routes returns all of the api route for the UserApiController
50+
// Routes returns all the api routes for the UserApiController
5151
func (c *UserApiController) Routes() Routes {
5252
return Routes{
5353
{

samples/server/petstore/go-api-server/go/helpers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ func IsZeroValue(val interface{}) bool {
3636
return val == nil || reflect.DeepEqual(val, reflect.Zero(reflect.TypeOf(val)).Interface())
3737
}
3838

39-
// AssertInterfaceRequired recursively checks each struct in a slice against the callback.
39+
// AssertRecurseInterfaceRequired recursively checks each struct in a slice against the callback.
4040
// This method traverse nested slices in a preorder fashion.
4141
func AssertRecurseInterfaceRequired(obj interface{}, callback func(interface{}) error) error {
4242
return AssertRecurseValueRequired(reflect.ValueOf(obj), callback)
4343
}
4444

45-
// AssertNestedValueRequired checks each struct in the nested slice against the callback.
45+
// AssertRecurseValueRequired checks each struct in the nested slice against the callback.
4646
// This method traverse nested slices in a preorder fashion.
4747
func AssertRecurseValueRequired(value reflect.Value, callback func(interface{}) error) error {
4848
switch value.Kind() {

samples/server/petstore/go-api-server/go/impl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
package petstoreserver
1111

12-
//Implementation response defines an error code with the associated body
12+
// ImplResponse response defines an error code with the associated body
1313
type ImplResponse struct {
1414
Code int
1515
Headers map[string][]string

0 commit comments

Comments
 (0)