Skip to content
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 7 commits into from
Feb 15, 2025
Merged

WN: P1 #34741

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions aspnetcore/release-notes/aspnetcore-10.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ This section describes new features for minimal APIs.

This section describes new features for OpenAPI.

[!INCLUDE[](~/release-notes/aspnetcore-10/includes/openApi.md)]

[!INCLUDE[](~/release-notes/aspnetcore-10/includes/responseDescProducesResponseType.md)]

## Authentication and authorization

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

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

[!INCLUDE[](~/release-notes/aspnetcore-10/includes/testAppsTopLevel.md)]

## Related content
71 changes: 45 additions & 26 deletions aspnetcore/release-notes/aspnetcore-10/includes/openApi.md
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
Comment on lines -3 to -4
Copy link
Contributor Author

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


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].
Expand All @@ -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 =>
Expand All @@ -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) =>
Expand All @@ -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) =>
Expand All @@ -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.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikekistler should I delete the before/after code and just have the diff? I prefer the diff.


### 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.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
### Response description on ProducesResponseType

https://github.com/dotnet/aspnetcore/pull/58193

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:
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:

```csharp
[HttpGet(Name = "GetWeatherForecast")]
Expand All @@ -11,7 +9,7 @@ public IEnumerable<WeatherForecast> Get()
{
```

And the generated OpenAPI will be
And the generated OpenAPI:

```json
"responses": {
Expand All @@ -20,4 +18,4 @@ And the generated OpenAPI will be
"content": {
```

Community contribution! 🙏
[Community contribution](https://github.com/dotnet/aspnetcore/pull/58193) by [Sander ten Brinke](https://github.com/sander1095) 🙏
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.
![Image](https://github.com/user-attachments/assets/a37f0c81-a58a-453f-8da5-fa49356ca180)

![Image](https://github.com/user-attachments/assets/a37f0c81-a58a-453f-8da5-fa49356ca180)
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)