-
-
Notifications
You must be signed in to change notification settings - Fork 525
Weird YAML tag in section /components/examples of auto-generated OpenAPI spec file #774
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
Comments
This is the generated OpenAPI description with your code: There is no wired tag. Additionnaly, springdoc internally doesn't generate any of these tags. It mainly relies on swagger-core and jackson for json/yaml generation. openapi: 3.0.1
info:
title: OpenAPI definition
version: v0
servers:
- url: 'http://localhost:8080'
description: Generated server url
paths:
/bug:
get:
tags:
- controller
summary: Test Bug
operationId: bug
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Umbrella'
examples:
Example with weird YAML tag:
$ref: '#/components/examples/umbrellaExample'
components:
schemas:
AbstractObject:
type: object
properties:
type:
type: string
enum:
- TYPE_A
- TYPE_B
name:
type: string
description: This reference to abstract class causes weird YAML tag to be added
discriminator:
propertyName: type
anyOf:
- $ref: '#/components/schemas/ConcreteObjectA'
ConcreteObjectA:
type: object
allOf:
- $ref: '#/components/schemas/AbstractObject'
- type: object
properties:
description:
type: string
Umbrella:
type: object
properties:
object:
$ref: '#/components/schemas/AbstractObject'
examples:
umbrellaExample:
value:
object:
type: TYPE_A
name: x
description: 'y'
Try to apply the following java code, to your type, to check the wired tag is present as well: ResolvedSchema resolvedSchema = ModelConverters.getInstance()
.resolveAsResolvedSchema(
new AnnotatedType(MyClass.class).resolveAsRef(false)); |
@bnasslahsen, thank you for such a quick response! I just tried generating the OpenAPI spec again, and still get the unwanted tag. Not really sure why you don't have it in your output. Have you used my project w/o any changes? For a clean experiment, I just did this:
I also don't know what I should look for in the With all that said, are you suggesting I should open this issue in Thanks for your help! |
Hi @EugeneDrm, My message to use ResolvedSchema, is to look for the cause in swagger library. OpenAPI openAPI = new OpenAPI()
.components(new Components()
.addExamples("umbrellaExample", new Example().value(new Umbrella(new ConcreteObjectA("x", "y"))))
);
String result = Yaml.mapper().writeValueAsString(openAPI);
Assert.isTrue(!result.contains("!<Type A>"), "should not contain wired charachter"); You can submit your ticket on the swagger-project instead: I think we can fin workaround for it in springodc. There is the following property that should be set: |
@bnasslahsen thanks, this is very helpful. |
Thanks to your clear description, a workaround will be availble on the next release of springdoc-openapi. |
The issue appears when a combination of tools is used:
Example of auto-generated OpenAPI file with unwanted tag
!<Type A>
doesn't seem to be a valid YAML tag.Swagger Online Editor tool also complains about this tag and refuses to render such YAML file.
There's a working example available at https://github.com/EugeneDrm/open-api-tag-bug
Key notes
AbstractObject
) with one or more concrete implementationsAbstractObject
) has atype
field@JsonTypeInfo
is used on the abstract class (AbstractObject
) to properly deserialize concrete implementation(s) into abstract referenceUmbrella
) which references the abstract class (AbstractObject
)Umbrella
) is defined in OpenAPIcomponents/examples
section via OpenAPI beanUmbrella
AbstractObject
Controller
Application
Expected behavior
The text was updated successfully, but these errors were encountered: