Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #7988
Closed
Open
Issue created Nov 20, 2020 by Administrator@rootContributor

[BUG] [Java] JAX-RS Jersey Compile errors when using oneOf in OpenApi definition

Created by: seybi87

Bug Report Checklist

  • [ x] Have you provided a full/minimal spec to reproduce the issue?
  • [ x] Have you validated the input using an OpenAPI validator (example)?
  • [ x] Have you tested with the latest master to confirm the issue still exists?
  • [ x] Have you searched for related issues/PRs?
  • [ x] What's the actual output vs expected output?
  • [ x] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

I have the validated the following openapi.yaml that uses the oneOf keyword and I tried the latest openapi-generator-cli-5.0.0-beta3 and the stable openapi-generator-cli-4.3.1 to create a server stub for JAX-RS Jersey:

openapi: 3.0.0
info:
  version: 0.0.1
  title: oneOf example
  description: ''


paths:
 /animal:
    post:
      summary: Create a new animal   
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Animal'
              
      responses:
        '201':
          description: Created        
 
components:
  schemas:
 
    Animal:
      type: object
      properties:
        name: 
          type: string
        props:  
          oneOf:
            - $ref: '#/components/schemas/Fish'
            - $ref: '#/components/schemas/Dog'
          discriminator:
              propertyName: animalType  
      
    Fish:
      type: object
      properties:
        animalType:
          type: string
        depth:
          type: integer
      required:
          - depth 
          - animalType   
      additionalProperties: false    

    Dog:
      type: object
      properties:
        animalType:
          type: string
        country:
          type: string   
      required:
          - country   
          - animalType
      additionalProperties: false      

The generated jax-rs server code produces the following compile error. This error with produced by both tested openapi-generator versions (4.3.1 and 5.0.0-beta3) even though the bugfix of #7263 in 5.0.0-beta3 should have resolved the issue.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project openapi-jaxrs-server: Compilation failure: Compilation failure:
[ERROR] /debugging/openapi-5.0.3-beta/jax-rs-server/src/gen/java/org/openapitools/model/Animal.java:[21,30] cannot find symbol
[ERROR]   symbol:   class OneOfFishDog
[ERROR]   location: package org.openapitools.model
[ERROR] /debugging/openapi-5.0.3-beta/jax-rs-server/src/gen/java/org/openapitools/model/Animal.java:[41,11] cannot find symbol
[ERROR]   symbol:   class OneOfFishDog
[ERROR]   location: class org.openapitools.model.Animal
[ERROR] /debugging/openapi-5.0.3-beta/jax-rs-server/src/gen/java/org/openapitools/model/Animal.java:[63,23] cannot find symbol
[ERROR]   symbol:   class OneOfFishDog
[ERROR]   location: class org.openapitools.model.Animal
[ERROR] /debugging/openapi-5.0.3-beta/jax-rs-server/src/gen/java/org/openapitools/model/Animal.java:[75,10] cannot find symbol
[ERROR]   symbol:   class OneOfFishDog
[ERROR]   location: class org.openapitools.model.Animal
[ERROR] /debugging/openapi-5.0.3-beta/jax-rs-server/src/gen/java/org/openapitools/model/Animal.java:[79,24] cannot find symbol
[ERROR]   symbol:   class OneOfFishDog
[ERROR]   location: class org.openapitools.model.Animal
openapi-generator version
  • stable: 4.3.1
  • latest snapshot: 5.0.0-beta3
Generation Details

java -jar openapi-generator-cli-5.0.0-beta.jar generate -i openapi.yaml -g jaxrs-jersey -o jax-rs-server/

Steps to reproduce
  • create directory debugging
  • save the above definition to debugging/openapi.yaml
  • download openapi-generator to debugging
  • mkdir debugging/jax-rs-jersey
  • cd debugging && ava -jar openapi-generator-cli-5.0.0-beta3.jar generate -i openapi.yaml -g jaxrs-jersey -o jax-rs-server/
Related issues/PRs

#7263

#7789

#7414

#7256

#7235

Sponsorship

I am happy to sponsor this fix with 200$ cc @wing328

Assignee
Assign to
Time tracking