You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thank you for implementing #2963, but it seems to be it is not working yet.
Describe the bug application/problem+json content type should be generated for endpoints, where the content type is not explicitly overridden,
but it still generates the default produces media type.
To Reproduce
Has the same setup as described in the referenced ticket, but with Springdoc 2.8.7 (or preferably 2.8.8)
Spring configuration:
...
importorg.springframework.http.ProblemDetail
@ControllerAdvice
classGlobalExceptionHandler {
@ExceptionHandler
@ApiResponse(responseCode ="404", description ="Description for API users...")
funmyCustomError(exception:MyCustomException) =ProblemDetail.forStatus(HttpStatus.BAD_REQUEST)
}
(I replaced ResponseStatus with ApiResponse just to provide a description to the users of the API, but from the code it seems like (from commit 0cd571a), the ApiResponse annotation also required for the automated ProblemDetail content type resolver to work)
Investigate that the generated content type is still the default media type, not the application/problem+json.
'400':
description: Bad Requestcontent:
application/json:
schema:
$ref: '#/components/schemas/ProblemDetail'
Expected behavior
The RFC defined problem detail content type is generated in the OpenAPI documentation.
Screenshots
Seems like the check for replacing the content type only checks for the configuration default content type */*, instead of
the springdoc.default-produces-media-type configured one.
Additional context
Possible solution:
I have not tested it, but if I get this right, instead of using MediaType.ALL_VALUE in line:
Note I got it working by adding the @ApiResponse explicitly, but it's a bit tedious and contains a lot of duplication to that for all exception handlers.
Also note I'm using a custom ProblemDetailDto which contains @Schema descriptions for better documentation..
@RestControllerAdvice
class GlobalExceptionHandler : ResponseEntityExceptionHandler() {
companion object {
private val BLANK_TYPE: URI = URI.create("about:blank")
}
@ExceptionHandler(value = [Throwable::class], produces = [APPLICATION_PROBLEM_JSON_VALUE])
@ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR)
@ApiResponse(
responseCode = "500",
content = [
Content(
mediaType = APPLICATION_PROBLEM_JSON_VALUE,
schema = Schema(implementation = ProblemDetailDto::class),
),
],
)
fun error(e: Throwable): ResponseEntity<ProblemDetailDto> {
val status = HttpStatus.INTERNAL_SERVER_ERROR
val problemDetail =
ProblemDetailDto(
type = BLANK_TYPE,
status = status.value(),
title = status.reasonPhrase,
)
return ResponseEntity
.status(status)
.contentType(APPLICATION_PROBLEM_JSON)
.body(problemDetail)
}
}
Thank you for implementing #2963, but it seems to be it is not working yet.
Describe the bug
application/problem+json
content type should be generated for endpoints, where the content type is not explicitly overridden,but it still generates the default produces media type.
To Reproduce
Has the same setup as described in the referenced ticket, but with Springdoc 2.8.7 (or preferably 2.8.8)
Spring configuration:
(I replaced
ResponseStatus
withApiResponse
just to provide a description to the users of the API, but from the code it seems like (from commit 0cd571a), theApiResponse
annotation also required for the automatedProblemDetail
content type resolver to work)application/problem+json
.Expected behavior
Screenshots

Seems like the check for replacing the content type only checks for the configuration default content type
*/*
, instead ofthe
springdoc.default-produces-media-type
configured one.Additional context
Possible solution:
I have not tested it, but if I get this right, instead of using
MediaType.ALL_VALUE
in line:springdoc-openapi/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/GenericResponseService.java
Line 451 in 0cd571a
springdoc-openapi/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/GenericResponseService.java
Line 454 in 0cd571a
it should use:
springDocConfigProperties.getDefaultProducesMediaType()
.Output of `./gradlew -q :app:dependencyInsight --dependency org.springdoc`:
The text was updated successfully, but these errors were encountered: