swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

[Java] Missing import of class OrderEnum when using nested Array in spec.

Open msjoshi opened this issue 8 years ago • 15 comments

Description

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

Swagger-codegen version

2.3.1

Swagger declaration file content or url
"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"
              ]
            }
          }
        }
Command line used for generation

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.

Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement

msjoshi avatar Mar 27 '18 02:03 msjoshi

I think this is fixed with 3.0.0-SNAPSHOT (see #7812).

jmini avatar Mar 28 '18 15:03 jmini

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 avatar Mar 28 '18 21:03 jmini

@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

msjoshi avatar Mar 29 '18 15:03 msjoshi

Thank you for the test and your feedback. I will try to look at your example spec.

jmini avatar Mar 29 '18 16:03 jmini

Confirmed. I have reproduced your problem in my computer. I will try to see if I can provide a fix.

jmini avatar Mar 29 '18 16:03 jmini

I think I have found a unit test that can be added to JavaModelEnumTest to reproduce the root of the problem.

jmini avatar Apr 03 '18 15:04 jmini

Fyi, if enums are not in nested array, it works well. The issue is only when enums are in nested array.

msjoshi avatar Apr 03 '18 21:04 msjoshi

@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).

jmini avatar Apr 04 '18 05:04 jmini

I have opened a PR to solve this issue: https://github.com/swagger-api/swagger-codegen-generators/pull/58

jmini avatar Apr 04 '18 05:04 jmini

Awesome. Appreciate it.

msjoshi avatar Apr 04 '18 14:04 msjoshi

Is the fix in this build swagger-codegen-cli-3.0.0-20180404.075754-56.jar?

msjoshi avatar Apr 05 '18 03:04 msjoshi

I am sorry but I do not think so.


Merge commit in swagger-codegen-generators (containing the fix):

commit 5935f358e9106f5f70ada0dba27611bf21d69e3e Committer: GitHub [email protected] 2018-04-04 14:27:51


Last commit in swagger-codegen :

commit e31243b6d96c656ad6300b1c7ef82eb6883faf4d Committer: GitHub [email protected] 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).

jmini avatar Apr 05 '18 04:04 jmini

Understood. Thanks for this insight.

msjoshi avatar Apr 05 '18 04:04 msjoshi

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.

jmini avatar Apr 05 '18 04:04 jmini

Tested with swagger-codegen-cli-3.0.0-20180405.043309-57.jar and it works. Thanks @jmini. This issue can be closed.

msjoshi avatar Apr 05 '18 14:04 msjoshi