OpenAPITools / OpenAPITools/openapi-generator
[BUG][Javascript] Constructors don't handle required fields with default values well
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
Currently the generator creates constructors where required fields are set to the parameters in the constructor. This is fine except when the parameters are null and there is a default value specified in the spec.
openapi-generator version
4.3.1
Suggest a fix
This can be fixed by just having the constructor assign either the incoming value or the default value if the incoming value is undefined. I'll submit a PR for this.
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 by generating a JavaScript client from an OpenAPI spec containing a required field with a default value, then inspect the generated model constructor. Verify that construction behaves correctly for null or undefined input and for an explicitly supplied value, using the generator's existing JavaScript tests if available.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100