Skip to content

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
Collaborator

@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
mpleine pushed a commit to mpleine/springdoc-openapi that referenced this pull request May 17, 2025
…an respect polymorphic links discovered in later methods springdoc#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.

2 participants