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

Support for using oneOf in response body #8100

Open
harshmeet001 opened this issue Jul 18, 2022 · 0 comments
Open

Support for using oneOf in response body #8100

harshmeet001 opened this issue Jul 18, 2022 · 0 comments

Comments

@harshmeet001
Copy link

harshmeet001 commented Jul 18, 2022

Q&A (please complete the following information)

  • OS: macOS Big Sur, 11.4

  • Browser: chrome

  • Version: 103.0.5060.53

  • Swagger-UI version: 3.0.0

  • Swagger/OpenAPI version: 3.0.3

Content & configuration

Unable to generate response object using oneOf keyword

Swagger/OpenAPI definition:

openapi: 3.0.3
info:
  title: AnimalKingdom
  description: AnimalKingdom
  version: 1.0.0
servers:
  - url: 'http://pets-api.animalkingdom-devjungle.com'
paths:
  /v1/search/pets:
    get:
      responses:
        '200':
                  description: OK
                  content:
                    application/json:
                      schema:
                        oneOf:
                          - $ref: '#/components/schemas/Cat'
                          - $ref: '#/components/schemas/Dog'
                          - $ref: '#/components/schemas/Hamster'
      summary: 'An API which returns different types of pets'
components:
  schemas:
    Cat:
      type: object
      properties:
        hunts:
          type: boolean
        age:
          type: integer
    Dog:
      type: object
      properties:
        hunts:
          type: boolean
        age:
          type: integer
        breed:
          type: string
          enum: [ Dingo, Husky, Retriever, Shepherd ]
    Hamster:
        type: object
        properties:
          hunts:
            type: boolean
          age:
            type: integer
          food:
            type: boolean

Swagger-UI configuration options:

SwaggerUI({
  // your config options here
})
?yourQueryStringConfig

Screenshots

image

image

image

image

image

How can we help?

The OpenAPI Generator does not generate the interface correctly when using oneOf.
The ApiResponse is OneOfCatDogHamster.class as seen in the screen shot which is not a generated class.
I want to use the oneOf operator to validate that the api responds with one of cat, dog or hamster class.
Is this even possible to do, if so what am i doing wrong and what is the suggested way to use oneOf keyword in respone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant