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.
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):
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}
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With