Skip to content

Commit 63ab6cf

Browse files
WN: P1 (#34741)
* WN: P1 * WN: P1 * WN: P1 * WN: P1 * WN: P1 * WN: P1 * WN: P1
1 parent f4eb109 commit 63ab6cf

File tree

4 files changed

+61
-43
lines changed

4 files changed

+61
-43
lines changed

aspnetcore/release-notes/aspnetcore-10.0.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ This section describes new features for minimal APIs.
3333

3434
This section describes new features for OpenAPI.
3535

36+
[!INCLUDE[](~/release-notes/aspnetcore-10/includes/openApi.md)]
37+
38+
[!INCLUDE[](~/release-notes/aspnetcore-10/includes/responseDescProducesResponseType.md)]
39+
3640
## Authentication and authorization
3741

3842
This section describes new features for authentication and authorization.
@@ -41,4 +45,6 @@ This section describes new features for authentication and authorization.
4145

4246
This section describes miscellaneous new features in ASP.NET Core 10.0.
4347

48+
[!INCLUDE[](~/release-notes/aspnetcore-10/includes/testAppsTopLevel.md)]
49+
4450
## Related content
Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
### OpenAPI 3.1 support
22

3-
https://github.com/dotnet/aspnetcore/pull/59480
4-
https://github.com/dotnet/aspnetcore/pull/60002
5-
63
ASP.NET Core has added support for generating [OpenAPI version 3.1] documents in .NET 10.
74
Despite the minor version bump, OpenAPI 3.1 is a significant update to the OpenAPI specification,
85
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].
118
[JSON Schema draft 2020-12]: https://json-schema.org/specification-links#2020-12
129

1310
Some of the changes you will see in the generated OpenAPI document include:
14-
- 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.
1511

16-
With this feature, the default OpenAPI version for generated documents will be 3.1, but you can easily change this
17-
by explicitly setting the `OpenApiVersion` property of the `OpenApiOptions` in the `configureOptions` delegate
18-
parameter of `AddOpenApi`.
12+
- Nullable types no longer have the `nullable: true` property in the schema.
13+
- Instead of a `nullable: true` property, they have a `type` keyword whose value is an array that includes `null` as one of the types.
14+
15+
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).
1916

2017
```csharp
2118
builder.Services.AddOpenApi(options =>
@@ -25,21 +22,20 @@ builder.Services.AddOpenApi(options =>
2522
});
2623
```
2724

28-
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.
25+
When generating the OpenAPI document at build time, the OpenAPI version can be selected by setting the `--openapi-version` in the `OpenApiGenerateDocumentsOptions` MSBuild item.
2926

3027
```xml
3128
<!-- Configure build-time OpenAPI generation to produce an OpenAPI 3.0 document. -->
3229
<OpenApiGenerateDocumentsOptions>--openapi-version OpenApi3_0</OpenApiGenerateDocumentsOptions>
3330
```
3431

35-
### Breaking changes
32+
OpenAPI 3.1 support was primarly added in the following [PR](https://github.com/dotnet/aspnetcore/pull/59480).
33+
34+
### OpenAPI 3.1 breaking changes
35+
36+
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.
3637

37-
Support for OpenAPI 3.1 requires an update to the underlying OpenAPI.NET library to a new major version, 2.0.
38-
This new version has some breaking changes from the previous version, and this may impact your applications
39-
if you have any document, operation, or schema transformers.
40-
Perhaps the most significant change is that the `OpenApiAny` class has been dropped in favor of using `JsonNode` directly.
41-
If your transformers use `OpenApiAny`, you will need to update them to use `JsonNode` instead.
42-
For example, a schema transformer to add an example in .NET 9 might look like this:
38+
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:
4339

4440
```csharp
4541
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
5854
});
5955
```
6056

61-
In .NET 10 the transformer to do the same task will look like this:
57+
In .NET 10 the transformer to do the same task will look like the following code:
6258

6359
```csharp
6460
options.AddSchemaTransformer((schema, context, cancellationToken) =>
@@ -77,22 +73,45 @@ In .NET 10 the transformer to do the same task will look like this:
7773
});
7874
```
7975

80-
Note that these changes will be necessary even if you congfigure the OpenAPI version to 3.0.
76+
The following example shows the changes in diff format.
8177

82-
### OpenAPI in Yaml
78+
```diff
79+
options.AddSchemaTransformer((schema, context, cancellationToken) =>
80+
{
81+
if (context.JsonTypeInfo.Type == typeof(WeatherForecast))
82+
{
83+
- schema.Example = new OpenApiObject
84+
+ schema.Example = new JsonObject
85+
{
86+
- ["date"] = new OpenApiString(DateTime.Now.AddDays(1).ToString("yyyy-MM-dd")),
87+
+ ["date"] = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"),
88+
- ["temperatureC"] = new OpenApiInteger(0),
89+
+ ["temperatureC"] = 0,
90+
- ["temperatureF"] = new OpenApiInteger(32),
91+
+ ["temperatureF"] = 32,
92+
- ["summary"] = new OpenApiString("Bracing"),
93+
+ []"summary"] = "Bracing",
94+
};
95+
}
96+
return Task.CompletedTask;
97+
});
98+
```
8399

84-
https://github.com/dotnet/aspnetcore/pull/58616
100+
Note that these changes are necessary even when only congfiguring the OpenAPI version to 3.0.
85101

86-
ASP.NET now supports serving the generated OpenAPI document in YAML format.
87-
YAML can be more concise than JSON, eliminating curly braces and quotation marks when these can be inferred.
88-
YAML also supports multi-line strings, which can be useful for long descriptions.
102+
### OpenAPI in Yaml
89103

90-
To configure your application to serve the generated OpenAPI document in YAML format,
91-
specify the endpoint in the MapOpenApi call with a ".yaml" or ".yml" suffix, as shown in this example:
104+
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.
105+
106+
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:
92107

93108
```csharp
94109
app.MapOpenApi("/openapi/{documentName}.yaml");
95110
```
96111

97-
Support for YAML is currently only available for the the OpenAPI served from the OpenAPI endpoint.
98-
Support for generating OpenAPI documents in YAML format at build time will be added in a future preview.
112+
Support for:
113+
114+
- YAML is currently only available for the the OpenAPI served from the OpenAPI endpoint.
115+
- Generating OpenAPI documents in YAML format at build time isadded in a future preview.
116+
117+
See [this PR](https://github.com/dotnet/aspnetcore/pull/58616) which added support for serving the generated OpenAPI document in YAML format.
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
### Response description on ProducesResponseType
22

3-
https://github.com/dotnet/aspnetcore/pull/58193
4-
5-
The ProducesAttribute, ProducesResponseTypeAttribute, and ProducesDefaultResponseType attributes now accept an optional string parameter, `Description`, that will set the description of the response. Here's an example:
3+
The [ProducesAttribute](/dotnet/api/microsoft.aspnetcore.mvc.producesattribute-1), [ProducesResponseTypeAttribute](/dotnet/api/microsoft.aspnetcore.mvc.producesresponsetypeattribute-1), and [ProducesDefaultResponseType](/dotnet/api/microsoft.aspnetcore.mvc.producesdefaultresponsetypeattribute) attributes now accept an optional string parameter, `Description`, that will set the description of the response. Here's an example:
64

75
```csharp
86
[HttpGet(Name = "GetWeatherForecast")]
@@ -11,7 +9,7 @@ public IEnumerable<WeatherForecast> Get()
119
{
1210
```
1311

14-
And the generated OpenAPI will be
12+
And the generated OpenAPI:
1513

1614
```json
1715
"responses": {
@@ -20,4 +18,4 @@ And the generated OpenAPI will be
2018
"content": {
2119
```
2220

23-
Community contribution! 🙏
21+
[Community contribution](https://github.com/dotnet/aspnetcore/pull/58193) by [Sander ten Brinke](https://github.com/sander1095) 🙏
Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
## Better support for testing apps with top-level statements
22

3-
https://github.com/dotnet/aspnetcore/pull/58199
4-
https://github.com/dotnet/aspnetcore/pull/58482
3+
.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.
54

6-
.NET 10 now has better support for testing apps that use top-level statements.
7-
Previously developers had to manually add `public partial class Program` to the
8-
Program.cs file so that the test project could reference the Program class.
9-
This is because the top-level statement feature in C# 9 generated a Program class
10-
that was declared as internal.
5+
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.
116

12-
In .NET 10, a source generator is used to generate the `public partial class Program`
13-
declaration if the programmer did not declare it explicitly. In addition, an analyzer
14-
was added to detect when `public partial class Program` is declared explicitly and
15-
advise the developer to remove it.
7+
![Image](https://github.com/user-attachments/assets/a37f0c81-a58a-453f-8da5-fa49356ca180)
168

17-
![Image](https://github.com/user-attachments/assets/a37f0c81-a58a-453f-8da5-fa49356ca180)
9+
The following PRs contribited to this feature:
10+
11+
- [PR 58199](https://github.com/dotnet/aspnetcore/pull/58199)
12+
- [PR 58482](https://github.com/dotnet/aspnetcore/pull/58482)

0 commit comments

Comments
 (0)