Skip to content

Commit 5f928c0

Browse files
authored
[Functions] VS OpenAPI tutorial portal-side updates
1 parent 1003c53 commit 5f928c0

File tree

1 file changed

+74
-15
lines changed

1 file changed

+74
-15
lines changed

articles/azure-functions/openapi-apim-integrate-visual-studio.md

Lines changed: 74 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,100 @@ ms.date: 01/18/2023
77

88
# Create serverless APIs in Visual Studio using Azure Functions and API Management integration
99

10-
REST APIs are often described using an OpenAPI definition. This file contains information about operations in an API and how the request and response data for the API should be structured.
10+
REST APIs are often described using an OpenAPI definition (formerly known as Swagger) file. This file contains information about operations in an API and how the request and response data for the API should be structured.
1111

1212
In this tutorial, you learn how to:
1313

1414
> [!div class="checklist"]
15-
> * Create a serverless function project in Visual Studio
15+
> * Create the code project in Visual Studio
16+
> * Install the OpenAPI extension
17+
> * Add an HTTP trigger endpoint, which includes OpenAPI definitions
1618
> * Test function APIs locally using built-in OpenAPI functionality
1719
> * Publish project to a function app in Azure with API Management integration
18-
> * Get the access key for the function and set it in API Management
20+
> * Get the access key for the function app and set it in API Management
1921
> * Download the OpenAPI definition file
2022
2123
The serverless function you create provides an API that lets you determine whether an emergency repair on a wind turbine is cost-effective. Because both the function app and API Management instance you create use consumption plans, your cost for completing this tutorial is minimal.
2224

23-
> [!NOTE]
24-
> The OpenAPI and API Management integration featured in this article is currently only supported for [in-process](functions-dotnet-class-library.md) C# class library functions. [Isolated worker process](dotnet-isolated-process-guide.md) C# class library functions and all other language runtimes should instead [use Azure API Management integration from the portal](functions-openapi-definition.md).
25-
2625
## Prerequisites
2726

2827
+ [Visual Studio 2022](https://azure.microsoft.com/downloads/). Make sure you select the **Azure development** workload during installation.
2928

3029
+ An active [Azure subscription](../guides/developer/azure-developer-guide.md#understanding-accounts-subscriptions-and-billing), create a [free account](https://azure.microsoft.com/free/dotnet/) before you begin.
3130

32-
## Create a Functions project
31+
## Create the code project
3332

34-
The Azure Functions project template in Visual Studio creates a project that you can publish to a function app in Azure. You'll also create an HTTP triggered function supports OpenAPI definition file (formerly Swagger file) generation.
33+
The Azure Functions project template in Visual Studio creates a project that you can publish to a function app in Azure. You'll also create an HTTP triggered function from a template that supports OpenAPI definition file (formerly Swagger file) generation.
3534

3635
1. From the Visual Studio menu, select **File** > **New** > **Project**.
3736

3837
1. In **Create a new project**, enter *functions* in the search box, choose the **Azure Functions** template, and then select **Next**.
3938

4039
1. In **Configure your new project**, enter a **Project name** for your project like `TurbineRepair`, and then select **Create**.
4140

42-
1. For the **Create a new Azure Functions application** settings, use the values in the following table:
41+
1. For the **Create a new Azure Functions application** settings, select one of these options for **Functions worker**, where the option you choose depends on your chosen process model:
42+
43+
### [Isolated worker model](#tab/isolated-process)
44+
45+
**.NET 8.0 Isolated (Long Term Support)**: Your C# functions run in the isolated worker model, which is recommended. For more information, see the [isolated worker model guide](dotnet-isolated-process-guide.md).
46+
47+
### [In-process](#tab/in-process)
48+
49+
[!INCLUDE [functions-in-process-model-retirement-note](../../includes/functions-in-process-model-retirement-note.md)]
50+
51+
**.NET 8.0 (Long Term Support)**: Your C# functions run in the [in-process model](functions-dotnet-class-library.md), which will be retired. To learn more, see the [in-process model guide](functions-dotnet-class-library.md).
52+
53+
---
54+
55+
1. For the rest of the options, use the values in the following table:
4356

4457
| Setting | Value | Description |
4558
| ------------ | ------- |----------------------------------------- |
46-
| **Functions worker** | **.NET 6** | This value creates a function project that runs in-process on version 4.x of the Azure Functions runtime, which is required for OpenAPI file generation. |
47-
| **Function template** | **HTTP trigger with OpenAPI** | This value creates a function triggered by an HTTP request, with the ability to generate an OpenAPI definition file. |
59+
| **Function template** | **Empty** | This creates a project without a trigger, which gives you more control over the name of the HTTP triggered function when you add it later. |
4860
| **Use Azurite for runtime storage account (AzureWebJobsStorage)** | **Selected** | You can use the emulator for local development of HTTP trigger functions. Because a function app in Azure requires a storage account, one is assigned or created when you publish your project to Azure. |
4961
| **Authorization level** | **Function** | When running in Azure, clients must provide a key when accessing the endpoint. For more information, see [Authorization level](functions-bindings-http-webhook-trigger.md#http-auth). |
62+
63+
1. Select **Create** to create the function project.
64+
65+
Next, you update the project by installing the OpenAPI extension for Azure Functions, which enables the discoverabilty of API endpoints in your app.
66+
67+
## Install the OpenAPI extension
68+
69+
To install the OpenAPI extension:
70+
71+
1. From the **Tools** menu, select **NuGet Package Manager** > **Package Manager Console**.
72+
73+
1. In the console, run the following [Install-Package](/nuget/tools/ps-ref-install-package) command to install the OpenAPI extension:
74+
75+
# [Isolated worker model](#tab/isolated-process)
5076

51-
![Azure Functions project settings](./media/openapi-apim-integrate-vs/functions-project-settings.png)
77+
```command
78+
NuGet\Install-Package Microsoft.Azure.Functions.Worker.Extensions.OpenApi -Version 1.5.1
79+
```
80+
You might need to updated the [specific version](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.OpenApi), based on your version of .NET.
81+
82+
# [In-process model](#tab/in-process)
83+
84+
```command
85+
NuGet\Install-Package Microsoft.Azure.WebJobs.Extensions.OpenApi -Version 1.5.1
86+
```
87+
You might need to updated the [specific version](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.OpenApi), based on your version of .NET.
88+
89+
---
90+
91+
Next, you can add create your HTTP endpoint function.
92+
93+
## Add an HTTP endpoint function
94+
95+
In a C# class library, the bindings used by the function are defined by applying attributes in the code. To create a function with an HTTP trigger:
5296

53-
1. Select **Create** to create the function project and HTTP trigger function, with support for OpenAPI.
97+
1. In **Solution Explorer**, right-click your project node and select **Add** > **New Azure Function**.
5498

55-
Visual Studio creates a project and class named `Function1` that contains boilerplate code for the HTTP trigger function type. Next, you replace this function template code with your own customized code.
99+
1. Enter **Turbine.cs** for the class, and then select **Add**.
100+
101+
1. Choose the **Http trigger** template, set **Authorization level** to **Function**, and then select **Add**. A Turbine.cs code file is added to your project that defines a new function endpoint with an HTTP trigger.
102+
103+
Now you can replace the HTTP trigger template code with code that implements the Turbine function endpoint, along with attributes that use OpenAPI to define endpoint.
56104

57105
## Update the function code
58106

@@ -65,10 +113,21 @@ The function uses an HTTP trigger that takes two parameters:
65113

66114
The function then calculates how much a repair costs, and how much revenue the turbine could make in a 24-hour period. Parameters are supplied either in the query string or in the payload of a POST request.
67115

68-
In the Function1.cs project file, replace the contents of the generated class library code with the following code:
116+
In the Turbine.cs project file, replace the contents of the class generated from the HTTP trigger template with the following code, which depends on your process model:
117+
118+
# [Isolated worker model](#tab/isolated-process)
119+
120+
```command
121+
NuGet\Install-Package Microsoft.Azure.Functions.Worker.Extensions.OpenApi -Version 1.5.1
122+
```
123+
You might need to updated the [specific version](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.OpenApi), based on your version of .NET.
124+
125+
# [In-process model](#tab/in-process)
69126

70127
:::code language="csharp" source="~/functions-openapi-turbine-repair/TurbineRepair/Function1.cs":::
71128

129+
---
130+
72131
This function code returns a message of `Yes` or `No` to indicate whether an emergency repair is cost-effective. It also returns the revenue opportunity that the turbine represents and the cost to fix the turbine.
73132

74133
## Run and verify the API locally

0 commit comments

Comments
 (0)