swagger-api / swagger-api/swagger-codegen
Fix array model type to also work with primitive type
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Currently, arrayModelType only works with non-primitive types. It should also work with primitive types.
Swagger-codegen version
3.0.0
Swagger declaration file content or url
components:
schemas:
Test:
type: array
items:
type: number
format: double
When using {{{arrayModelType}}} in a template file, I expect something like f64, but I get an empty string.
Command line used for generation
java -jar swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
-i openapi.yaml \
-l rust \
-o generated_api
Steps to reproduce
Use a primitive type in the items section of an array schema.
Suggest a fix/enhancement
The problem lies on line 1111 of DefaultCodegen.java:
https://github.com/swagger-api/swagger-codegen/blob/d300ebf34411d0e7f42f1c44ab6bd7584443089d/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java#L1111
Here the complexType of the array property is used, and as we can see at line 1540, it is obviously not set when we have a primitive type:
https://github.com/swagger-api/swagger-codegen/blob/d300ebf34411d0e7f42f1c44ab6bd7584443089d/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java#L1540-L1544
A proposed solution is to use .items.baseType instead of .complexType, so that line 1111 becomes:
codegenModel.arrayModelType = fromProperty(name, schema).items.baseType;
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
Read DefaultCodegen.java around lines 1111 and 1540-1544, then reproduce the issue with the provided array schema and Rust generation command. Update the array model type handling so the primitive item type is exposed, and verify that the template receives a value such as f64 instead of an empty string.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100