c# - 如何在 asp.net core 的字段中添加 swagger 示例?

标签 c# asp.net-core swagger asp.net-core-webapi

基于 the Swagger documentation我必须能够为我的类字段添加一些示例,例如:

enter image description here

但是我找不到任何方法将这些示例添加到我的类中。

最佳答案

您可以启用 XML Comments然后使用 <example>元素来定义一个例子。这是使用 <example> 的示例:

public class CompanyValidationResponse
{
    /// <example>1234</example>
    public int CompanyId { get; set; }

    /// <example>Damage, Inc</example>
    public string CompanyName { get; set; }
}

关于c# - 如何在 asp.net core 的字段中添加 swagger 示例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70002577/

相关文章:

json - 使用 swagger 发布 json 正文

ViewSet 操作中的 Django REST Framework 架构参数列表

c# - 从 xml 数据源读取 url

c# - 无法连接到 Docker 中托管的网络核心 gRPC 服务

c# - 使用授权 header (Bearer) 设置 Swagger (ASP.NET Core)

c# - 如何从 NuGet 包获取的 RCL 导入 Razor 页面?

c# - 如何将不记名授权 header 附加到 swagger 请求。虚张声势 v 5.0.0-rc2

c# - 从 XAML 引用嵌套枚举类型

c# - 如何使用 PLINQ 执行 IO 密集型任务?

c# - 返回文件结果时出现 HTTP ERROR 500