Web Api Swagger 参数示例
将 ASP.NET 5 Web API 与 MVC 版本化 API 资源管理器结合使用,是否有一种方法可以自动生成参数示例,如 Swagger 文档中所述: https://swagger.io/docs/specation/adding-examples/
我目前正在使用 XML 注释,但我没有找到提供的例子 范围。 <备注> XML 注释不适用于参数,仅适用于操作。
我想做的是为以下模型自动生成示例
public record GetSpecsCommand {
/// <summary>filter results by already selected specs</summary>
/// <remarks>
/// {
/// "selectedspecs.year": "2020"
/// }
/// </remarks>
public IDictionary<string, string> SelectedSpecs { get; set; }
}
Using ASP.NET 5 Web API with MVC Versioned API Explorer, is there a way to auto generate the example for a parameter like described in the Swagger docs: https://swagger.io/docs/specification/adding-examples/
I'm currently using XML Comments, but I don't see a way to provide the example for a parameter. The <remarks> XML Comment doesn't apply to parameters and only to the operation.
What I'd like to do is have the example auto-generated for the following model
public record GetSpecsCommand {
/// <summary>filter results by already selected specs</summary>
/// <remarks>
/// {
/// "selectedspecs.year": "2020"
/// }
/// </remarks>
public IDictionary<string, string> SelectedSpecs { get; set; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发布这个之后,我搜索了github代码,发现它支持; XML 注释。更改<备注>后<示例>我的示例神奇地添加到生成的 swagger 文档中。
After I posted this, I searched through the github code and found that it supports the <example> XML comment. After changing <remarks> to <example> my example was magically added to the generated swagger doc.