springdoc-openapi
springdoc-openapi copied to clipboard
oneOf schema not generated > 2.3.0
We have a Exception handler which can handle oneOf subclasses of a exception. But since springdoc version > 2.3.0 we have the problem, that this schemas no longer be generated.
@ExceptionHandler(ApiException.class)
@ApiResponse(
responseCode = "400",
description = "Bad Request",
content = @Content(
mediaType = BaseController.API_V3_JSON,
schema = @Schema(oneOf = {
ExceptionResponse.class,
EsbException.EsbExceptionResponse.class,
ValidationException.ValidationExceptionResponse.class})))
@ApiResponse(
responseCode = "404",
description = "Not found",
content = @Content(
mediaType = BaseController.API_V3_JSON,
schema = @Schema(oneOf = {
ExceptionResponse.class,
EsbException.EsbExceptionResponse.class})))
@ApiResponse(
responseCode = "500",
description = "Internal Server Error",
content = @Content(
mediaType = BaseController.API_V3_JSON,
schema = @Schema(oneOf = {
ExceptionResponse.class,
EsbException.EsbExceptionResponse.class})))
@ApiResponse(
responseCode = "504",
description = "Gateway Timeout, the connection to the ESB timed out",
content = @Content(
mediaType = BaseController.API_V3_JSON,
schema = @Schema(implementation = ExceptionResponse.class)))
public ResponseEntity<ExceptionResponse> processApiException(ApiException exception) {
log.error(exception.toString());
return new ResponseEntity<>(exception.getExceptionResponse(environment), exception.getStatus());
}
In the swagger-ui we see then this error
I didn't found anything related in the release notes of 2.4.0, are we missing something?
Ran into the same problem, created a reproduction repository for this issue. Issue seems to happen due removeBrokenReferenceDefinitions
. When setting springdoc.remove-broken-reference-definitions
to false the issue doesn't seem to happen.
After a little debugging I found out the response schema class 2.3.0 is ComposedSchema
, while it is just a Schema
for 2.4.0+.
Edit: It looks like @mschout already created a fix for this: #2577. Tested it with my repository and seems to solves the issue.
We ran into a similar (maybe the same?) issue when trying to use polymorphic types, like:
@JsonTypeInfo(use = NAME, include = PROPERTY, property = DISCRIMINATOR_PROPERTY)
@JsonSubTypes(
Type(value = Activate::class, name = ACTIVATE)
)
@Schema(
subTypes = [Activate::class],
oneOf = [Activate::class],
discriminatorProperty = DISCRIMINATOR_PROPERTY,
discriminatorMapping = [
DiscriminatorMapping(value = ACTIVATE, schema = Activate::class)
]
)
sealed interface PolymorphicEvent {
@Schema(requiredProperties = [DISCRIMINATOR_PROPERTY])
@SchemaProperty(name = DISCRIMINATOR_PROPERTY, schema = Schema(allowableValues = [ACTIVATE]))
data object Activate : PolymorphicEvent
companion object {
const val DISCRIMINATOR_PROPERTY = "type"
const val ACTIVATE = "ACTIVATE"
}
}
Defining this in 2.3.0 would work, but totally broke our Schema view in SwaggerUI after 2.5.0, where the oneOf
definition just references itself recursively forever. (This might even be worth a second issue)
should be fixed with https://github.com/springdoc/springdoc-openapi/pull/2577
It wasn't the same problem I encountered, apparently, as I'm still seeing it in version 2.6.0.