springdoc-openapi icon indicating copy to clipboard operation
springdoc-openapi copied to clipboard

Issue with displaying generics model and return type in Swagger UI

Open tonjack opened this issue 6 years ago • 1 comments

Describe the bug We are having issues on displaying generics model as a return type for our controller in Swagger UI. Instead of showing GenericModel, it is showing GenericModelType. In Springfox, we are able to either show GenericModel or GenericModelOfType (http://springfox.github.io/springfox/docs/snapshot/#changing-how-generic-types-are-named). How can we achieve the same representation of generic model as return type using springdoc-openapi?

To Reproduce Steps to reproduce the behavior:

  • Currently using spring boot 2.2.6 with Java 11
  • springdoc-openapi-ui version 1.3.0

Given this generic model:

public class BaseApiResponse<T> {
    private T data;
    private List<Error> errors = new ArrayList();
    private List<Message> messages = new ArrayList();
}

When we are returning the following type in our controller:

public ResponseEntity<BaseApiResponse<Account>> get(@PathVariable Long id) throws ResourceNotFoundException {
}

The schema created in the Swagger UI and API-docs for the return type is: BaseApiResponseAccount instead of BaseApiResponse.

Expected behavior We should expect similar behaviour as in Springfox (http://springfox.github.io/springfox/docs/snapshot/#changing-how-generic-types-are-named), where Swagger UI should either display BaseApiResponse or BaseApiResponseOfAccount

tonjack avatar Apr 16 '20 17:04 tonjack

@tonjack,

This is not an issue on springxdoc-openapi. We only rely on standard OpenAPI 3 and official swagger jars. The generated OpenAPI description is Valid.

The behaviour you are expecting, is not supported natively, by the API. There is already an Open issue on swagger-core that you can follow, similar to the behaviour you are expecting:

  • https://github.com/swagger-api/swagger-core/issues/3323

bnasslahsen avatar Apr 16 '20 18:04 bnasslahsen