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

[BUG][Java][jersey2] Bug generating client with jersey2 for specification with anyOf or oneOf #7033

Open
ghost opened this issue Jul 23, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented Jul 23, 2020

Description

I have an API specification that makes use of inheritance and polymorphism using the oneOf,anyOf, and allOf syntax. In the current master snapshot, the Java generator using jersey2 library handles the allOf inheritance without errors. However, the oneOf and anyOf polymorphism does not result in the creation of classes, thus causing compile errors.

openapi-generator version

5.0.0-snapshot as of July 23, 2020

OpenAPI declaration file content or url

Here is a sample specification which reproduces the issue:
https://gist.github.com/sylvester-rubidium/6898e33c93fe67d23effefb352db971e

Command line used for generation

The client config file:

apiPackage: "org.myapi.client.api"
artifactId: "myapi-java-client"
groupId: "org.myapi"
invokerPackage: "org.myapi.client"
library: "jersey2"
modelPackage: "org.myapi.client.model"

The command to generate the SDK:

echo "Creating JAVA client"
rm -rf java_sdk
OPENAPI_GENERATOR_VERSION=5.0.0-SNAPSHOT openapi-generator-cli \
    generate \
    -g java \
    -i openapi.yaml \
    -o ./java_sdk \
    -c ./java_client.yaml
Steps to reproduce
  1. Download the gist YAML locally or clone this repo
  2. Run the generate script
  3. Compile the SDK: cd java_sdk; mvn clean install
  4. The process yields errors:
[INFO] 14 errors 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project myapi-java-client: Compilation failure: Compilation failure: 
[ERROR] java_sdk/src/main/java/org/myapi/client/model/Inventory.java:[29,29] error: cannot find symbol
[ERROR]   symbol:   class AnyOfShapesConstraintColorsConstraint
[ERROR]   location: package org.myapi.client.model
[ERROR] java_sdk/src/main/java/org/myapi/client/model/Inventory.java:[30,29] error: cannot find symbol
[ERROR]   symbol:   class OneOfSmallLarge
[ERROR]   location: package org.myapi.client.model
[ERROR] java_sdk/src/main/java/org/myapi/client/model/Inventory.java:[45,15] error: cannot find symbol
[ERROR]   symbol:   class AnyOfShapesConstraintColorsConstraint
[ERROR]   location: class Inventory
[ERROR] java_sdk/src/main/java/org/myapi/client/model/Inventory.java:[48,15] error: cannot find symbol
[ERROR]   symbol:   class OneOfSmallLarge
[ERROR]   location: class Inventory
[ERROR] java_sdk/src/main/java/org/myapi/client/model/Inventory.java:[51,36] error: cannot find symbol
[ERROR]   symbol:   class AnyOfShapesConstraintColorsConstraint
[ERROR]   location: class Inventory
[ERROR] java_sdk/src/main/java/org/myapi/client/model/Inventory.java:[56,38] error: cannot find symbol
[ERROR]   symbol:   class AnyOfShapesConstraintColorsConstraint
[ERROR]   location: class Inventory
[ERROR] java_sdk/src/main/java/org/myapi/client/model/Inventory.java:[69,14] error: cannot find symbol
[ERROR]   symbol:   class AnyOfShapesConstraintColorsConstraint
[ERROR]   location: class Inventory
[ERROR] java_sdk/src/main/java/org/myapi/client/model/Inventory.java:[74,34] error: cannot find symbol
[ERROR]   symbol:   class AnyOfShapesConstraintColorsConstraint
[ERROR]   location: class Inventory
[ERROR] java_sdk/src/main/java/org/myapi/client/model/Inventory.java:[79,30] error: cannot find symbol
[ERROR]   symbol:   class OneOfSmallLarge
[ERROR]   location: class Inventory
[ERROR] java_sdk/src/main/java/org/myapi/client/model/Inventory.java:[84,32] error: cannot find symbol
[ERROR]   symbol:   class OneOfSmallLarge
[ERROR]   location: class Inventory
[ERROR] java_sdk/src/main/java/org/myapi/client/model/Inventory.java:[97,14] error: cannot find symbol
[ERROR]   symbol:   class OneOfSmallLarge
[ERROR]   location: class Inventory
[ERROR] java_sdk/src/main/java/org/myapi/client/model/Inventory.java:[102,28] error: cannot find symbol
[ERROR]   symbol:   class OneOfSmallLarge
[ERROR]   location: class Inventory
[ERROR] java_sdk/src/main/java/org/myapi/client/model/Inventory.java:[45,82] error: cannot find symbol
[ERROR]   symbol:   class AnyOfShapesConstraintColorsConstraint
[ERROR]   location: class Inventory
[ERROR] java_sdk/src/main/java/org/myapi/client/model/Inventory.java:[48,54] error: cannot find symbol
[ERROR]   symbol:   class OneOfSmallLarge
[ERROR]   location: class Inventory
Related issues/PRs

Several issues and PRs have been reported. However, @wing328 suggested I open a bug issue for this specific problem.

A possibly related issue in the final comment here:
#4785 (comment)

Suggest a fix

Sadly, I am not a Java fluent developer and am creating this SDK to support another team. Thus, I do not have a suggested fix and am seeking help.

@ghost ghost added the Issue: Bug label Jul 23, 2020
@guthrum
Copy link

guthrum commented Aug 6, 2020

Also getting the same issue (repo with example). So would be interested in the cause of this.

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

1 participant