San M
San M

Reputation: 31

Hiding fields in Example Value but not in Model of Request Body in Swagger UI

We are trying to achieve a scenario on the Swagger UI in the Body section. In the Requests section, can we have an Example Value JSON hiding one or more fields but the Model would still show those fields?

We are basically trying to reduce the number of fields in the request body but have all the fields visible in the Model.

For example, we would like to hide the name in the example here:

Swagger UI - Example Value

but still display the name in the Model here:

Swagger UI - Model

Upvotes: 3

Views: 4284

Answers (1)

Helen
Helen

Reputation: 97677

To hide fields from auto-generated model examples in Swagger UI, you'll need to add a custom example for that model that includes only the fields you need.

definitions:
  Pet:
    type: object
    properties:
      ...

    # Override model example that will be displayed in Swagger UI
    example:
      id: foo
      status: available

Upvotes: 2

Related Questions