-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Description
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.yamlSteps to reproduce
- Download the gist YAML locally or clone this repo
- Run the generate script
- Compile the SDK:
cd java_sdk; mvn clean install - 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 InventoryRelated issues/PRs
Several issues and PRs have been reported. However, @wing328 suggested I open a bug issue for this specific problem.
- [REQ][Java][Jersey2] Generate java method for each oneOf/anyOf #6892
- [Java] Add proper support for allOf anyOf oneOf #634
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.