swagger-api / swagger-api/swagger-codegen
[JavaScript] Model default value of `null` for strings results in `"null"` value
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Model default value of null for strings gets set to "null" upon creating a new instance of the model.
Swagger-codegen version
2.3.0
Swagger declaration file content or url
Schema definition for the model property:
outbound_localization : {
"default": null,
"description": "...",
"type": "string"
}
Command line used for generation
docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli generate \
-i https://apidev.telnyx.com/mission_control_docs \
-l javascript \
-o /local/src/.swagger-codegen-output/missionControl \
--additional-properties usePromises=true,useEs6=true
Steps to reproduce
- Create a new version of the Connection model
let connection = new moduleName.Connection(); - See that the
connection.outbound_localizationvalue is"null"
Suggest a fix/enhancement
I suggest that if the default value for a model property is null, then set the value to null regardless of the property type. Otherwise keep it as undefined.
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
Use the JavaScript generation command and the generated Connection model as the entry points. Reproduce the issue with the schema property whose default is null, then trace how that default is rendered for a string. Done means a new model instance has null for that property rather than "null", while properties without a default remain undefined.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100