Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I represent java Generic type in swagger.yml #957

Closed
howshit opened this issue Mar 2, 2017 · 5 comments
Closed

How can I represent java Generic type in swagger.yml #957

howshit opened this issue Mar 2, 2017 · 5 comments
Milestone

Comments

@howshit
Copy link

howshit commented Mar 2, 2017

Hi, I have multiple APIs returning data with same structure, just like examples underneath:

  CatResponse:
    type: object
    properties:
      counts:
        type: integer
      value:
        type: array
        items:
          $ref: '#/definitions/Cat'  
  DogResponse:
    type: object
    properties:
      counts:
        type: integer
      value:
        type: array
        items:
          $ref: '#/definitions/Dog' 

How can I represent them in swagger so that I can generate EntityResponse<T>, when I refer to them, I just replace T with Cat or Dog.

So that I just need to define one response object.

Thx.

@webron
Copy link
Member

webron commented Mar 2, 2017

There's no support for templating of responses (or message wrappers).

@howshit
Copy link
Author

howshit commented Mar 2, 2017

You mean that no definition can generate Java generic type like EntityResponse<T>,
and thus I have to define ten response objects if I have ten kinds of animal entities.

@webron
Copy link
Member

webron commented Mar 2, 2017

How it translates to code in a specific language is out of scope. You can use composition and inheritance, but not templating.

@macarlet
Copy link

macarlet commented Jun 6, 2018

Maybe this thread can be useful? Take a look at the last message
swagger-api/swagger-core#498

@handrews
Copy link
Member

Generics/templates are supported in OAS 3.1 by using dynamic references.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants