swagger - Swashbuckle - 如何在 Schema 部分中包含参数类型
问题描述
我有一个使用 Swashbuckle 的 Azure Function App。
[FunctionName("DoWorkV2")]
[QueryStringParameter("DoWorkParameters", "", DataType = typeof(DoWorkParametersV2), Required = true)]
[ProducesResponseType(typeof(DoWorkResults), (int)HttpStatusCode.OK)]
public static async Task<IActionResult> DoWorkV2(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log, ExecutionContext context)
{
ProducesResponseType 属性定义的返回类型包含在架构部分中。由 QueryStringParameter 属性定义的参数不包含在架构部分中。
如何使参数出现在架构部分中,以便我的消费者知道要传递什么样的参数?
解决方案
我最终使用 ProducesResponseType 为 QueryStringParameter 中包含的类型创建了虚拟方法。现在我有两个额外的方法什么都不做。似乎有点 hacky,但该类型现在出现在 Swagger 页面的架构部分。
[FunctionName("DoWorkParametersV2Factory")]
[ProducesResponseType(typeof(DoWorkParametersV2), (int)HttpStatusCode.OK)]
public static async Task<IActionResult> DoWorkParametersV2Factory(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log, ExecutionContext context)
{
推荐阅读
- javascript - 通过在 JavaScript 中将两个变量名附加在一起来定义变量
- excel - For Each 循环每第 N 行并包括最后一行
- sql - Oracle SQL - 如何计算两个日期之间的工作时间和分钟
- python - 如何在 matplotlib FuncAnimation 中有效地叠加散点图?
- android - 如何让我的 ionic 应用程序以 API 级别 28 及以上为目标
- python - 安装 Requirements.txt 导致无效的语法错误 Python 3.7
- tsql - 仅当它们彼此相隔一周内时才对行求和
- visual-studio - 新dot net core 3.0预览控制台项目-堆栈溢出错误:VS 2019 16.2.0
- c++ - 在 CentOs 7 上安装 gcc 7.4.0 不会更新我的 libstdc++ 版本
- c++ - 如何正确将 GRC 块“随机源”的字节输出数据读入 C++ 中自己的 OOT 块?