Skip to content
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

oneOf schema not generated > 2.3.0 #2575

Open
ebcFlagman opened this issue Apr 18, 2024 · 2 comments
Open

oneOf schema not generated > 2.3.0 #2575

ebcFlagman opened this issue Apr 18, 2024 · 2 comments

Comments

@ebcFlagman
Copy link

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

image

I didn't found anything related in the release notes of 2.4.0, are we missing something?

@felhag
Copy link

felhag commented Apr 19, 2024

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.

@LouisXhaferi
Copy link

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)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants