Ask a Question

How to define response type of a templated object

ktalebian
Occasional Visitor

How to define response type of a templated object

Let's say I have a `Pagination<T>` type to be used for my list endpoints. Now let's say I have `/Users` and this should return `Pagination<User>`. How do I define the response? Doing this is only partially:

 

responses:
200:
description: OK
content:
application/json; charset=utf-8:
schema:
$ref: '#/components/schemas/Pagination'

This has no idea what the type of pagination is. I'm using Swagger annotations to generate this, and so I'd like to keep the solution working with annotation. I know I can probably create a custom component, something like

UserList:
type: object
properties:
result:
type: array
items:
$ref: '#/components/schemas/User'
meta:
$ref: '#/components/schemas/PagingMetadata'

And then update the above to reference this object, but I manually made this myself inside the .yaml file and I'd like to keep the solution working with annotations.

1 REPLY 1
hugomario
Staff

Hello @ktalebian, generics is not a feature in code generation yet. But sounds as a good propose. Feel free to add that propose here: https://github.com/swagger-api/swagger-codegen-generators, and ping as @HugoMario , will like to work on it.

cancel
Showing results for 
Search instead for 
Did you mean: