Skip to content

Type information is lost on wildcard generic operation parameters or return types #434

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

Closed
robfletcher opened this issue Feb 16, 2020 · 1 comment

Comments

@robfletcher
Copy link

If a controller operation has a parameter or return type with a wildcard generic type, the type information is lost and any customizers will see the generically typed property of the class as just an Object rather than the upper bound of the type parameter.

This is fairly complex so I've created an example on a fork of the project: robfletcher@6f212b2

When considering the parameter and response types of the controller method here: robfletcher@6f212b2#diff-3cea84ffe0d7e0808cc1ed9cd9c1fe9aR16-R18

With the wildcard the schemas in the API treat the PetRecord.pet property as just an object. If I change the generic declarations on the controller to PetRecord<? extends Pet> then it works correctly. However, this shouldn't be necessary since that is just re-declaring the same variance as on the PetRecord class. Removing the generic type altogether also works (with a compiler warning). I originally ran into this problem in a Kotlin codebase where omitting the generic type is not possible.

@bnasslahsen
Copy link
Collaborator

bnasslahsen commented Feb 16, 2020

Hi @robfletcher,

As you know we rely on swagger-core official libraries.
The behaviour that you are describing is related to swagger-core. There is still some related issues:

You can use the attached ModelConverter, is a kind of fix and should help you achieve your goal.
Let me know if that helps, so we can plan to integrate it in future releases:

@springdoc springdoc deleted a comment from robfletcher Jun 1, 2021
@springdoc springdoc deleted a comment from iliecirciumaru Jun 1, 2021
@springdoc springdoc locked as off-topic and limited conversation to collaborators Jun 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants