OpenAPITools / OpenAPITools/openapi-generator
[BUG] default value not used for query parameters
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
Default value of not required query parameter not used. Maybe there is an other way to do what I want?
openapi-generator version
openapi-generator-maven-plugin 5.1.1
OpenAPI declaration file content or url
"parameters": {
"version": {
"name": "version",
"in": "query",
"required": false,
"schema": {
"type": "string",
"default": "1.0.0"
}
}
}
Generation Details
Generation for typescript-angular with ngVersion to 11 and spec validation to true.
What are generated:
public myFunction(version?: string, observe: any = 'body', reportProgress: boolean = false, options?: { httpHeaderAccept?: 'application/json' }): Observable<any> {}
What is expected:
public myFunction(version?: string = '1.0.0', observe: any = 'body', reportProgress: boolean = false, options?: { httpHeaderAccept?: 'application/json' }): Observable<any> {}
Steps to reproduce
In the OpenAPI specification file créate a query parameter that is not required and with a default value.
Generate the code for typescript-angular with ng version to 11 and validation spec to true
Related issues/PRs
Suggest a fix
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
Reproduce the issue with the shown OpenAPI parameter and the typescript-angular generator using ngVersion 11 and spec validation enabled. Trace how the generator handles optional query parameters with schema defaults, then verify that the generated myFunction signature uses '1.0.0' and that relevant generator tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100