JAVA: generating generic list/array property of nested model fails
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
I think the issue is related to https://github.com/swagger-api/swagger-codegen/issues/3305
As a workaround, defining the models within the same file (spec) should work without issue.
I am having this issue as well. But my spec is huge, so I can't specify in the same file.
I have this issue as well and it is critical to our use of swagger. Our spec is huge, so we must split our spec into multiple files.
Another possible workaround (as mentioned in #3305) is to revert Swagger Parser version to 1.0.19
The issue is also present with *.json definitions, and downgrading Swagger Parser version didn`t help =( The only difference in our case is the type being "object" in nested references, not "array"
Can you guys please pull the latest master to give it a try (as a newer stable version of Swagger parser has been released)?
Hi, wing328! Seems like the problem is still there, but it looks differently (or might be another one, not sure). Let us have models A1 and A2, each of A-models referencing model B. Model B, in turn, references model C (../Path/to/C.json#/definitions/C):
- When processing model A1, ExternalRefPRocessor processes model B and adds it to cache. Then it processes properties of model B, stripping them from external reference part (before #/definitions/...), and putting them into cache. Now model B references model C as an INTERNAL model (#/definitions/C)
- When processing model A2, ExternalRefPRocessor gets model B from cache and continues to resolving properties one more time. It now sees references to C as INTERNAL, trying to resolve it by adding path to B (../Path/to/B.json#/definitions/C), and, of course, doesn`t find it there, failing with RuntimeException: Could not find definitions/C in contents of ../Path/to/B.json
@dennisTs thanks for performing more tests to confirm. Do you mind sharing with me the spec so that I can more easily reproduce the issue?
If the spec cannot be shared publicly, please send it to [email protected] (email address stated in my github profile)
@wing328 Nested_references_API.zip - here is a stub definition to reproduce the issue
@wing328 just checked - it is a separate issue =( the one described by FlorianSchmuck still exists
I tried with the latest version swagger-codegen-cli-3.0.0-rc0 and still see the missing imports for the nested arrays. Is there any solution released yet?
@vidyas78 can you please share the command and spec you use to get the error?
api.yaml definition contains the "array of array" definition,
swagger: '2.0' info: title: description: version: "1.0.0" host: schemes:
- http
- https basePath: /v1 produces:
- application/json
paths:
/patients/{uuid}/forms:
get:
summary:
operationId:
description: |
tags: - forms parameters: - name: uuid in: path description: identifier uuid. required: true type: string - name: start in: query description: Start date-time for data. required: false type: string format: dateTime - name: end in: query description: End date-time for data. required: false type: string format: dateTime responses: 200: description: An array of updates headers: Access-Control-Allow-Origin: type: string default: "*" schema: type: array items: type: array items: $ref: '#/definitions/WaveformsUpdate'
Command to generate: java -jar libs/swagger-codegen-cli-3.0.0-rc0.jar generate -l java -i api.yaml -o target
Once the files are generated , I see missing imports for WaveformsUpdate and mvn clean install fails due to that.
Thanks
thanks @vidyas78 , since this is for 3.0.0, can you please file a new ticket with these info and tag me there? i'll address the issue.
sure will do it. We are currently using 2.2.3 for my project and to overcome this issue, I was trying all the later versions until 3.0.0.
Do you know any specific version where this issue is fixed? Or any workaround?