swagger-core
swagger-core copied to clipboard
Cast to ComposedSchema fails in case of OpenApi 3.1 with oneOf, anyOf, allOf
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
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
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