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
  • #4849
Closed
Open
Issue created Dec 20, 2019 by Administrator@rootContributor

[BUG][java][spring][oneOf] imports that do not exist

Created by: skchande

Description

I am using openapi-codegen version 4.2.2 and openapi specification 3.0.0 on a Windows 10 Enterprise 64bit system to generate a java server API from a yaml file. I also opened a stackoverflow question to get a possible answer. But currently I'm not sure if I have to look for the error at my place or at openapi-codegen. Therefore I have opened my first issue here today. If this is not desired, you are welcome to close the issue. It can be found here.

The problem I encounter is, that the generated code tries to import a class that does not exist. The API should accept an object of type pet and return the same pet, but it should also work with all three subtypes of Pet - Dog, Cat, Lizard.

The code generator tries to import the following classes that it did not generated:

import org.openapitools.model.OneOfCatDogLizard;
import org.openapitools.model.OneOfPet;

Furthermore the generator has generated some classes which I cannot understand at my current state of knowledge

CatAllOf.java
DogAllOf.java
LizardAllOf.java

I tried using the inheritence example from the openapi specification and build the following yaml file from it:

openapi-generator version
openapi-codegen version 4.2.2
OpenAPI declaration file content or url
openapi: 3.0.0
info:
  version: 1.0.0
  title: Three Pets
  termsOfService: http://swagger.io/terms
tags:
  - name: test
paths:
  /echoPet:
    post:
      tags:
        - test
      summary: Return input
      description: Send pet get pet
      operationId: echoPet
      parameters:
        - name: pet
          in: query
          schema:
            oneOf:
              - $ref: '#/components/schemas/Cat'
              - $ref: '#/components/schemas/Dog'
              - $ref: '#/components/schemas/Lizard'
      responses:
        "200":
          description: Pet sucesfully returned
          content:
            application/json:
                schema:
                  oneOf:
                    - $ref: '#/components/schemas/Pet'
servers:
  - url: https://localhost:8080/v2
  - url: http://localhost:8080/v2
components:
  schemas:
    Pet:
      type: object
      required:
      - pet_type
      properties:
        pet_type:
          type: string
      discriminator:
        propertyName: pet_type
        mapping:
          cachorro: Dog
    Cat:
      allOf:
      - $ref: '#/components/schemas/Pet'
      - type: object
        # all other properties specific to a `Cat`
        properties:
          name:
            type: string
          huntingSkill:
            type: string
            description: The measured skill for hunting
            enum:
            - clueless
            - lazy
            - adventurous
            - aggressive
    Dog:
      allOf:
      - $ref: '#/components/schemas/Pet'
      - type: object
        # all other properties specific to a `Dog`
        properties:
          bark:
            type: string
          packSize:
            type: integer
            format: int32
            description: the size of the pack the dog is from
            default: 0
            minimum: 0
    Lizard:
      allOf:
      - $ref: '#/components/schemas/Pet'
      - type: object
        # all other properties specific to a `Lizard`
        properties:
          lovesRocks:
            type: boolean

I validated the yaml file with openapi-generator, but found no error or warning:

$ openapi-generator validate -i test.yaml Validating spec (test.yaml) No validation issues detected.

Command line used for generation
openapi-generator generate -i test.yaml -g spring -o /tmp/springTest
Steps to reproduce
  1. create a yaml file with the content above
  2. use the command line seen above to generate java code
Related issues/PRs

The same behaviour can be observed, if you generate a server API with the following command, for jaxrs-cxf:

 openapi-generator generate -i test.yaml -g jaxrs-cxf -o /tmp/jaxrs
Suggest a fix/enhancement

Regards, skchande

Assignee
Assign to
Time tracking