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

OpenAPI 3.1.0 support: [Bug] Wrong field in 'Example value' when using oneOf #9198

Closed
bartgut opened this issue Sep 8, 2023 · 2 comments · May be fixed by codingfragments/tvh-guide#134
Closed

Comments

@bartgut
Copy link

bartgut commented Sep 8, 2023

Q&A (please complete the following information)

Content & configuration

Example Swagger/OpenAPI definition:

openapi: 3.1.0
info:
  title: test
  version: '1.0'
paths:
  /test/route:
    get:
      operationId: getTestRoute
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Entity'
components:
  schemas:
    Entity:
      oneOf:
      - $ref: '#/components/schemas/EntityChild1'
      - $ref: '#/components/schemas/EntityChild2'
      discriminator:
        propertyName: $type
        mapping:
          EntityChild1: '#/components/schemas/EntityChild1'
          EntityChild2: '#/components/schemas/EntityChild2'
    EntityChild1:
      required:
      - a
      - b
      - c
      - $type
      type: object
      properties:
        a:
          type: string
        b:
          type: string
        c:
          type: string
        $type:
          type: string
    EntityChild2:
      required:
      - a
      - b
      - d
      - $type
      type: object
      properties:
        a:
          type: string
        b:
          type: string
        d:
          type: string
        $type:
          type: string

Swagger-UI configuration options:

Using https://editor-next.swagger.io

Describe the bug you're encountering

Parameter "c" is added to the EntityChild2 in "Example value" although this field is not in this entity.

To reproduce...

Steps to reproduce the behavior:

  1. Go to https://editor-next.swagger.io
  2. Paste the above mentioned YAML file

Expected behavior

Example response value for the /test/route endpoint should be:

  {
    "a": "string",
    "b": "string",
    "c": "string",
    "$type": "EntityChild1"
  },
  {
    "a": "string",
    "b": "string",
    "$type": "EntityChild2",
    "d": "string"
  }
]

instead

  {
    "a": "string",
    "b": "string",
    "c": "string",
    "$type": "EntityChild1"
  },
  {
    "a": "string",
    "b": "string",
    "c": "string",
    "$type": "EntityChild2",
    "d": "string"
  }
]

"c" parameter does not belong to EntityChild2 so it should not be there.

Additional context or thoughts

Happens in Scala using Tapir as well. When switching back to OpenAPI 3.0.3 everything seems to be fine

@bartgut bartgut changed the title [Bug] Wrong field in 'Example' value when using oneOf [Bug] Wrong field in 'Example value' when using oneOf Sep 8, 2023
@char0n char0n changed the title [Bug] Wrong field in 'Example value' when using oneOf OpenAPI 3.1.0 support: [Bug] Wrong field in 'Example value' when using oneOf Nov 13, 2023
@InterStella0
Copy link

This happened for anyOf as well.

@char0n
Copy link
Member

char0n commented Apr 23, 2024

Addressed in #9853

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

Successfully merging a pull request may close this issue.

4 participants