swagger-api / swagger-core

Examples and server integrations for generating the Swagger API Specification, which enables easy access to your REST API
http://swagger.io
Apache License 2.0
7.36k stars 2.17k forks source link

Cast to ComposedSchema fails in case of OpenApi 3.1 with oneOf, anyOf, allOf #4657

Open quovide opened 2 months ago

quovide commented 2 months ago

The cast to ComposedSchema here:

https://github.com/swagger-api/swagger-core/blob/95c8253c5239f6e980acd0b2998d037b35eb8761/modules/swagger-core/src/main/ java/io/swagger/v3/core/util/AnnotationsUtils.java#L827 https://github.com/swagger-api/swagger-core/blob/95c8253c5239f6e980acd0b2998d037b35eb8761/modules/swagger-core/src/main/ java/io/swagger/v3/core/util/AnnotationsUtils.java#L834 https://github.com/swagger-api/swagger-core/blob/95c8253c5239f6e980acd0b2998d037b35eb8761/modules/swagger-core/src/main/ java/io/swagger/v3/core/util/AnnotationsUtils.java#L841

image

Will cause a ClassCastException when generating OpenAPI 3.1 ComposedSchema is only created when OpenAPI is not 3.1.

See: https://github.com/swagger-api/swagger-core/blob/95c8253c5239f6e980acd0b2998d037b35eb8761/modules/swagger-core/src/main/java/io/swagger/v3/core/util/AnnotationsUtils.java#L605

image

Removing the cast will resolve the issue. But I don't know this issue exists due to non compatibility with OpenAPI 3.1 or if it's a mere programming error.

The intended annotation use is: @ApiResponse(responseCode = "200", description = "Get a foorter", content = @Content(schema = @Schema(anyOf = { Footer.class, Footer2.class }) Object getFooter();

Maybe this issue is related to #4634