Skip to content

Commit ceb4a10

Browse files
committed
application/problem+json content type is not set for ProblemDetails. Fixes #2982
1 parent a23005b commit ceb4a10

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/GenericResponseService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,10 +448,11 @@ private void buildGenericApiResponses(Components components, MethodParameter met
448448
if (apiResponse != null) {
449449
Content content = apiResponse.getContent();
450450
if (content != null) {
451-
io.swagger.v3.oas.models.media.MediaType mediaType = content.get(MediaType.ALL_VALUE);
451+
String defaultProducesMediaType = springDocConfigProperties.getDefaultProducesMediaType();
452+
io.swagger.v3.oas.models.media.MediaType mediaType = content.get(defaultProducesMediaType);
452453
if (mediaType != null && ProblemDetail.class.isAssignableFrom(methodParameter.getParameterType())) {
453454
content.addMediaType(MediaType.APPLICATION_PROBLEM_JSON_VALUE, mediaType);
454-
content.remove(MediaType.ALL_VALUE);
455+
content.remove(defaultProducesMediaType);
455456
}
456457
}
457458
}

springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app124/SpringDocApp124Test.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
import test.org.springdoc.api.v31.AbstractSpringDocTest;
2727

2828
import org.springframework.boot.autoconfigure.SpringBootApplication;
29+
import org.springframework.test.context.TestPropertySource;
2930

3031

3132
/**
3233
* Tests Spring meta-annotations as method parameters
3334
*/
35+
@TestPropertySource(properties = "springdoc.default-produces-media-type=application/json")
3436
public class SpringDocApp124Test extends AbstractSpringDocTest {
3537

3638
@SpringBootApplication

springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.1.0/app124.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"418": {
5454
"description": "I'm a teapot",
5555
"content": {
56-
"*/*": {
56+
"application/json": {
5757
"schema": {
5858
"type": "object"
5959
}

0 commit comments

Comments
 (0)