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 buil…


This content originally appeared on DEV Community and was authored by DEV Community

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.

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.


This content originally appeared on DEV Community and was authored by DEV Community


Print Share Comment Cite Upload Translate Updates
APA

DEV Community | Sciencx (2022-02-23T00:00:27+00:00) Generating OpenAPI Document from Azure Functions within CI/CD Pipeline. Retrieved from https://www.scien.cx/2022/02/23/generating-openapi-document-from-azure-functions-within-ci-cd-pipeline/

MLA
" » Generating OpenAPI Document from Azure Functions within CI/CD Pipeline." DEV Community | Sciencx - Wednesday February 23, 2022, https://www.scien.cx/2022/02/23/generating-openapi-document-from-azure-functions-within-ci-cd-pipeline/
HARVARD
DEV Community | Sciencx Wednesday February 23, 2022 » Generating OpenAPI Document from Azure Functions within CI/CD Pipeline., viewed ,<https://www.scien.cx/2022/02/23/generating-openapi-document-from-azure-functions-within-ci-cd-pipeline/>
VANCOUVER
DEV Community | Sciencx - » Generating OpenAPI Document from Azure Functions within CI/CD Pipeline. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/02/23/generating-openapi-document-from-azure-functions-within-ci-cd-pipeline/
CHICAGO
" » Generating OpenAPI Document from Azure Functions within CI/CD Pipeline." DEV Community | Sciencx - Accessed . https://www.scien.cx/2022/02/23/generating-openapi-document-from-azure-functions-within-ci-cd-pipeline/
IEEE
" » Generating OpenAPI Document from Azure Functions within CI/CD Pipeline." DEV Community | Sciencx [Online]. Available: https://www.scien.cx/2022/02/23/generating-openapi-document-from-azure-functions-within-ci-cd-pipeline/. [Accessed: ]
rf:citation
» Generating OpenAPI Document from Azure Functions within CI/CD Pipeline | DEV Community | Sciencx | https://www.scien.cx/2022/02/23/generating-openapi-document-from-azure-functions-within-ci-cd-pipeline/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.