Openapi-generator: [Java] Add proper support for allOf anyOf oneOf

Created on 24 Jul 2018  路  11Comments  路  Source: OpenAPITools/openapi-generator

Description

In the openApiSpec it is possible to define a schema with properties, where one property can be defined directly or be using _oneOf_ _anyOf_ or _allOf_ and passing the some provided Schemas.

Currently only allOf is considered and only the first of these schemas is taken (allOf requires all of them!). The other two delimiter are not even considered.

The following example makes it only possible to set the CustomProperties.

openapi-generator version

3.1.1

OpenAPI declaration file content or url

Sample Snippet.:

info:
  title: test
  version: 1.0.0
paths:
  /test:
    get:
      responses:
        '200':
          description: All good
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/ObjectWithProps'
      operationId: get
      summary: Get object with properties.
components:
  schemas:
    ObjectWithProps:
      properties:
        properties:
          allOf:
           - $ref: '#/components/schemas/CustomProperties'
           - $ref: '#/components/schemas/Properties'
      description: An object with difined and undifined keys.
    CustomProperties:
      description: The custom properties key.
      type: object
      properties:
        'someDefinedKey':
          type: object
          additionalProperties:
            type: object
    Properties:
      description: The wildcard properties key.
      type: object
      additionalProperties:
        type: object
openapi: 3.0.0
Steps to reproduce
java -jar ${PathToOpenApiGeneratorJAR3.1.1} generate \
 -i /path/swagger3.yaml \
 -o /path/swagger3-client \
 --api-package "com.123" \
 --model-package "com.123" \
 --group-id "com.123" \
 --artifact-id "123" \
 --artifact-version "SNAPSHOT" \
 -c ./java-options.json \
 -g java

JavaOptions:

{
  "java8": true,
  "dateLibrary": "java8"
}
Java Feature Composition / Inheritance Java help wanted

Most helpful comment

Any news?

All 11 comments

Related issues:

  • oneOf: discussion take place in #15.
  • anyOf: #537, #559.
  • allOf: there are also some issues

Looking forward to this feature ! I will be happy to help testing it if you need some help.

I've just run into the same problem with the Spring generator.

I've just run into the same problem with the jaxrs-resteasy (3.2.0).
I will also be happy to help testing it if you need some help.

I have the same issue, is there any plan to support "anyOf" tag?

Hi folks, I've added better support of allOf, anyOf and oneOf via #1360. Please give it a try and let us know if you've any feedback. Clearly, some works need to be done in the Java client templates to better support oneOf and anyOf.

Any news?

Any news?

Heys, can you guys please try the branch "improve-java" (https://github.com/OpenAPITools/openapi-generator/tree/improve-java) ? I've only added oneOf support but anyOf support can be easily added if you guys are ok with my approach.

Example:

git clone https://github.com/OpenAPITools/openapi-generator
git checkout improve-java
mvn clean package -DskipTests
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java --library jersey2-experimental -i https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/oneOf.yaml -o /tmp/oneOfTest/ --skip-validate-spec

@wing328 i don鈥檛 see the branch anymore. Did it get merged?

Please check out the latest master: java generator with the jersey2library

Was this page helpful?
0 / 5 - 0 ratings