OpenAPI (aka Swagger) in Azure Functions V2

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


UPDATE (2021-06-04)

Microsoft recently announced the OpenAPI support on Azure Functions during the //Build event.

The Aliencube extension has now been archived and no longer supported. Please use this official extension.

As of today, it's in preview. Although it's in preview, it has more features than the Aliencube one.

Acknowledgement 2: I am still maintaining the official one.


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

Nuget > Aliencube.AzureFunctions.Extensions.OpenApi

And here’s the blog post for it:

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 1: I am the owner of the NuGet package.


For anyone looking into this, Microsoft still hasn't added Open API support for Azure Functions +v2 and there hasn't been any major movement toward it.

I faced this same issue recently and I found a pretty good solution. If you aren't aware yet, check this out: https://github.com/RicoSuter/NSwag

NSwag is a toolchain that integrates with .NET to produce the Open API documentation and UI, but also generates the respective API clients for you. I've used this tool for the past 2 years when working with Angular and .NET apps, it saves a lot of time and seamlessly integrates with my whole development workflow.

For Azure Functions +v2, a contributor created a generator that in less than 10 lines of code, allow us to expose the Swagger endpoint for an Azure Function class: https://github.com/Jusas/NSwag.AzureFunctionsV2

Now, if you design HTTP-Triggered Functions using DI, grouping related operations under the same class and leveraging model binding, you might not even need to apply any custom decorator, it just works! Here's an example of how one real API would look like: API + Swagger example

(ignore the base class. It is part of a personal pattern I follow, unrelated to Swagger)

And this is how it looks like using a swagger UI: Swagger UI example


There is official library Azure Functions OpenAPI Extension. It is still in preview, but looks great.