From time to time, you might be facing some situations while using the Azure Functions OpenAPI extension for your Azure Functions development. One of them is that you are asked to generate the OpenAPI document from the function app right after the build and integrate it with Power Platform or Azure API Management. What if you want to do this process within your CI/CD pipeline?
Throughout this post, I'm going to discuss how to generate the OpenAPI document within the GitHub Actions workflow right after the function app build.
NOTE: Let's use the sample app provided by the Azure Functions OpenAPI Extension repository.
Azure / azure-functions-openapi-extension
This extension provides an Azure Functions app with Open API capability for better discoverability to consuming parties
Azure Functions OpenAPI Extension
Acknowledgement
- Swagger UI version used for this library is v3.44.0 under the Apache 2.0 license.
- This extension supports the OpenAPI spec version of v2.0 and v3.0.1.
Getting Started
- Enable OpenAPI documents to your Azure Functions HTTP Trigger: This document shows how to enable OpenAPI extension on your Azure Functions applications and render Swagger UI, and OpenAPI v2 and v3 documents on-the-fly.
- Securing Azure Functions Endpoints through OpenAPI Auth: This document shows many various scenarios to add authN features including the built-in features and OAuth2 auth flows.
Azure Functions v1 Support: This document shows how to support Azure Functions v1 runtime with this OpenAPI extension.- Integrating OpenAPI-enabled Azure Functions to Azure API Management: This document shows how to integrate the Azure Functions application with Azure API Management, via this OpenAPI extension.
First of all, you need to install the Azure Functions Core Tools within your GitHub Actions workflow. Installing the tool varies depending on the runner OS. The command you're going to run the function app is like this:
If it's the terminal environment on your local machine, just open one terminal session and run the function app. After that, you can open another terminal session for additional command-line jobs. That's not a problem at all. However, it's a totally different story when it's about the CI/CD pipeline because you can't open multiple terminal sessions there. Therefore, you have to run the function app as a background process.
Bash Shell Background Process
Bash shell offers &
to run your app as the background process, like func start &
(line #2). Therefore, you can run the shell commands to get the OpenAPI document like:
How simple is that?
PowerShell Background Process
If you prefer PowerShell, use the Start-Process
cmdlet with the -NoNewWindow
switch to run the function app as the background process (line #2). For example, here are the commands on non-Windows runner:
On the other hand, the Start-Process
cmdlet doesn't understand the command, func
on the Windows runner. Therefore, you need a pre-process the func
command (line #2, 5).
Now, you can get the OpenAPI document in PowerShell.
GitHub Actions Workflow
Now, we can get the OpenAPI document from the function app running as a background process. It means that you can get the document within the CI/CD pipeline. Here's the example in the GitHub Actions workflow. It only shows the function app build and OpenAPI document generation (line #26-33) for brevity.
So far, we've walked through how to generate the OpenAPI document from the function app running as a background process within the CI/CD pipeline. The generated document can be stored somewhere as an artifact and integrated with other services like Power Platform or Azure API Management.
Top comments (0)