首页 > 解决方案 > 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 属性定义的参数不包含在架构部分中。

如何使参数出现在架构部分中,以便我的消费者知道要传递什么样的参数?

标签: swaggerswagger-uiswagger-2.0swashbuckle

解决方案


我最终使用 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)
{

推荐阅读