Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 642
Sunil Kumar Avatar asked Jun 04 '15 06:06

Sunil Kumar


People also ask

How do you pass multiple parameters in Swagger?

If you are trying to send a body with multiple parameters, add an object model in the definitions section and refer it in your body parameter, see below (works with editor.swagger.io):

What are parameters in Swagger?

Path Parameters. Path parameters are variable parts of a URL path. They are typically used to point to a specific resource within a collection, such as a user identified by ID. A URL can have several path parameters, each denoted with curly braces { } . GET /users/{id}

How do you specify optional parameters in Swagger?

You can use the default key to specify the default value for an optional parameter. The default value is the one that the server uses if the client does not supply the parameter value in the request. The value type must be the same as the parameter's data type.

What are the formats supported by OpenAPI Swagger for their definitions?

Format. An OpenAPI document that conforms to the OpenAPI Specification is itself a JSON object, which may be represented either in JSON or YAML format.


1 Answers

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.

like image 185
Ashwin Krishnamurthy Avatar answered Sep 17 '22 09:09

Ashwin Krishnamurthy