Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JAVA: generating generic list/array property of nested model fails #3495

Open
RunCMD159 opened this issue Aug 1, 2016 · 16 comments
Open

JAVA: generating generic list/array property of nested model fails #3495

RunCMD159 opened this issue Aug 1, 2016 · 16 comments

Comments

@RunCMD159
Copy link

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
@wing328
Copy link
Contributor

wing328 commented Aug 1, 2016

I think the issue is related to #3305

@wing328
Copy link
Contributor

wing328 commented Aug 1, 2016

As a workaround, defining the models within the same file (spec) should work without issue.

@jeff9finger
Copy link
Contributor

I am having this issue as well. But my spec is huge, so I can't specify in the same file.

@jeff9finger
Copy link
Contributor

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.

@wing328
Copy link
Contributor

wing328 commented Aug 1, 2016

Another possible workaround (as mentioned in #3305) is to revert Swagger Parser version to 1.0.19

@wing328 wing328 modified the milestones: v2.2.1, v2.2.2 Aug 8, 2016
@dennisTS
Copy link

dennisTS commented Aug 8, 2016

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"

@wing328
Copy link
Contributor

wing328 commented Aug 9, 2016

Can you guys please pull the latest master to give it a try (as a newer stable version of Swagger parser has been released)?

@dennisTS
Copy link

dennisTS commented Aug 9, 2016

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):

  1. 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)
  2. 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

@wing328
Copy link
Contributor

wing328 commented Aug 9, 2016

@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 wing328@yahoo.com (email address stated in my github profile)

@dennisTS
Copy link

dennisTS commented Aug 9, 2016

@wing328 Nested_references_API.zip - here is a stub definition to reproduce the issue

@dennisTS
Copy link

@wing328 just checked - it is a separate issue =( the one described by FlorianSchmuck still exists

@wing328 wing328 modified the milestones: v2.2.2, v2.2.3 Feb 22, 2017
@wing328 wing328 modified the milestones: v2.2.3, v2.3.0 Jul 16, 2017
@wing328 wing328 modified the milestones: Future, v2.3.0 Jul 27, 2017
@vidyas78
Copy link

vidyas78 commented Mar 9, 2018

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?

@HugoMario
Copy link
Contributor

@vidyas78 can you please share the command and spec you use to get the error?

@vidyas78
Copy link

vidyas78 commented Mar 9, 2018

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

@HugoMario
Copy link
Contributor

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.

@vidyas78
Copy link

vidyas78 commented Mar 9, 2018

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants