swagger-ui
swagger-ui copied to clipboard
OpenAPI 3.1.0 support: [Bug] Wrong field in 'Example value' when using oneOf
Q&A (please complete the following information)
- OS: macOS
- Browser: safari
- Version: 22
- Method of installation: via Tapir in Scala/using https://editor-next.swagger.io
- Swagger-UI version: 5.4.2 - https://mvnrepository.com/artifact/com.softwaremill.sttp.tapir/tapir-swagger-ui_2.13/1.7.3
- Swagger/OpenAPI version: OpenAPI 3.1.0
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:
- Go to https://editor-next.swagger.io
- 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
This happened for anyOf as well.
Addressed in https://github.com/swagger-api/swagger-ui/pull/9853