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

久未见 提交于 2019-12-11 00:57:07

问题


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:

but still display the name in the Model here:


回答1:


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


来源:https://stackoverflow.com/questions/50647157/hiding-fields-in-example-value-but-not-in-model-of-request-body-in-swagger-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!