swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

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

Open quovide opened this issue 10 months ago • 0 comments

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

quovide avatar Apr 16 '24 14:04 quovide