OpenAPITools / OpenAPITools/openapi-generator
[BUG] Handle empty string for non-required query parameter
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
openapi-generator version
v5.4.0
OpenAPI declaration file content or url
/objectives/alerts:
get:
summary: Get the MultiBurnrateAlerts for the Objective
operationId: GetMultiBurnrateAlerts
tags:
- objectives
parameters:
- in: query
name: expr
required: true
schema:
type: string
- in: query
name: grouping
required: false
schema:
type: string
- in: query
name: inactive
required: false
schema:
type: boolean
default: false
It's about the last query parameter called inactive here.
The problem seems to be, that even though the parameter isn't required the code doesn't handle a non existing &inactive in the URL and instantly returns 500 internal server error
Generation Details
docker run openapitools/openapi-generator-cli:v5.4.0
Steps to reproduce
This first one works as the parameter doesn't have an empty string but f
http://localhost:9099/api/v1/objectives/alerts?expr=&inactive=f
The second one doesn't work, as the string is "" and that results in a parse error.
http://localhost:9099/api/v1/objectives/alerts?expr=&inactive=
Here's the Go stdlib for parsing the boolean that returns a syntaxError:
https://cs.opensource.google/go/go/+/refs/tags/go1.18:src/strconv/atob.go;l=10
Related issues/PRs
Suggest a fix
Something similar to other types should be just fine. For example:
https://github.com/OpenAPITools/openapi-generator/blob/941d4845d73536473ac6ef63ebaa6e762bdf0606/modules/openapi-generator/src/main/resources/go-server/routers.mustache#L184-L191
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Inspect modules/openapi-generator/src/main/resources/go-server/routers.mustache, especially the parameter handling around lines 184-209, and compare the optional boolean path with the other types. Reproduce the generated server behavior using the provided OpenAPI declaration and URLs; done means an empty optional inactive query value no longer causes a 500 parse error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, openapi
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100