You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When using the go-server generator, query parameters with required: false are being generated as value types. Using the example spec below, this generates a method signature like the following:
type DefaultAPIServicer interface {
RootGet(context.Context, bool) (ImplResponse, error)
}
Since the default value of bool is false, it is not possible to tell whether the client passed false to the parameter or simply did not provide it at all. By using a pointer instead, the parameter could be nil when not passed by the client. The method signature should look like the following:
type DefaultAPIServicer interface {
RootGet(context.Context, *bool) (ImplResponse, error)
}
openapi-generator version
7.7.0
OpenAPI declaration file content or url
openapi: 3.0.0security: []info:
description: >- This is a sample spec to demonstrate handling non-required boolean query parameters in the go-server generatorversion: 1.0.0title: Boolean samplelicense:
name: Apache-2.0url: 'https://www.apache.org/licenses/LICENSE-2.0.html'paths:
/:
get:
summary: Sample endpointdescription: Demonstrate handling of non-required boolean query parametersparameters:
- in: queryname: someParamdescription: a test parameterschema:
type: booleanrequired: falseresponses:
'200':
description: Democontent:
application/json:
schema:
type: string
Generation Details
This bug can be reproduced using the go-server generator with no additional settings.
Steps to reproduce
Copy the above spec into a file and save at ./openapi/openapi.yaml
Run the generator with the command: java -jar openapi-generator-cli.jar generate -i ./openapi/openapi.yaml -o ./server-gen -g go-server
Observe the generated server code in the server-gen directory, eg. ./server-gen/go/api.go, note that the RootGet method signature takes a bool rather than a *bool parameter.
@lwj5 Thanks for this sample, I had tried something similar but didn't realize the nullable property had to be under schema. This does indeed address the problem so I will close this issue/PR. Thanks for your time.
Bug Report Checklist
Description
When using the
go-server
generator, query parameters withrequired: false
are being generated as value types. Using the example spec below, this generates a method signature like the following:Since the default value of
bool
is false, it is not possible to tell whether the client passedfalse
to the parameter or simply did not provide it at all. By using a pointer instead, the parameter could benil
when not passed by the client. The method signature should look like the following:openapi-generator version
7.7.0
OpenAPI declaration file content or url
Generation Details
This bug can be reproduced using the
go-server
generator with no additional settings.Steps to reproduce
./openapi/openapi.yaml
java -jar openapi-generator-cli.jar generate -i ./openapi/openapi.yaml -o ./server-gen -g go-server
server-gen
directory, eg../server-gen/go/api.go
, note that theRootGet
method signature takes abool
rather than a*bool
parameter.Related issues/PRs
Suggest a fix
#19149
Would appreciate the Go technical committee reviewing this issue and my suggested fix (@antihax, @grokify, @kemokemo, @jirikuncar, @ph4r5h4d, @lwj5)
The text was updated successfully, but these errors were encountered: