OpenAPITools / OpenAPITools/openapi-generator

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

Open
#7,033 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

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

  • #6892
  • #634

A possibly related issue in the final comment here:
https://github.com/OpenAPITools/openapi-generator/pull/4785#issuecomment-630020644

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the sample specification from the linked gist or openapi.yaml in the reproduction repository, then run the documented Java generator command with the jersey2 library. Inspect the generated model/Inventory.java and the missing AnyOfShapesConstraintColorsConstraint and OneOfSmallLarge classes, then run mvn clean install. Done means the oneOf and anyOf models are generated and the client compiles successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.