DEV Community

Cover image for Generating OpenAPI Document from Azure Functions within CI/CD Pipeline
Justin Yoo for Microsoft Azure

Posted on • Updated on • Originally published at devkimchi.com

Generating OpenAPI Document from Azure Functions within CI/CD Pipeline

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.

GitHub logo 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

Out-of-Proc Worker In-Proc Worker

Acknowledgement

Getting Started

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)