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

Allow ComposedSchemas to replace non-composed so we can respect polymorphic links discovered in later methods #1620

Merged
merged 2 commits into from Apr 20, 2022

Conversation

slw546
Copy link

@slw546 slw546 commented Apr 19, 2022

Paths are inspected in reverse alphabetical order, with the first schema generated any inserted into components taking precedence.

Therefore if you have paths e.g.

    @GetMapping("/any")
    public Pet aaaagetAnyPet() {
        return new Cat(true, "cat");
    }

    @GetMapping("/zzzzzdog")
    public Dog zzzzgetDog() {
        return new Dog(true, "dog");
    }

...
class Dog extends Pet
class Cat extends Pet
class Pet

We'll generate Dog first by inspecting zzzGetDog, which isn't composed because we are returning Dog directly.
We then generate Pet and subtypes when we find the other method. At this point we should replace the existing Dog component with the new composed one, as we're now aware that we care about the polymorphism, but the existing code skips the existing key for Dog, meaning the spec incorrectly presents Dog as unrelated to Pet.

Meanwhile, as Pet and Cat were not previously generated, Cat is correctly emitted as a subtype of Pet with an allOf Pet reference.

As far as I can tell, this issue hasn't cropped up before in examples or existing tests because the path naming has always been such that Pet generated first by conincidence, which meant a ComposedSchema for Dog would already be present in the components.

…esn't prevent polymorphic links generating into the spec
@bnasslahsen bnasslahsen merged commit c7c31fc into springdoc:master Apr 20, 2022
@bnasslahsen
Copy link
Contributor

@slw546,

Thank your contribution to the project!

bnasslahsen added a commit that referenced this pull request Apr 20, 2022
…an respect polymorphic links discovered in later methods #1620
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants