问题描述
我是 swagger 开放 API 文档的新手。在 azure 函数应用 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 默认显示上述预期示例值。这对我们来说也很有帮助。
请帮我解决这个问题,因为我们的时间不多了。
提前致谢!
解决方法
你应该使用,Pet
是一个模型。
[OpenApiRequestBody(contentType: "application/json",bodyType: typeof(Pet),Required = true,Description = "Pet object that needs to be added to the store")]