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] jaxrs-spec [server] oneOf, anyOf Polymorphism does not work #5565

Open
5 of 6 tasks
s-jepsen opened this issue Mar 9, 2020 · 8 comments
Open
5 of 6 tasks

[BUG] jaxrs-spec [server] oneOf, anyOf Polymorphism does not work #5565

s-jepsen opened this issue Mar 9, 2020 · 8 comments

Comments

@s-jepsen
Copy link
Contributor

s-jepsen commented Mar 9, 2020

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Currently, openapi-generator doesn't support oneOf. It currently generates the following broken code, outputting UNKNOWN_BASE_TYPE rather than Pet for the example below.
The code is broken with or without the discriminator in the Spec.

Bug:

@Path("/pets")
@Api(description = "the pets API")
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen", date = "2020-03-09T08:49:06.102+01:00[Europe/Copenhagen]")
public interface PetsApi {

    @POST
    @Consumes({ "application/json" })
    @ApiOperation(value = "", notes = "", tags={  })
    @ApiResponses(value = { 
        @ApiResponse(code = 200, message = "created", response = Void.class) })
    Response petsPost(@Valid UNKNOWN_BASE_TYPE UNKNOWN_BASE_TYPE);
}

Expected

Generator config:

           <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>4.2.3</version>

                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>

                        <configuration>
                            <inputSpec>${project.basedir}/src/main/webapp/spec/api.yaml</inputSpec>
                            <generatorName>jaxrs-spec</generatorName>
                            <modelNameSuffix>ApiModel</modelNameSuffix>

                            <configOptions>
                                <sourceFolder>src/gen/java/main</sourceFolder>
                                <dateLibrary>java8</dateLibrary>
                                <java8>true</java8>
                                <interfaceOnly>true</interfaceOnly>
                                <returnResponse>true</returnResponse>
                                <useSwaggerAnnotations>true</useSwaggerAnnotations>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

OpenAPI Spec:

openapi: "3.0.2"
info:
  version: 1.0.0
  title: Polymorphism
paths:
  /pets:
    post:
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/Cat'
                - $ref: '#/components/schemas/Dog'
              discriminator:
                propertyName: pet_type
      responses:
        '200':
          description: created
components:
  schemas:
    # Parent
    Pet:
      type: object
      required:
        - pet_type      
      properties:
        pet_type:
          type: string
        eats:
          type: string
      discriminator:
        propertyName: pet_type
    # Child 1
    Dog:
      allOf:
        - $ref: '#/components/schemas/Pet'
        - type: object
          # all other properties specific to a `Dog`
          properties:
            bark:
              type: boolean
    # Child 2
    Cat:
      allOf:
        - $ref: '#/components/schemas/Pet'
        - type: object
          # all other properties specific to a `Cat`
          properties:
            climbs:
              type: boolean
openapi-generator version

4.2.3

OpenAPI declaration file content or url
Command line used for generation
Steps to reproduce
  1. create a pom.xml with openapi-generator-maven-plugin 4.2.3
  2. create api.yaml file above
  3. mvn clean compile
  4. see broken code under target directory \target\generated-sources\openapi\src\gen\java\main\org\openapitools\api\PetsApi.java
Related issues/PRs

This bug is related to the Server side Java code (SpringBoot)
@bkabrda has already merged PR for client Jackson Client side: #5120

Suggest a fix

Try apply client side fix from #5120 to server side.

@wing328
Copy link
Member

wing328 commented Mar 31, 2020

@s-jepsen may I know if you've time to apply the enhancement (#5120) to the server side?

@s-jepsen
Copy link
Contributor Author

Sorry, no - currently my time is limited :(

@tuxBurner
Copy link

I will give it a try need this feature to

tuxBurner added a commit to micromata/openapi-generator that referenced this issue May 11, 2020
tuxBurner added a commit to micromata/openapi-generator that referenced this issue May 12, 2020
tuxBurner added a commit to micromata/openapi-generator that referenced this issue May 13, 2020
tuxBurner added a commit to micromata/openapi-generator that referenced this issue May 14, 2020
@s-jepsen
Copy link
Contributor Author

Any news on this fix?

tuxBurner added a commit to micromata/openapi-generator that referenced this issue Jun 23, 2020
tuxBurner added a commit to micromata/openapi-generator that referenced this issue Jun 23, 2020
tuxBurner added a commit to micromata/openapi-generator that referenced this issue Jun 23, 2020
@tuxBurner
Copy link

@s-jepsen i have it running in production code and it is running. I hope it gets merged

@mmmsalo
Copy link

mmmsalo commented Jul 29, 2020

@wing328 Hey! Any updates on this bugfix? It would be nice to have this feature implemented :)

@wing328
Copy link
Member

wing328 commented Nov 9, 2020

For oneOf, anyOf, please give the Java (jersey2, native) client generator a try as these generators have better support for oneOf, anyOf.

@sonic-martin
Copy link

Any update for the jaxrs-spec generator on this topic?

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

5 participants