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

Schemas for subclasses not rendered in GraalVM native image builds #1252

Closed
psinghal04 opened this issue Aug 28, 2021 · 2 comments
Closed

Schemas for subclasses not rendered in GraalVM native image builds #1252

psinghal04 opened this issue Aug 28, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@psinghal04
Copy link

psinghal04 commented Aug 28, 2021

Describe the bug
When either the request or response payloads are subclasses in a class hierarchy, the generated OpenAPI UI content does not render the schemas for subclasses, when the Spring Boot app is built and run as a native image using Spring Native and GraalVM. The schemas are rendered properly when the same code is run under non-native, JVM mode.

To Reproduce
Steps to reproduce the behavior:

  • What version of spring-boot you are using?
    2.5.4

  • What modules and versions of springdoc-openapi are you using?
    springdoc-openapi-ui 1.5.10
    springdoc-openapi-security 1.5.10

  • What is the actual and the expected result using OpenAPI Description (yml or json)?

    Expected:
    {"content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/ChildA"},{"$ref":"#/components/schemas/ChildB"},{"$ref":"#/components/schemas/ChildC"}]}}},"required":true}

    Actual:
    {"content":{"application/json":{"schema":{},"exampleSetFlag":false}}

  • Provide with a sample code (HelloController) or Test that reproduces the problem

    @GetMapping("/children/{childId}")
    @Operation(summary = "Get child by child ID")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "Found the child"),
            @ApiResponse(responseCode = "404", description = "Child not found", content = @Content)
    })
    public AbstractChild byChildId(@PathVariable("childId") String childId) {
        return childrenRepo.findFirstByChildId(childId).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "No child found"));
    }

Note: ChildA, ChildB and ChildC are concrete subclasses of AbstractChild

Expected behavior
The behavior should be the same when the code is run in non-native JVM mode, as well as when the code is built and run as native image using GraalVM and Spring Native. Currently, the non-native JVM mode correctly renders the schema for the class hierarchy in the "schema: oneOf" format, whereas the native build does not generate any schema for the subclasses.

Additional context
Spring Boot 2.5.4
Spring API Doc 1.5.10
Spring Native 0.10.3
GraalVM CE 21.2.0 (build 11.0.12+6-jvmci-21.2-b08

@bnasslahsen
Copy link
Contributor

@psinghal04,

I can confirm it's reproducible with v1.5.10.
I have added a fix that you can test using the latest available snapshot v1.5.11-SNAPHOT.

@psinghal04
Copy link
Author

psinghal04 commented Sep 1, 2021

@bnasslahsen , I can confirm that the latest v1.5.11-SNAPSHOT fixes the issue I reported. The subclass schema is now generated properly by my native image build. Thanks!

@bnasslahsen bnasslahsen added the bug Something isn't working label Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants