aspnetcore/fundamentals/openapi/overview.md
:::moniker range=">= aspnetcore-9.0"
ASP.NET Core supports the generation of OpenAPI documents in controller-based and Minimal APIs apps. The OpenAPI specification is a programming language-agnostic standard for documenting HTTP APIs. This standard is supported in ASP.NET Core apps through a combination of built-in APIs and open-source libraries. There are three key aspects to OpenAPI integration in an application:
ASP.NET Core apps provide built-in support for generating information about endpoints in an app via the Microsoft.AspNetCore.OpenApi package.
The following code is generated by the ASP.NET Core minimal web API template and uses OpenAPI:
In the preceding highlighted code:
AddOpenApi registers services required for OpenAPI document generation into the application's DI container.MapOpenApi adds an endpoint into the application for viewing the OpenAPI document serialized into JSON. The OpenAPI endpoint is restricted to the Development environment to minimize the risk of exposing sensitive information and reduce the vulnerabilities in production.<a name="openapinuget"></a>
Microsoft.AspNetCore.OpenApi NuGet packageThe Microsoft.AspNetCore.OpenApi package provides the following features:
To use the Microsoft.AspNetCore.OpenApi package, add it as a PackageReference to a project file:
To learn more about the Microsoft.AspNetCore.OpenApi package, see xref:fundamentals/openapi/aspnetcore-openapi.
Microsoft.Extensions.ApiDescription.Server NuGet packageThe Microsoft.Extensions.ApiDescription.Server package provides support for generating OpenAPI documents at build time and serializing them.
To use Microsoft.Extensions.ApiDescription.Server, add it as a PackageReference to a project file.
Document generation at build time is enabled by setting the OpenApiGenerateDocuments property.
By default, the generated OpenAPI document is saved to the obj directory, but you can customize
the output directory by setting the OpenApiDocumentsDirectory property.
:::moniker-end