How to enable OpenAPI v3 in in Azure Function isolated model with .net8.0

Li Shen 0 Reputation points Microsoft Employee
2024-11-25T09:23:45.85+00:00

Cannot use Microsoft.Azure.WebJobs.Extensions.OpenApi as dependency in Azure Function isolated model due to package prefix requirement according to https://learn.microsoft.com/en-us/azure/azure-functions/migrate-dotnet-to-isolated-model?tabs=net8#migrate-your-local-project.

Due to some security reason, we are required to use OpenAPI v3 in our Function app. How can we achieve this?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,398 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Pinaki Ghatak 5,575 Reputation points Microsoft Employee
    2024-11-27T10:20:25.4533333+00:00

    Hello 👋🏼 colleague @Li Shen

    To enable OpenAPI v3 in Azure Function isolated model with .NET 8.0, you can use the Swashbuckle.AspNetCore NuGet package.

    Here are the steps to achieve this:

    1. Add the Swashbuckle.AspNetCore NuGet package to your project.
    2. In your Startup.cs file, add the following code to the ConfigureServices method:
    services.AddSwaggerGen(c => { c.SwaggerDoc("v1", 
    		new OpenApiInfo { Title = "My API", Version = "v1" }); });
    
    1. In the Configure method, add the following code:
    app.UseSwagger(); 
    app.UseSwaggerUI(c => { 
    	c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); 
    	});
    
    1. Build and run your project. This will enable OpenAPI v3 in your Azure Function isolated model with .NET 8.0. If you have any further questions, you know how to reach me.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.