Ask a Question

Swagger json format that works for codegen and redoc

belgi
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
HKosova
SmartBear Alumni (Retired)

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
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
belgi
New Contributor

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 

HKosova
SmartBear Alumni (Retired)

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
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
cancel
Showing results for 
Search instead for 
Did you mean: