You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Nested array data type missing import and fails in build #7812
When we define nested arrays (arrays containing arrays) in yaml file and later generate code , it fails to import the inner array type model. This causes build failure.
Swagger-codegen version
swagger-codegen-cli-3.0.0-rc0.jar
But I see this issue since 2.2.3 until 3.0.0?
Swagger declaration file content or url
api.yaml definition contains the "array of array" definition,
Please see the yaml content inserted as code this time. Hope the indentation is taken care now. Command used to generate code,
java -jar libs/swagger-codegen-cli-2.2.3.jar generate -l java -i contracts\api.yaml -o target Observation: target\src\main\java\io\swagger\client\model had "WaveformsUpdate.java" whereas
target\src\main\java\io\swagger\client\api\FormsApi.java had missing import for WaveformsUpdate.
`swagger: '2.0'
info:
title: Data Platform API
description: Platform API
version: "1.0.0"
host: api.com
schemes:
http
https
basePath: /v1
produces:
application/json
paths:
/patients/{uuid}/waveforms:
get:
summary: Return all the data items
operationId: getWaveforms
description: |
Return all the waveform data items
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 (one per every source)
headers:
Access-Control-Allow-Origin:
type: string
default: "*"
schema:
type: array
items:
type: array
items:
$ref: '#/definitions/WaveformsUpdate'
definitions:
WaveformsUpdate:
type: object
description: "An update for a collection of parameters"
properties:
entityID:
description: "The internal id"
type: string
sourceID:
description: "Identifier of source emitting the data"
type: string
watchID:
description: "Unique id of the data stream"
type: string
dateTime:
description: "Date/time of the sample"
type: string
format: [dateTime`]
Tried the same with "swagger-codegen-cli-3.0.0-20180307.151249-37.jar" & still issue exist. Command used to generate code,
java -jar libs/swagger-codegen-cli-3.0.0-20180307.151249-37.jar generate -l java -i contracts\api.yaml -o target
If you replace the array of array definition to array of waveformsupdate you can see the swagger-codegen-cli inserts the below import in FormsApi.java
Ooops you are right, I made the revision 2 in gist by updating as array[array]. Please generate the same way and you can see the missing import for <List<List>>.
The imports look also good regarding List... I have found an other problem with imports: I think that some imports for the model classes are missing, but this looks like other issues that are reported here (#7776 and #7836). I will try to have a look at this.
Forget what I have told about the other issues. I think your problem is different and I think I have found a solution.
About the swagger-codegen-cli version containing the fix: I am only a contributor to the project, submitting pull request. I can not influence when they are merged. Improving swagger-codegen is not my job.
@jmini Now that the PR is merged, please help me understand how do I generate the cli jar from source? My understanding is download the latest source code of swagger-codegen and compile.
However, I could not understand how is swagger-codegen-generators is referenced in this project.
In v3, the swagger-codegen-generators jar now contains the fix.
The next swagger-codegen build will produce a cli jar that contains the latest version of swagger-codegen-generators. You can also build it locally. Checkout this repo swagger-codegen branch 2.0 and run mvn clean install -U in the root folder.
If you are using the maven plugin. I think that if you run your build with -U, using version 3.0.0-SNAPSHOT of the swagger-codegen-maven-plugin maven will also fetch io.swagger:swagger-codegen-generators:1.0.0-SNAPSHOT (this needs to be verified).
@msjoshi: do not hesitate to ask if you need something.
A build of the v3 branch was triggered with commit a33c06d. This means that if you download cli jar version 3.0.0-SNAPSHOT from maven central, you should get a cli jar that includes the io.swagger:swagger-codegen-generators:1.0.0-SNAPSHOT jar that contains the fix.
However, it did not resolve the nested array issue. When I try to compile the client, it would give an error.
[ERROR] /Users/mjoshi/projects/papi/app/src/swagger/clients/papi-client-java/src/main/java/io/swagger/client/model/ActionRoleSearch.java:[148,45] cannot find symbol
[ERROR] symbol: class OrderEnum
[ERROR] location: class io.swagger.client.model.ActionRoleSearch
For me it works with this spec provided by @vidyas78 I could run mvn verify in the output/ folder. I get no error.
Second verification: file output/src/main/java/io/swagger/client/api/FormsApi.java contains the expected import line: import io.swagger.client.model.WaveformsUpdate;
@msjoshi: There is no need to continue the discussion here. #7918 might be a similar but other problem. Test your case with the swagger-codegen-cli-3.0.0-20180328.154333-52.jar jar, and if you still have a problem, explain it in #7918.
I tried my spec with swagger-codegen-cli-3.0.0-20180328.065958-50.jar but import is still missing in the API. Was wondering how it works for you, am I using the right cli?
Activity
webron commentedon Mar 9, 2018
@vidyas78 the yaml you pasted is completely flat and missing indentation, can't really be used that way.
jmini commentedon Mar 12, 2018
As mentioned by @webron it is hard to follow what your input spec is.
Please try the latest
3.0.0-SNAPSHOTversion, because I made some changes with array in order to fix: #7592As far as I know, in Java
ArraySchemaare converted toList<?>. Maybe an array of array will be a List of List in the generated Java code.vidyas78 commentedon Mar 13, 2018
Please see the yaml content inserted as code this time. Hope the indentation is taken care now.
Command used to generate code,
java -jar libs/swagger-codegen-cli-2.2.3.jar generate -l java -i contracts\api.yaml -o target
Observation: target\src\main\java\io\swagger\client\model had "WaveformsUpdate.java" whereas
target\src\main\java\io\swagger\client\api\FormsApi.java had missing import for WaveformsUpdate.
`swagger: '2.0'
info:
title: Data Platform API
description: Platform API
version: "1.0.0"
host: api.com
schemes:
basePath: /v1
produces:
paths:
/patients/{uuid}/waveforms:
get:
summary: Return all the data items
operationId: getWaveforms
description: |
Return all the waveform data items
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 (one per every source)
headers:
Access-Control-Allow-Origin:
type: string
default: "*"
schema:
type: array
items:
type: array
items:
$ref: '#/definitions/WaveformsUpdate'
definitions:
WaveformsUpdate:
type: object
description: "An update for a collection of parameters"
properties:
entityID:
description: "The internal id"
type: string
sourceID:
description: "Identifier of source emitting the data"
type: string
watchID:
description: "Unique id of the data stream"
type: string
dateTime:
description: "Date/time of the sample"
type: string
format: [dateTime`]
vidyas78 commentedon Mar 13, 2018
Tried the same with "swagger-codegen-cli-3.0.0-20180307.151249-37.jar" & still issue exist.
Command used to generate code,
java -jar libs/swagger-codegen-cli-3.0.0-20180307.151249-37.jar generate -l java -i contracts\api.yaml -o target
If you replace the array of array definition to array of waveformsupdate you can see the swagger-codegen-cli inserts the below import in FormsApi.java
import io.swagger.client.model.WaveformsUpdate;
jmini commentedon Mar 13, 2018
Without indentation, it is to hard to follow. Please edit your messages.
Have a look at the markdown syntax guide. For multiline code, you need to use 3 grave accent. As alternative, you can also save your spec example at http://gist.github.com/ and then add the link here.
vidyas78 commentedon Mar 13, 2018
https://gist.github.com/vidyas78/737441244829907cd961ce2a986ec94c
Please refer from above & let me know if this helps, the yaml was validated in https://editor.swagger.io//.
vidyas78 commentedon Mar 15, 2018
Team
Can you please acknowledge if the issue was reproducible at your end?
Thanks
jmini commentedon Mar 16, 2018
I am sorry but I am not able to follow.
I have generated code using the
javagenerator with the spec taken from your gist.I can compile the generated artefact with maven =>
BUILD SUCCESSWhen I look at
/<output folder>/src/main/java/io/swagger/client/api/FormsApi.java, I see following import lines:This includes the expected
WaveformsUpdateimport.Maybe I missed something from your bug description. You have described 2 cases. Maybe the one you posted as gist is the one working...
vidyas78 commentedon Mar 16, 2018
Ooops you are right, I made the revision 2 in gist by updating as array[array]. Please generate the same way and you can see the missing import for <List<List>>.
jmini commentedon Mar 17, 2018
I have tried your example with the latest version
3.0.0-SNAPSHOTand I did not manage to reproduce your issue.I have found an other issue: #7863
With the fix proposed in the Pull Request, the method looks correct:
The imports look also good regarding
List... I have found an other problem with imports: I think that some imports for the model classes are missing, but this looks like other issues that are reported here (#7776 and #7836). I will try to have a look at this.vidyas78 commentedon Mar 18, 2018
Yes imports of the model classes are missing, Can you please share the swagger-codegen-cli version once its fixed? Thanks
jmini commentedon Mar 19, 2018
Forget what I have told about the other issues. I think your problem is different and I think I have found a solution.
About the swagger-codegen-cli version containing the fix: I am only a contributor to the project, submitting pull request. I can not influence when they are merged. Improving
swagger-codegenis not my job.jmini commentedon Mar 19, 2018
I have propsed a pull request to solve your issue: swagger-api/swagger-codegen-generators#44
Fix missing import of model class with nested arrays in response
vidyas78 commentedon Mar 21, 2018
Thanks
3 remaining items
msjoshi commentedon Mar 28, 2018
@jmini Now that the PR is merged, please help me understand how do I generate the cli jar from source? My understanding is download the latest source code of
swagger-codegenand compile.However, I could not understand how is
swagger-codegen-generatorsis referenced in this project.jmini commentedon Mar 28, 2018
In v3, the
swagger-codegen-generatorsjar now contains the fix.The next
swagger-codegenbuild will produce aclijar that contains the latest version ofswagger-codegen-generators. You can also build it locally. Checkout this reposwagger-codegenbranch2.0and runmvn clean install -Uin the root folder.If you are using the maven plugin. I think that if you run your build with
-U, using version3.0.0-SNAPSHOTof theswagger-codegen-maven-pluginmaven will also fetchio.swagger:swagger-codegen-generators:1.0.0-SNAPSHOT(this needs to be verified).@msjoshi: do not hesitate to ask if you need something.
jmini commentedon Mar 28, 2018
A build of the v3 branch was triggered with commit a33c06d. This means that if you download
clijar version3.0.0-SNAPSHOTfrom maven central, you should get aclijar that includes theio.swagger:swagger-codegen-generators:1.0.0-SNAPSHOTjar that contains the fix.jmini commentedon Mar 28, 2018
@webron, @HugoMario can you please add
java-clientandjava-serverandissuelabels. And3.0.0milestone to this issue?msjoshi commentedon Mar 28, 2018
@jmini Let me know if I did this correctly.
I downloaded the source code from - https://github.com/swagger-api/swagger-codegen/tree/a33c06d876cc3cd428c7c0002eadbe39c770385c
I verified in pom.xml for
swagger-codegenproject that it is referencing to 3.0.0-SNAPSHOT.And pom for
swagger-codegen-cliis referencing to correct version ofswagger-codegen-generators-version.Then I ran
mvn clean install -U.However, it did not resolve the nested array issue. When I try to compile the client, it would give an error.
jmini commentedon Mar 28, 2018
The snapshot Builds are here:
https://oss.sonatype.org/content/repositories/snapshots/io/swagger/swagger-codegen-cli/3.0.0-SNAPSHOT/
Now the latest build is
3.0.0-20180328.154333-52.As explained in the README, you can download it with:
(or manually click on "save link as..." and indicate
swagger-codegen-cli.jaras name, save it somewhere on your computer. I have used atmpfolder)To test it (in your
tmpfolder):Then to generate assuming that
spec.yamlis your input spec (located near to the jar) and that you want the output to go in aoutput/folder:For me it works with this spec provided by @vidyas78 I could run
mvn verifyin theoutput/folder. I get no error.Second verification: file
output/src/main/java/io/swagger/client/api/FormsApi.javacontains the expected import line:import io.swagger.client.model.WaveformsUpdate;@msjoshi: There is no need to continue the discussion here. #7918 might be a similar but other problem. Test your case with the
swagger-codegen-cli-3.0.0-20180328.154333-52.jarjar, and if you still have a problem, explain it in #7918.vidyas78 commentedon Apr 3, 2018
Hi Jmini,
I tried my spec with swagger-codegen-cli-3.0.0-20180328.065958-50.jar but import is still missing in the API. Was wondering how it works for you, am I using the right cli?
thanks
vidyas78 commentedon Apr 3, 2018
Sorry for missing the version, its working with swagger-codegen-cli-3.0.0-20180328.154333-52.jar. Thanks
jmini commentedon Apr 3, 2018
@webron, @HugoMario can you please add
java-clientandjava-serverandissuelabels and3.0.0milestone to this issue? Can you also close it?webron commentedon Apr 3, 2018
Thanks @jmini.
Fix missing import of model class with nested arrays in response