OpenAPITools / OpenAPITools/openapi-generator

[BUG][Javascript] Constructors don't handle required fields with default values well

Open
#6,648 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.