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
  • #5903
Closed
Open
Issue created Apr 13, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][java] oneOf in "anonymous" schemas: model not generated.

Created by: jfeltesse-mdsol

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

As mentioned in #5706, if the openapi spec file defines a oneOf schema in responses "as is", the generator references a model in the DefaultApi but the model doesn't get generated. See examples below. edit: the same issue happens to all the places where oneOf is used without being directly under a named schema (e.g. responses, array items etc.). See the comments.

openapi-generator version

latest master: cc09118f

OpenAPI declaration file content or url

OpenApi spec file:

openapi: 3.0.3
info:
  title: oneOf test
  version: '1.0'
paths:
  /state:
    get:
      operationId: getState
      responses:
        '200':
          description: get states
          content:
            application/json:
              schema: # doesn't work
                oneOf:
                  - $ref: '#/components/schemas/ObjA'
                  - $ref: '#/components/schemas/ObjB'
                discriminator:
                  propertyName: realtype
  /state_ref:
    get:
      operationId: getStateRef
      responses:
        '200':
          description: 'get states using $ref'
          content:
            application/json:
              schema: # logically same as above but works
                $ref: '#/components/schemas/ObjAOrObjB'
components:
  schemas:
    ObjA:
      type: object
      properties:
        realtype:
          type: string
        message:
          type: string
    ObjB:
      type: object
      properties:
        realtype:
          type: string
        code:
          type: integer
    ObjAOrObjB:
      oneOf:
        - $ref: '#/components/schemas/ObjA'
        - $ref: '#/components/schemas/ObjB'
      discriminator:
        propertyName: realtype
Command line used for generation

openapi-generator generate -i spec.yaml -g java --library native -o ./out/java_oneof

Steps to reproduce
  • use spec file above
  • run command above
  • notice how src/main/java/org/openapitools/client/api/DefaultApi.java features
    import org.openapitools.client.model.GetState200;
    import org.openapitools.client.model.ObjAOrObjB;
    but the GetState200 model is not present in src/main/java/org/openapitools/client/model while ObjAOrObjB is.

@bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608 @bkabrda

Assignee
Assign to
Time tracking