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
@ApiResponse response parameter not used in 3.0.0 #3503
Comments
@varjasz do you find any solution? |
No, but I wasn't looking for it. |
Thanks for reporting @varjasz |
Same issue here. Line 117 in 07a4c86
Springfox 3.0 uses v3 models by default, but |
The prescribed workaround doesn't seem to work for |
I can confirm the fix with On the other hand, shouldn't it work out of the box with doc type |
Also getting this on springfox 3.0.0 using OAS_30. Specifically, the problem is that my POST requests to a JPA respository return a body with 201 responses, which are incorrectly labelled to have no body. Overriding this using edit: I believe the issue for me comes from here: Lines 187 to 198 in ab58684
edit 2: I've traced this back to Lines 40 to 57 in ab58684
It adds support for PUT, PATCH, POST, but doesn't set the media types it produces and consumes, causing edit 3: from the spring rest docs, the only valid media types are |
I tried with After a few hours I found a way to add my custom errors as a global response. It may not be a suitable solution if your endpoints have different custom errors, but in my case it was good enough and hopefully it will save someone's time, so I'll share it anyway. Here's an example on how to add the class @Bean
public Docket api(TypeResolver typeResolver) {
return new Docket(DocumentationType.SWAGGER_2)
.useDefaultResponseMessages(false)
// omitted config...
.additionalModels(
typeResolver.resolve(CustomError.class)
)
.globalResponses(
HttpMethod.POST,
List.of(
new ResponseBuilder()
.code("400")
.description("some description..")
.representation(MediaType.APPLICATION_JSON)
.apply(r ->
r.model(m ->
m.referenceModel(rm ->
rm.key(k ->
k.qualifiedModelName(q ->
q.namespace(CustomError.class.getPackageName())
.name(CustomError.class.getSimpleName()))))))
.build()
))
} Note that you need to register the class with |
As already pointed out, the bug is tied to an empty set of I would recommend avoid setting FYI... root cause of this particular issue is tied to |
@ale-rd 's solution worked, and it's still possible to add custom error responses by specifying |
Is there any update on this issue? |
I got the same issue, but it's caused by spring.main.lazy-initialization = true, so don't override this configuration. Spring Boot 2.7.2 |
set your @XXXXXMapping produces value on your operation i.e : @GetMapping(value="/endpoint", produces={"application/json"}). That would solve your problem ;) |
Starting with 3.0.0 (in 2.9.2 it worked properly)
@ApiResponse(code = 404, message = "Not Found", response = CustomError::class)
The 404 - Not Found is in the documentation, but the defined response (CustomError in example) not shown in the generated documentation (response sample and model)
The text was updated successfully, but these errors were encountered: