swagger-api / swagger-api/swagger-codegen
Initializing generated properties with default empty arrays instead of null
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
We are moving to swagger codegen from the Jsonschema2pojo plugin, for generating the pojos from json schema. However swagger is defaulting all properties to null, which wasnt the case with the other plugin. It was helping us in a way to not have null checks in the functional implementation, but now moving to swagger is creating problem with this behavior and forcing us to introduce null checks all across leads to bigger change.
I have tried modifying the schema like below by introducing the default, still it did not help.
"Limits": {
"type": "array",
"default" : [],
"items": {
"$ref": "#/definitions/Limit"
}
},
Swagger-codegen version - 2.3.1
Swagger declaration file content or url
Command line used for generation
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement
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
The report identifies swagger-codegen 2.3.1 and an array property named Limits, but provides no declaration, command, target language, generated file, or test. First supply a minimal reproducible schema and generation setup, then trace the generated property initialization and define the expected empty-array behavior.
Written by the indexing model from the issue text.
Assessment
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100