swagger-api / swagger-api/swagger-codegen
[aspnetcore] swagger-codegen passes invalid parameters to the mustache template
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
For the Swagger declaration below, swagger-codegen-cli generates invalid code. It is caused by the invalid parameters passed to the mustache template engine. The string enum is not represented as enum according the model debug information.
Is there any workaround for this issue? Unfortunately, I cannot update to a newer version because of... reasons.
Swagger-codegen version
2.3.1
Swagger declaration file content or url
https://gist.github.com/std66/e264d5c839621c2fd782232825d36830
Command line used for generation
(on Windows machine)
java -jar swagger-codegen-cli-2.3.1.jar generate --type-mappings array=IEnumerable -l aspnetcore -i yaml\test.yaml -o generated_code -DmodelTests=false -DapiTests=false -DdebugModels=true
Steps to reproduce
- Have the linked YAML file on path [working_dir]\yaml\test.yaml
- Run the command above
- Observe the model debug info outputted by swagger-codegen-cli.
- Observe the generated SampleRequestDto model. The SampleRequestDto contains all the properties from BaseObjectDto, but the "PropertyFromBase" is not Nullable, which causes compilation errors in the constructor.
- Observe the generated BaseObjectDto. The "PropertyFromBase" property is generated correctly as Nullable.
Actual result:
Different parameters are used for "PropertyFromBase" property in "BaseObjectDto" and "SampleRequestDto". I attached the output of the model debug:
The entire output: https://gist.github.com/std66/fdad6658d9883dfbfb305eb6a9a94913
The property's parameters in "BaseObjectDto": https://gist.github.com/std66/9b96c3fdac4ba4a850e6d7eced97c4d7
The property's parameters in "SampleRequestDto": https://gist.github.com/std66/4566891c1bc046dba51fd132653beb57
Related issues/PRs
I did a search but didn't found any.
Suggest a fix/enhancement
The issue could be resolved in two possible ways.
Expected result ("A" version):
"SampleRequestDto" should inherit from "BaseObjectDto" and "SampleRequestDto" should not contain "PropertyFromBase".
Expected result ("B" version):
"SampleRequestDto" does not inherit from "BaseObjectDto", but the enum parameters should be configured the same for the two classes.
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
Start by reproducing the issue with swagger-codegen-cli 2.3.1, the linked YAML declaration, and the provided Windows command. Compare the debug model output and generated BaseObjectDto and SampleRequestDto parameters, then confirm whether the intended result is inheritance or consistent enum parameters; done means the generated models compile without the reported mismatch.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, java
- Domain
- devtools, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100