How to add Open API support for Azure Functions
This post is about documenting Azure Functions using Open API. Similar to ASP.NET Core, Open API support for Azure Functions is also simple and straight forward.
I am using the QR Generator Azure Function and I am enabling Open API support for that. To enable Open API support first you need to add the Open API package for Azure Functions. You can do this by running the command -
dotnet add package Microsoft.Azure.WebJobs.Extensions.OpenApi --version 0.1.0-preview
When you add this package and if run the function, you will be able to see the function is displaying 3 more URLs other than the function HTTP endpoint.
But if you try to access it, it will return internal server error. It is because you are missing the Open API configuration. You can fix this by adding the following JSON values in the
Now if you run and browse the Swagger UI endpoint you will be able to see a Open API screen like the following.
But it is showing
No operations defined in spec!, in case of ASP.NET Core, we don’t need to do it, but in Function you need to explicitly configure the Open API operations and associated request and responses. Here is an example.
Now if you run the app again you will be able to find something like this.
Now you can test and verify this function with the Open API UI, if you provide the URL it will generate the QR code image and will display it in the UI. Now you’re able to import the Open API file into API Management and it can work with Azure Functions.
Happy Programming :)