In our API spec, I have a nested array with enums as one of the attribute. When I use the default command to generate Java client, it looks like there is a missing import for OrderEnum class and get the following error during compile.
I searched the issues and did find similar issues but none related to OrderEnum. Really appreciate if anyone can guide me in the right direction.
cannot find symbol
symbol: class OrderEnum
location: class io.swagger.client.model.NotificationSearch
2.3.1
"order": {
"description": "A collection of grouped attribute names and directions.",
"type": "array",
"items": {
"type": "array",
"items": {
"type": "string",
"enum": [
"id",
"tagId",
"position",
"roomNumber",
"floorNumber",
"alarmThreshold",
"adjustedVariance",
"location",
"caliberType",
"caliberConfidence",
"realTimeClock",
"createdAt",
"updatedAt",
"deletedAt",
"ASC",
"DESC"
]
}
}
}
java -jar "/Users/mjoshi/projects/papi/app/src/scripts/lib/swagger/codegen/2.3.1/swagger-codegen-cli.jar" generate -i /Users/mjoshi/projects/papi/app/src/swagger/api.json -l java -c /Users/mjoshi/projects/papi/app/src/swagger/clients/papi-client-java/.swagger-codegen/config.json -o /Users/mjoshi/projects/papi/app/src/swagger/clients/papi-client-java 2>&1
Please note config.json is empty.
I think this is fixed with 3.0.0-SNAPSHOT (see #7812).
Your declaration file is too complicated to understand for me. Please post a complete minimal example (yaml or json) somewhere. You can use https://gist.github.com/ if you are looking for a great place to post it.
@jmini Unfortunately, the fix did not work for me. I realized there is a subtle difference between #7812 and mine. I also have a nested array and the inner array is a enum. The definition of inner enum is not generated which causes the client to fail. Here is the gist which contains the full spec for you to try.
https://gist.github.com/msjoshi/08f95f35610656ec7d45bacb48f7bd22
Below is the error I get when I try to compile the generated client.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project swagger-java-client: Compilation failure
[ERROR] /Users/mjoshi/projects/scratch/swagger-codegen/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
Thank you for the test and your feedback. I will try to look at your example spec.
Confirmed. I have reproduced your problem in my computer. I will try to see if I can provide a fix.
I think I have found a unit test that can be added to JavaModelEnumTest to reproduce the root of the problem.
Fyi, if enums are not in nested array, it works well. The issue is only when enums are in nested array.
@msjoshi: luckally there is both form (array of array of enum and array of enum) in your input spec (OrderEnum is missing, AttributesEnum is generated).
I have opened a PR to solve this issue: https://github.com/swagger-api/swagger-codegen-generators/pull/58
Awesome. Appreciate it.
Is the fix in this build swagger-codegen-cli-3.0.0-20180404.075754-56.jar?
I am sorry but I do not think so.
Merge commit in swagger-codegen-generators (containing the fix):
commit 5935f358e9106f5f70ada0dba27611bf21d69e3e
Committer: GitHub noreply@github.com 2018-04-04 14:27:51
Last commit in swagger-codegen :
commit e31243b6d96c656ad6300b1c7ef82eb6883faf4d
Committer: GitHub noreply@github.com 2018-04-04 09:51:03
This commit has triggered the build of swagger-codegen-cli producing: swagger-codegen-cli-3.0.0-20180404.075754-56.jar but this version might include a version of io.swagger:swagger-codegen-generators:1.0.0-SNAPSHOT that does not contains the fix (because it was merged after that).
If you want to use the cli you need to build it locally or wait for any new commit in swagger-codegen (on branch 3.0.0).
Understood. Thanks for this insight.
A new commit was added by @HugoMario to 3.0.0 branch: 431a52c62b12882edba088217564a56b048944c3
This has produced a new build swagger-codegen-cli-3.0.0-20180405.043309-57.jar. Maybe you can give this version a try and report feedback here.
Tested with swagger-codegen-cli-3.0.0-20180405.043309-57.jar and it works. Thanks @jmini.
This issue can be closed.