简体   繁体   English

如何在 azure 函数(2.0)的 swagger UI 中默认显示帖子正文示例

[英]How to display post body example by default in swagger UI from azure functions(2.0)

I'm new to swagger open API documentation.我是 swagger 打开 API 文档的新手。 Integrating the Aliencube.AzureFunctions.Extensions.OpenApi.Core in azure function app 2.0 .azure function 应用程序 2.0中集成Aliencube.AzureFunctions.Extensions.OpenApi.Core

Here is the code:这是代码:

    [FunctionName("TestFunction")]
    [OpenApiOperation(operationId: "TestFunction", tags: new[] { "TestFunction" })]
    [OpenApiRequestBody("text/plain", typeof(string))]
    public static async Task<IActionResult> TestFunctionRun([HttpTrigger(AuthorizationLevel.Anonymous,"post", Route = null)] HttpRequest TestFunctionRequest, ExecutionContext executionContext)
    {
        {
           //definition of function
        }
    }

In Swagger it is displaying as below在Swagger中显示如下

在此处输入图像描述

we are expected to display below example value by default我们应该默认显示下面的示例值

{
  "username" : "testuser",
  "userid" : "1"
}

If the above Expected example value is displayed by default by using AzureFunctions.Extensions.Swashbuckle in azurefunction 2.0.如果使用azurefunction 2.0 中的 AzureFunctions.Extensions.Swashbuckle 默认显示上述 Expected 示例值。 It is also help full for us.这对我们也很有帮助。

Please help me out from this problem as we are running out of time.请帮我解决这个问题,因为我们时间不多了。
Thanks in advance!提前致谢!

You should use, Pet is a model.你应该使用, Pet是一个 model。

[OpenApiRequestBody(contentType: "application/json", bodyType: typeof(Pet), Required = true, Description = "Pet object that needs to be added to the store")]

在此处输入图像描述

Reproduce your problem:重现您的问题:

在此处输入图像描述

在此处输入图像描述

Solution:解决方案:

在此处输入图像描述

在此处输入图像描述

Reference参考

  1. Source codeAzureFunctions.Extensions源码AzureFunctions.Extensions

  2. Blog : Introducing Swagger UI on Azure Functions博客在 Azure 功能上介绍 Swagger UI

  3. set startup project.设置启动项目。

    在此处输入图像描述

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

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