Skip to content

Commit 88594a6

Browse files
OpenApi 3.1 /1 (#35242)
* OpenApi 3.1 /1 * fix stuff * fix stuff * fix stuff * fix stuff
1 parent 07a5f4b commit 88594a6

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

aspnetcore/fundamentals/openapi/aspnetcore-openapi.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to generate and customize OpenAPI documents in an ASP.NET
55
ms.author: safia
66
monikerRange: '>= aspnetcore-6.0'
77
ms.custom: mvc
8-
ms.date: 2/23/2025
8+
ms.date: 3/18/2025
99
uid: fundamentals/openapi/aspnetcore-openapi
1010
---
1111
# Generate OpenAPI documents
@@ -14,12 +14,34 @@ uid: fundamentals/openapi/aspnetcore-openapi
1414

1515
The [`Microsoft.AspNetCore.OpenApi`](https://www.nuget.org/packages/Microsoft.AspNetCore.OpenApi) package provides built-in support for OpenAPI document generation in ASP.NET Core. The package provides the following features:
1616

17+
* Support for generating [OpenAPI version 3.1] documents.
18+
* Support for [JSON Schema draft 2020-12].
1719
* Support for generating OpenAPI documents at run time and accessing them via an endpoint on the app.
1820
* Support for "transformer" APIs that allow modifying the generated document.
1921
* Support for generating multiple OpenAPI documents from a single app.
2022
* Takes advantage of JSON schema support provided by [`System.Text.Json`](/dotnet/api/system.text.json).
2123
* Is compatible with native AoT.
2224

25+
[OpenAPI version 3.1]: https://spec.openapis.org/oas/v3.1.1.html
26+
[JSON Schema draft 2020-12]: https://json-schema.org/specification-links#2020-12
27+
28+
The default OpenAPI version for generated documents is`3.1`. The version can be changed by explicitly setting the [OpenApiVersion](/dotnet/api/microsoft.aspnetcore.openapi.openapioptions.openapiversion) property of the [OpenApiOptions](/dotnet/api/microsoft.aspnetcore.openapi.openapioptions) in the `configureOptions` delegate parameter of [AddOpenApi](/dotnet/api/microsoft.extensions.dependencyinjection.openapiservicecollectionextensions.addopenapi):
29+
30+
```csharp
31+
builder.Services.AddOpenApi(options =>
32+
{
33+
// Specify the OpenAPI version to use.
34+
options.OpenApiVersion = Microsoft.OpenApi.OpenApiSpecVersion.OpenApi3_0;
35+
});
36+
```
37+
38+
When generating the OpenAPI document at build time, the OpenAPI version can be selected by setting the `--openapi-version` in the `OpenApiGenerateDocumentsOptions` MSBuild item.
39+
40+
```xml
41+
<!-- Configure build-time OpenAPI generation to produce an OpenAPI 3.1 document. -->
42+
<OpenApiGenerateDocumentsOptions>--openapi-version OpenApi3_1</OpenApiGenerateDocumentsOptions>
43+
```
44+
2345
## Package installation
2446

2547
Install the `Microsoft.AspNetCore.OpenApi` package:
@@ -81,12 +103,12 @@ GET http://localhost:5000/openapi/internal.json
81103

82104
### Customize the OpenAPI version of a generated document
83105

84-
By default, OpenAPI document generation creates a document that is compliant with [v3.0 of the OpenAPI specification](https://spec.openapis.org/oas/v3.0.0). The following code demonstrates how to modify the default version of the OpenAPI document:
106+
By default, OpenAPI document generation creates a document that is compliant with [OpenAPI version 3.1](https://spec.openapis.org/oas/v3.1.1.html). The following code demonstrates how to modify the default version of the OpenAPI document:
85107

86108
```csharp
87109
builder.Services.AddOpenApi(options =>
88110
{
89-
options.OpenApiVersion = OpenApiSpecVersion.OpenApi2_0;
111+
options.OpenApiVersion = OpenApiSpecVersion.OpenApi3_0;
90112
});
91113
```
92114

aspnetcore/fundamentals/openapi/includes/aspnetcore-openapi9.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,10 @@ var app = builder.Build();
263263
+ app.MapOpenApi();
264264
```
265265

266-
:::moniker-end
267-
268266
Publish the app.
269267

270268
```console
271269
dotnet publish
272270
```
271+
272+
:::moniker-end

0 commit comments

Comments
 (0)