-
-
Notifications
You must be signed in to change notification settings - Fork 517
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
Schema replaced by String when using @ApiResponse with RepresentationModel (Hateoas links) #2902
Comments
Just want to add, we're seeing the same problem. |
Not reproducible. git clone https://github.com/didjoman/springdoc-nullable_fields-issue
mvn spring-boot:run
curl --location --request GET 'http://localhost:8080/api-docs' --header 'Content-Type: application/json' This the result of your project: {
"openapi":"3.1.0",
"info":{
"title":"OpenAPI definition",
"version":"v0"
},
"servers":[
{
"url":"http://localhost:8080",
"description":"Generated server url"
}
],
"paths":{
"/cat":{
"get":{
"tags":[
"basic-controller"
],
"summary":"get",
"description":"Provides an animal.",
"operationId":"get",
"parameters":[
{
"name":"cat",
"in":"query",
"required":true,
"schema":{
"$ref":"#/components/schemas/Cat"
}
}
],
"responses":{
"200":{
"description":"OK",
"content":{
"*/*":{
"schema":{
"type":"string"
}
}
}
}
}
}
}
},
"components":{
"schemas":{
"Cat":{
"type":"object",
"description":"Represents a Cat class.",
"properties":{
"name":{
"type":"string",
"description":"The name."
}
}
}
}
}
} This ticket will be closed, but can be reopened if your provide the reproducible sample. |
@bnasslahsen the |
Would you be able to provide a reproducible sample? |
Hi @bnasslahsen yes - try this: https://github.com/smurf667/springdoc-npe |
Thank you for the weekend work, much appreciated 👍 |
Hi, |
Describe the bug
When using the annotation
@ApiResponse
with a content and a mediatype, the schema of my response object is being replaced by a String (instead of the reference to the actual schema).Example:
This is due to a
NullPointerException
occuring in the newHateoasLinksConverter
.The stacktrace (not displayed as catched in
SpringDocAnnotationsUtils
line 442) :How to reproduce
git clone https://github.com/didjoman/Springdoc-String-Schema-returned-mediatype-issue
Run the application (spring boot).
Run curl --location --request GET 'http://localhost:8080/api-docs' --header 'Content-Type: application/json'
Expected behavior
I expect to have the same OAS generated as before v2.8.2, that is to say:
Actual behavior
Since v2.8.2 I have this, the
Response
schema is not generated and its reference in the path is replaced by the type String:Additional context
The issue did not occur before v2.8.2, and it is still present in v2.8.4.
I think it may be related to this commit 88f5da0 introducing the HateoasLinkConverter. But it's not clear what should be done to fix it.
Maybe, the swagger-core.ModelResolver should be called with a
new AnnotatedType(returnType) .resolveAsRef(true).jsonViewAnnotation(jsonView).ctxAnnotations(annotations)
as it is done inSpringDocAnnotationsUtils.extractSchema()
line 138 ? Because, here it gets called withresolveAsRef(false)
, then theref
is not added to the schema at lineModelResolver.resolve()
line 1060 and then it breaks inHateoasLinksConverter.resolve()
line 74.Thank you for your help :)
The text was updated successfully, but these errors were encountered: