Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have two different Swagger Model with same name?

I am writing swagger documentation(swagger.json) for my project(which is done and alive). Now i have a problem with modelling my object. I have a object called "Listing", Which is used to handle both "applications" and "services" internally.

Now in my definition i want to have two objects, one with applications related fields and one with service related fields . But i want to keep the name listing to both the objects,because in the swagger-ui i want the both of the objects to be displayed as listing(since the APIs are already used by users)

Any help?

Thanks.

like image 358
Jeevi Avatar asked Sep 18 '25 21:09

Jeevi


2 Answers

Schema names must be unique, such as ApplicationListing and ServiceListing. But you can set the schema title to customize the schema name displayed in Swagger UI.

definitions:
  ApplicationListing:
    title: Listing
    description: Application listing
    type: object
    ...

  ServiceListing:
    title: Listing
    description: Service listing
    type: object
    ...
like image 160
Helen Avatar answered Sep 21 '25 08:09

Helen


With out adding unique named classes, you can do this by customizing schema name for swagger documentation.

@Schema(name = "ApplicationListing")

and

@Schema(name = "ServiceListing")

like image 40
lakshitha Avatar answered Sep 21 '25 08:09

lakshitha