Skip to content

oneOf schema not generated > 2.3.0 #2575

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
ebcFlagman opened this issue Apr 18, 2024 · 4 comments
Closed

oneOf schema not generated > 2.3.0 #2575

ebcFlagman opened this issue Apr 18, 2024 · 4 comments
Labels
duplicate This issue or pull request already exists

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

@bnasslahsen
Copy link
Collaborator

should be fixed with #2577

@bnasslahsen bnasslahsen added the duplicate This issue or pull request already exists label Jun 15, 2024
@LouisXhaferi
Copy link

It wasn't the same problem I encountered, apparently, as I'm still seeing it in version 2.6.0.

image

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

4 participants