Sunil Kumar
Sunil Kumar

Reputation: 5647

How will Swagger 2.0 handle generics in parameters or return types?

I am using Swagger 2.0 for documentation generation. In my controller class, I have some operations like:

public Page<Employee> getEmployees(Pageable pageable) {....}

Swagger document generated for response of the operation above:

"responses" : {
          "200" : {
            "schema" : {
              "$ref" : "#/definitions/Page"
              } 
            }
          }

Here, Swagger documentation failed to say that response is Page<Employee>. How do I get generics data in documentation in Swagger?

And what if I have the following return types?

Page<String,Employee>
Page<Employee,List<Department>>
Page<Employee,Tuple.Two<String,User>>

Same is true for Swagger Operation parameters and Model properties.

Upvotes: 7

Views: 6620

Answers (1)

Ashwin Krishnamurthy
Ashwin Krishnamurthy

Reputation: 3758

This is a known issue with Swagger, please check the following issue: https://github.com/OAI/OpenAPI-Specification/issues/957. Point being, you'll need to create your own extensions to describe generics.

Upvotes: 1

Related Questions