cancel
Showing results for 
Search instead for 
Did you mean: 

Swagger json format that works for codegen and redoc

Highlighted
New Contributor

Swagger json format that works for codegen and redoc

I want swagger-codegen to generate a function Foo with two parameters of the same type. For example Foo(User first, User second).

For this to work, both "first" and "second" have the same $ref pointing to User.

 

However, in this case I can not have the redoc use two distinct description fields and I get that both "first" and "second" has the same description - the one pointed to by $ref.

What can I do to have something that generated code with the same classes as in the example of Foo but also allows for two different descriptions to be used ? 

3 REPLIES 3
Highlighted
Moderator

Re: Swagger json format that works for codegen and redoc

To add description to a $ref, you can wrap the $ref into allOf:

first:
  description: The first user
  allOf:
    - $ref: '#/definitions/User'

Helen Kosova
SmartBear Documentation Team Lead
________________________
Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
Highlighted
New Contributor

Re: Swagger json format that works for codegen and redoc

Thank you.

The description does work, however now the redoc does not recognize that the type of the first user is User and it is shown as type "object". 

The swagger-codegen generates a Request class with no users as oppesed to the attempt in the post 

Highlighted
Moderator

Re: Swagger json format that works for codegen and redoc

It's a tooling bug then. You can submit bug reports in the GitHub repositores of those projects:


Swagger Codegen: https://github.com/swagger-api/swagger-codegen/issues
ReDoc: https://github.com/Redocly/redoc/issues


Helen Kosova
SmartBear Documentation Team Lead
________________________
Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors