简体   繁体   English

Swashbuckle - 如何在 Schema 部分中包含参数类型

[英]Swashbuckle - How to include parameter types in the Schema section

I have an Azure Function App using Swashbuckle.我有一个使用 Swashbuckle 的 Azure Function 应用程序。

[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)
{

The return type as defined by ProducesResponseType attribute is included in the schema section. ProducesResponseType 属性定义的返回类型包含在架构部分中。 The parameter as defined by QueryStringParameter attribute is not included in the schema section.由 QueryStringParameter 属性定义的参数不包含在架构部分中。

How do I make the parameter appear in the schema section so my consumers can know what kind of parameter to pass?如何使参数出现在架构部分中,以便我的消费者知道要传递什么样的参数?

I ended up creating dummy method using ProducesResponseType for the type contained in the QueryStringParameter.我最终使用 ProducesResponseType 为 QueryStringParameter 中包含的类型创建了虚拟方法。 Now I have two extra methods to do nothing.现在我有两个额外的方法什么都不做。 Seems kind of hacky, but the type now appears in the schema section of Swagger page.似乎有点 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)
{

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM