[JavaScript] Model default value of `null` for strings results in `"null"` value
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.
@dganoff What about not specifying "default": null as the default should already be null, right?
I remember there's a discussion about null value (default or example) before and the recommended approach is to use vendor extension to indicate the null value as default/example values are treated as string ("null")
@wing328 Thanks for the feedback! I will advocate that we do away with null default values since you make a good point that they are not helpful. I'll also look into the vendor extension which sounds interesting.
I'll also look into the vendor extension which sounds interesting.
@dganoff We've not implemented it yet. I can show you some good starting point to add it to JS client templates.