隐藏示例值中的字段,但不在 Swagger UI 中的请求正文模型中 [英] Hiding fields in Example Value but not in Model of Request Body in Swagger UI

查看:37
本文介绍了隐藏示例值中的字段,但不在 Swagger UI 中的请求正文模型中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试在 Body 部分的 Swagger UI 上实现一个场景.在请求部分,我们是否可以使用示例值 JSON 隐藏一个或多个字段,但模型仍会显示这些字段?

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.

例如,我们想隐藏示例中的 name :

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

但仍然在此处显示模型中的name:

but still display the name in the Model here:

推荐答案

要在 Swagger UI 中从自动生成的模型示例中隐藏字段,您需要为该模型添加自定义 example仅包含您需要的字段.

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

这篇关于隐藏示例值中的字段,但不在 Swagger UI 中的请求正文模型中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆