-
Notifications
You must be signed in to change notification settings - Fork 25.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WN: P1 #34741
Merged
Merged
WN: P1 #34741
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
### OpenAPI 3.1 support | ||
|
||
https://github.com/dotnet/aspnetcore/pull/59480 | ||
https://github.com/dotnet/aspnetcore/pull/60002 | ||
|
||
ASP.NET Core has added support for generating [OpenAPI version 3.1] documents in .NET 10. | ||
Despite the minor version bump, OpenAPI 3.1 is a significant update to the OpenAPI specification, | ||
in particular with full support for [JSON Schema draft 2020-12]. | ||
|
@@ -11,11 +8,11 @@ in particular with full support for [JSON Schema draft 2020-12]. | |
[JSON Schema draft 2020-12]: https://json-schema.org/specification-links#2020-12 | ||
|
||
Some of the changes you will see in the generated OpenAPI document include: | ||
- Nullable types will no longer have the `nullable: true` property in the schema, and instead will have a `type` keyword whose value is an array that includes `null` as one of the types. | ||
|
||
With this feature, the default OpenAPI version for generated documents will be 3.1, but you can easily change this | ||
by explicitly setting the `OpenApiVersion` property of the `OpenApiOptions` in the `configureOptions` delegate | ||
parameter of `AddOpenApi`. | ||
- Nullable types no longer have the `nullable: true` property in the schema. | ||
- Instead of a `nullable: true` property, they have a `type` keyword whose value is an array that includes `null` as one of the types. | ||
|
||
With this feature, 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). | ||
|
||
```csharp | ||
builder.Services.AddOpenApi(options => | ||
|
@@ -25,21 +22,20 @@ builder.Services.AddOpenApi(options => | |
}); | ||
``` | ||
|
||
If you are generating the OpenAPI document at build time, you can select the OpenAPI version by setting the `--openapi-version` in the `OpenApiGenerateDocumentsOptions` MSBuild item. | ||
When generating the OpenAPI document at build time, the OpenAPI version can be selected by setting the `--openapi-version` in the `OpenApiGenerateDocumentsOptions` MSBuild item. | ||
|
||
```xml | ||
<!-- Configure build-time OpenAPI generation to produce an OpenAPI 3.0 document. --> | ||
<OpenApiGenerateDocumentsOptions>--openapi-version OpenApi3_0</OpenApiGenerateDocumentsOptions> | ||
``` | ||
|
||
### Breaking changes | ||
OpenAPI 3.1 support was primarly added in the following [PR](https://github.com/dotnet/aspnetcore/pull/59480). | ||
|
||
### OpenAPI 3.1 breaking changes | ||
|
||
Support for OpenAPI 3.1 requires an update to the underlying OpenAPI.NET library to a new major version, 2.0. This new version has some breaking changes from the previous version. The breaking changes may impact apps if they have any document, operation, or schema transformers. | ||
|
||
Support for OpenAPI 3.1 requires an update to the underlying OpenAPI.NET library to a new major version, 2.0. | ||
This new version has some breaking changes from the previous version, and this may impact your applications | ||
if you have any document, operation, or schema transformers. | ||
Perhaps the most significant change is that the `OpenApiAny` class has been dropped in favor of using `JsonNode` directly. | ||
If your transformers use `OpenApiAny`, you will need to update them to use `JsonNode` instead. | ||
For example, a schema transformer to add an example in .NET 9 might look like this: | ||
One of the most significant changes is that the `OpenApiAny` class has been dropped in favor of using `JsonNode` directly. Transformers that use `OpenApiAny` need to be updated to use `JsonNode`. For example, a schema transformer to add an example in .NET 9 might look like the following code: | ||
|
||
```csharp | ||
options.AddSchemaTransformer((schema, context, cancellationToken) => | ||
|
@@ -58,7 +54,7 @@ For example, a schema transformer to add an example in .NET 9 might look like th | |
}); | ||
``` | ||
|
||
In .NET 10 the transformer to do the same task will look like this: | ||
In .NET 10 the transformer to do the same task will look like the following code: | ||
|
||
```csharp | ||
options.AddSchemaTransformer((schema, context, cancellationToken) => | ||
|
@@ -77,22 +73,45 @@ In .NET 10 the transformer to do the same task will look like this: | |
}); | ||
``` | ||
|
||
Note that these changes will be necessary even if you congfigure the OpenAPI version to 3.0. | ||
The following example shows the changes in diff format. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mikekistler should I delete the before/after code and just have the |
||
|
||
### OpenAPI in Yaml | ||
```diff | ||
options.AddSchemaTransformer((schema, context, cancellationToken) => | ||
{ | ||
if (context.JsonTypeInfo.Type == typeof(WeatherForecast)) | ||
{ | ||
- schema.Example = new OpenApiObject | ||
+ schema.Example = new JsonObject | ||
{ | ||
- ["date"] = new OpenApiString(DateTime.Now.AddDays(1).ToString("yyyy-MM-dd")), | ||
+ ["date"] = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"), | ||
- ["temperatureC"] = new OpenApiInteger(0), | ||
+ ["temperatureC"] = 0, | ||
- ["temperatureF"] = new OpenApiInteger(32), | ||
+ ["temperatureF"] = 32, | ||
- ["summary"] = new OpenApiString("Bracing"), | ||
+ []"summary"] = "Bracing", | ||
}; | ||
} | ||
return Task.CompletedTask; | ||
}); | ||
``` | ||
|
||
https://github.com/dotnet/aspnetcore/pull/58616 | ||
Note that these changes are necessary even when only congfiguring the OpenAPI version to 3.0. | ||
|
||
ASP.NET now supports serving the generated OpenAPI document in YAML format. | ||
YAML can be more concise than JSON, eliminating curly braces and quotation marks when these can be inferred. | ||
YAML also supports multi-line strings, which can be useful for long descriptions. | ||
### OpenAPI in Yaml | ||
|
||
To configure your application to serve the generated OpenAPI document in YAML format, | ||
specify the endpoint in the MapOpenApi call with a ".yaml" or ".yml" suffix, as shown in this example: | ||
ASP.NET now supports serving the generated OpenAPI document in YAML format. YAML can be more concise than JSON, eliminating curly braces and quotation marks when these can be inferred. YAML also supports multi-line strings, which can be useful for long descriptions. | ||
|
||
To configure an app to serve the generated OpenAPI document in YAML format, specify the endpoint in the MapOpenApi call with a ".yaml" or ".yml" suffix, as shown in the following example: | ||
|
||
```csharp | ||
app.MapOpenApi("/openapi/{documentName}.yaml"); | ||
``` | ||
|
||
Support for YAML is currently only available for the the OpenAPI served from the OpenAPI endpoint. | ||
Support for generating OpenAPI documents in YAML format at build time will be added in a future preview. | ||
Support for: | ||
|
||
- YAML is currently only available for the the OpenAPI served from the OpenAPI endpoint. | ||
- Generating OpenAPI documents in YAML format at build time isadded in a future preview. | ||
|
||
See [this PR](https://github.com/dotnet/aspnetcore/pull/58616) which added support for serving the generated OpenAPI document in YAML format. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 7 additions & 12 deletions
19
aspnetcore/release-notes/aspnetcore-10/includes/testAppsTopLevel.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,12 @@ | ||
## Better support for testing apps with top-level statements | ||
|
||
https://github.com/dotnet/aspnetcore/pull/58199 | ||
https://github.com/dotnet/aspnetcore/pull/58482 | ||
.NET 10 now has better support for testing apps that use top-level statements. Previously developers had to manually add `public partial class Program` to the `Program.cs` file so that the test project could reference the `Program class`. This is because the top-level statement feature in C# 9 generated a `Program class` that was declared as internal. | ||
|
||
.NET 10 now has better support for testing apps that use top-level statements. | ||
Previously developers had to manually add `public partial class Program` to the | ||
Program.cs file so that the test project could reference the Program class. | ||
This is because the top-level statement feature in C# 9 generated a Program class | ||
that was declared as internal. | ||
In .NET 10, a source generator is used to generate the `public partial class Program` declaration if the programmer did not declare it explicitly. In addition, an analyzer was added to detect when `public partial class Program` is declared explicitly and advise the developer to remove it. | ||
|
||
In .NET 10, a source generator is used to generate the `public partial class Program` | ||
declaration if the programmer did not declare it explicitly. In addition, an analyzer | ||
was added to detect when `public partial class Program` is declared explicitly and | ||
advise the developer to remove it. | ||
 | ||
|
||
 | ||
The following PRs contribited to this feature: | ||
|
||
- [PR 58199](https://github.com/dotnet/aspnetcore/pull/58199) | ||
- [PR 58482](https://github.com/dotnet/aspnetcore/pull/58482) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate PR, is there another? I added the PR at the end of the H3