OpenAPI (aka Swagger) in Azure Functions V2

余生长醉 提交于 2020-05-14 16:38:06

问题


I'm creating a V2 Function App and want to use Swagger/Open API for docs, however it is not yet supported in the Azure Portal for V2 Functions.

Any suggestions on how I can use Swagger with V2 Functions in VSTS to create the docs on each build?


回答1:


TL;DR - use the NuGet package to render Open API document and Swagger UI through Azure Functions.

—-

Microsoft hasn’t officially started supporting Open API (or Swagger) yet. But there is a community-driven NuGet package currently available:

https://www.nuget.org/packages/Aliencube.AzureFunctions.Extensions.OpenApi/

And here’s the blog post for it:

https://devkimchi.com/2019/02/02/introducing-swagger-ui-on-azure-functions/

Basically its usage is similar to Swashbuckle — using decorators. And it supports both Azure Functions V1 and V2.

Acknowledgement: I am the owner of the NuGet package.




回答2:


Medium actually has a great tutorial on how to accomplish this: https://medium.com/@yuka1984/open-api-swagger-and-swagger-ui-on-azure-functions-v2-c-a4a460b34b55

It uses the Swashbuckle AzureFunctions Extension: https://www.nuget.org/packages/AzureFunctions.Extensions.Swashbuckle/

I've tested/implemented successfully - definitely one of the best ways out there on how to do this.




回答3:


Can you drop your V2 Function to run on v1 of the runtime by starting over with a blank function app first?

The MSDN documents for Create an OpenAPI definition for a function (with a date of 11/2018 interestingly enough) example states:

By default, the function app you create uses version 2.x of the runtime. You must set the runtime version back to 1.x before you create your function.

But one can't just move the setting to 1:

To pin your function app to the version 1.x runtime, choose ~1 under Runtime version. This switch is disabled when you have functions in your app.

Which implies one must create the Function app, publish/create it, set it to V1 and then put in a function before adding a function app.




回答4:


You can check out the framework Function Monkey Function Monkey homepage

It has a lot of features, including swagger/ OpenAPI definitions. Function Monkey Swagger




回答5:


In the portal, if you go to the Function App > Platform Features > API Definition and click the "Function (preview)" button under "API Defintion Source" you can experiment with writing the Swagger there.



来源:https://stackoverflow.com/questions/52500329/openapi-aka-swagger-in-azure-functions-v2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!