swagger-api / swagger-api/swagger-codegen
JAVA: generating generic list/array property of nested model fails
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I have a Model A which has a property with type: array that references another Model B which also has a property with type: array and references another Model.
When generating the Model A i get a generic List with Model B but in Model B the referenced Model is not generated and the List $ref string as generic type.
Swagger-codegen version
gradle plugin:
'org.detoeuf.swagger-codegen' version '1.6.1'
Swagger declaration file content or url
ModelA.yaml:
definitions:
ModelA:
type: object
properties:
propertyA:
type: array
items: { $ref: './ModelB.yaml#/definitions/ModelB' }
ModelB.yaml:
definitions:
ModelB:
type: object
properties:
propertyA1:
type: array
items: { $ref: './ModelC.yaml#/definitions/ModelC' }
ModelC.yaml:
definitions:
ModelC:
type: object
properties:
property1: {type: string}
property2: {type: number}
property3: {type: string}
==generated Models==
ModelA:
`public class ModelA {
private List '<'ModelB'>' propertyA = new ArrayList'<'ModelB'>'();`
this is right.
ModelB:
public class ModelB {
private List '<'ModelCYamldefinitionsModelC'>' propertyA1 = new ArrayList '<'ModelCYamldefinitionsModelC'>'();
this not.
And ModelC is not even generated.
Command line used for generation
gradlew swagger
Steps to reproduce
generate the models for a path.
Related issues
Suggest a Fix
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
Reproduce the issue with ModelA.yaml, ModelB.yaml, and ModelC.yaml using the gradlew swagger command. Start by tracing Java model generation and nested $ref resolution; done means ModelC is generated and ModelB uses List<ModelC> rather than the unresolved reference string.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100