【发布时间】:2021-09-02 23:17:55
【问题描述】:
我是大摇大摆的开放 API 文档的新手。在 azure function app 2.0 中集成 Aliencube.AzureFunctions.Extensions.OpenApi.Core。
代码如下:
[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
}
}
在 Swagger 中显示如下
默认情况下,我们应该在示例值下方显示
{
"username" : "testuser",
"userid" : "1"
}
如果在 azurefunction 2.0 中使用 AzureFunctions.Extensions.Swashbuckle 默认显示上述预期示例值。这对我们也很有帮助。
请帮我解决这个问题,因为我们的时间不多了。
提前致谢!
【问题讨论】:
-
如何将属性更改为
[OpenApiRequestBody("application/json", typeof(User))]。确保在typeof中添加正确的类。 -
我的回答对你有用吗?
标签: c# azure-functions asp.net-core-2.0 swagger-ui swagger-2.0