Skip to content

Commit 41b6b7c

Browse files
Merge pull request #34854 from dotnet/main
Merge to Live
2 parents e5b795b + 53dc80a commit 41b6b7c

File tree

47 files changed

+224
-83
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+224
-83
lines changed

.github/ISSUE_TEMPLATE/customer-feedback.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ body:
3838
required: true
3939
attributes:
4040
label: Document ID
41+
- type: input
42+
id: platformId
43+
validations:
44+
required: true
45+
attributes:
46+
label: Platform Id
4147
- type: input
4248
id: author
4349
validations:

aspnetcore/blazor/security/includes/usermanager-signinmanager.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ services.Configure<IdentityOptions>(options =>
3030
The following `WeatherForecastController` logs the <xref:Microsoft.AspNetCore.Identity.IdentityUser%601.UserName> when the `Get` method is called.
3131

3232
> [!NOTE]
33-
> The following example uses a [file-scoped namespace](/dotnet/csharp/language-reference/keywords/namespace), which is a C# 10 or later (.NET 6 or later) feature.
33+
> The following example uses:
34+
>
35+
> * A [file-scoped namespace](/dotnet/csharp/language-reference/keywords/namespace), which is a C# 10 or later (.NET 6 or later) feature.
36+
> * A [primary constructor](/dotnet/csharp/whats-new/tutorials/primary-constructors), which is a C# 12 or later (.NET 8 or later) feature.
3437
3538
```csharp
3639
using System;
@@ -49,25 +52,15 @@ namespace BlazorSample.Server.Controllers;
4952
[Authorize]
5053
[ApiController]
5154
[Route("[controller]")]
52-
public class WeatherForecastController : ControllerBase
55+
public class WeatherForecastController(ILogger<WeatherForecastController> logger,
56+
UserManager<ApplicationUser> userManager) : ControllerBase
5357
{
54-
private readonly UserManager<ApplicationUser> userManager;
55-
5658
private static readonly string[] Summaries = new[]
5759
{
5860
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm",
5961
"Balmy", "Hot", "Sweltering", "Scorching"
6062
};
6163

62-
private readonly ILogger<WeatherForecastController> logger;
63-
64-
public WeatherForecastController(ILogger<WeatherForecastController> logger,
65-
UserManager<ApplicationUser> userManager)
66-
{
67-
this.logger = logger;
68-
this.userManager = userManager;
69-
}
70-
7164
[HttpGet]
7265
public async Task<IEnumerable<WeatherForecast>> Get()
7366
{

aspnetcore/fundamentals/aot/request-delegate-generator/rdg.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
32
title: ASP.NET Core Request Delegate Generator (RDG) for Native AOT
43
description: Turn Map methods into request delegates with the ASP.NET Core Request Delegate Generator (RDG) for Native AOT.
54
author: rick-anderson
@@ -48,7 +47,17 @@ The RDG:
4847
* Is enabled automatically in projects when publishing with Native AOT is enabled or when trimming is enabled.
4948
* Can be manually enabled even when not using Native AOT by setting `<EnableRequestDelegateGenerator>true</EnableRequestDelegateGenerator>` in the project file:
5049

51-
:::code language="xml" source="~/fundamentals/aot/samples/rdg/RDG.csproj" highlight="7":::
50+
:::moniker range=">= aspnetcore-10.0"
51+
52+
:::code language="xml" source="~/fundamentals/aot/samples/10.0/rdg/RDG.csproj" highlight="7":::
53+
54+
:::moniker-end
55+
56+
:::moniker range="< aspnetcore-10.0"
57+
58+
:::code language="xml" source="~/fundamentals/aot/samples/8.0/rdg/RDG.csproj" highlight="7":::
59+
60+
:::moniker-end
5261

5362
Manually enabling RDG can be useful for:
5463

@@ -57,7 +66,17 @@ Manually enabling RDG can be useful for:
5766

5867
Minimal APIs are optimized for using <xref:System.Text.Json>, which requires using the [System.Text.Json source generator](/dotnet/standard/serialization/system-text-json/source-generation). All types accepted as parameters to or returned from request delegates in Minimal APIs must be configured on a <xref:System.Text.Json.Serialization.JsonSerializerContext> that's registered via ASP.NET Core's dependency injection:
5968

60-
:::code language="csharp" source="~/fundamentals/aot/samples/rdg/Program.cs" highlight="5-9,32-99":::
69+
:::moniker range=">= aspnetcore-10.0"
70+
71+
:::code language="csharp" source="~/fundamentals/aot/samples/10.0/rdg/Program.cs" highlight="5-9,34-36":::
72+
73+
:::moniker-end
74+
75+
:::moniker range="< aspnetcore-10.0"
76+
77+
:::code language="csharp" source="~/fundamentals/aot/samples/8.0/rdg/Program.cs" highlight="5-9,32-35":::
78+
79+
:::moniker-end
6180

6281
## Diagnostics for unsupported RDG scenarios
6382

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Text.Json.Serialization;
2+
3+
var builder = WebApplication.CreateSlimBuilder(args);
4+
5+
builder.Services.ConfigureHttpJsonOptions(options =>
6+
{
7+
options.SerializerOptions.TypeInfoResolverChain.Insert(
8+
0, AppJsonSerializerContext.Default);
9+
});
10+
11+
var app = builder.Build();
12+
13+
Todo[] sampleTodos =
14+
[
15+
new(1, "Walk the dog"),
16+
new(2, "Do the dishes", DateOnly.FromDateTime(DateTime.Now)),
17+
new(3, "Do the laundry", DateOnly.FromDateTime(DateTime.Now.AddDays(1))),
18+
new(4, "Clean the bathroom"),
19+
new(5, "Clean the car", DateOnly.FromDateTime(DateTime.Now.AddDays(2)))
20+
];
21+
22+
var todosApi = app.MapGroup("/todos");
23+
todosApi.MapGet("/", () => sampleTodos);
24+
todosApi.MapGet("/{id}", (int id) =>
25+
sampleTodos.FirstOrDefault(a => a.Id == id) is { } todo
26+
? Results.Ok(todo)
27+
: Results.NotFound());
28+
29+
app.Run();
30+
31+
public record Todo(int Id, string? Title, DateOnly? DueBy = null, bool IsComplete = false);
32+
33+
[JsonSerializable(typeof(Todo[]))]
34+
internal partial class AppJsonSerializerContext : JsonSerializerContext
35+
{
36+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net10.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<EnableRequestDelegateGenerator>true</EnableRequestDelegateGenerator>
8+
</PropertyGroup>
9+
10+
</Project>

aspnetcore/fundamentals/aot/samples/rdg/Program.cs renamed to aspnetcore/fundamentals/aot/samples/8.0/rdg/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,4 @@ public record Todo(int Id, string? Title, DateOnly? DueBy = null, bool IsComplet
3232
[JsonSerializable(typeof(Todo[]))]
3333
internal partial class AppJsonSerializerContext : JsonSerializerContext
3434
{
35-
3635
}

aspnetcore/fundamentals/aot/samples/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,4 @@
2525
[JsonSerializable(typeof(Todo[]))]
2626
internal partial class AppJsonSerializerContext : JsonSerializerContext
2727
{
28-
2928
}

aspnetcore/fundamentals/openapi/aspnetcore-openapi.md

Lines changed: 37 additions & 17 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: 01/23/2025
8+
ms.date: 2/23/2025
99
uid: fundamentals/openapi/aspnetcore-openapi
1010
---
1111
# Generate OpenAPI documents
@@ -14,7 +14,7 @@ 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 documents at run time and accessing them via an endpoint on the application.
17+
* Support for generating OpenAPI documents at run time and accessing them via an endpoint on the app.
1818
* Support for "transformer" APIs that allow modifying the generated document.
1919
* Support for generating multiple OpenAPI documents from a single app.
2020
* Takes advantage of JSON schema support provided by [`System.Text.Json`](/dotnet/api/system.text.json).
@@ -112,7 +112,7 @@ The OpenAPI endpoint doesn't enable any authorization checks by default. Howeve
112112

113113
#### Cache generated OpenAPI document
114114

115-
The OpenAPI document is regenerated every time a request to the OpenAPI endpoint is sent. Regeneration enables transformers to incorporate dynamic application state into their operation. For example, regenerating a request with details of the HTTP context. When applicable, the OpenAPI document can be cached to avoid executing the document generation pipeline on each HTTP request.
115+
The OpenAPI document is regenerated every time a request to the OpenAPI endpoint is sent. Regeneration enables transformers to incorporate dynamic app state into their operation. For example, regenerating a request with details of the HTTP context. When applicable, the OpenAPI document can be cached to avoid executing the document generation pipeline on each HTTP request.
116116

117117
[!code-csharp[](~/fundamentals/openapi/samples/9.x/WebMinOpenApi/Program.cs?name=snippet_mapopenapiwithcaching)]
118118

@@ -122,7 +122,7 @@ In some scenarios, it's helpful to generate multiple OpenAPI documents with diff
122122

123123
* Generating OpenAPI documentation for different audiences, such as public and internal APIs.
124124
* Generating OpenAPI documentation for different versions of an API.
125-
* Generating OpenAPI documentation for different parts of an application, such as a frontend and backend API.
125+
* Generating OpenAPI documentation for different parts of an app, such as a frontend and backend API.
126126

127127
To generate multiple OpenAPI documents, call the <xref:Microsoft.Extensions.DependencyInjection.OpenApiServiceCollectionExtensions.AddOpenApi%2A> extension method once for each document, specifying a different document name in the first parameter each time.
128128

@@ -135,9 +135,12 @@ Each invocation of <xref:Microsoft.Extensions.DependencyInjection.OpenApiService
135135

136136
The framework uses the <xref:Microsoft.AspNetCore.OpenApi.OpenApiOptions.ShouldInclude> delegate method of <xref:Microsoft.AspNetCore.OpenApi.OpenApiOptions> to determine which endpoints to include in each document.
137137

138-
For each document, the <xref:Microsoft.AspNetCore.OpenApi.OpenApiOptions.ShouldInclude> delegate method is called for each endpoint in the application, passing the <xref:Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescription> object for the endpoint. The method returns a boolean value indicating whether the endpoint should be included in the document. The <xref:Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescription> object contains information about the endpoint, such as the HTTP method, route, and response types, as well as metadata attached to the endpoint via attributes or extension methods.
138+
For each document, the <xref:Microsoft.AspNetCore.OpenApi.OpenApiOptions.ShouldInclude> delegate method is called for each endpoint in the app, passing the <xref:Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescription> object for the endpoint. The method returns a boolean value indicating whether the endpoint should be included in the document. The <xref:Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescription> object:
139139

140-
The default implementation of this delegate uses the <xref:Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescription.GroupName> field of <xref:Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescription>, which is set on an endpoint using either the <xref:Microsoft.AspNetCore.Builder.RoutingEndpointConventionBuilderExtensions.WithGroupName%2A> extension method or the <xref:Microsoft.AspNetCore.Routing.EndpointGroupNameAttribute> attribute, to determine which endpoints to include in the document. Any endpoint that has not been assigned a group name is included all OpenAPI documents.
140+
* contains information about the endpoint, such as the HTTP method, route, and response types
141+
* Metadata attached to the endpoint via attributes or extension methods.
142+
143+
The default implementation of this delegate uses the <xref:Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescription.GroupName> field of <xref:Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescription>. The delegate is set on an endpoint using either the <xref:Microsoft.AspNetCore.Builder.RoutingEndpointConventionBuilderExtensions.WithGroupName%2A> extension method or the <xref:Microsoft.AspNetCore.Routing.EndpointGroupNameAttribute> attribute. `WithGroupName` or the `EndpointGroupName` attribute determines which endpoints to include in the document. Any endpoint that has not been assigned a group name is included all OpenAPI documents.
141144

142145
```csharp
143146
// Include endpoints without a group name or with a group name that matches the document name
@@ -148,13 +151,13 @@ You can customize the <xref:Microsoft.AspNetCore.OpenApi.OpenApiOptions.ShouldIn
148151

149152
## Generate OpenAPI documents at build-time
150153

151-
In typical web applications, OpenAPI documents are generated at run-time and served via an HTTP request to the application server.
154+
In typical web apps, OpenAPI documents are generated at run-time and served via an HTTP request to the app server.
152155

153-
In some scenarios, it's helpful to generate the OpenAPI document during the application's build step. These scenarios include:
156+
In some scenarios, it's helpful to generate the OpenAPI document during the app's build step. These scenarios include:
154157

155-
- Generating OpenAPI documentation that is committed into source control.
156-
- Generating OpenAPI documentation that is used for spec-based integration testing.
157-
- Generating OpenAPI documentation that is served statically from the web server.
158+
* Generating OpenAPI documentation that is committed into source control.
159+
* Generating OpenAPI documentation that is used for spec-based integration testing.
160+
* Generating OpenAPI documentation that is served statically from the web server.
158161

159162
To add support for generating OpenAPI documents at build time, install the `Microsoft.Extensions.ApiDescription.Server` package:
160163

@@ -173,20 +176,37 @@ Run the following command in the directory that contains the project file:
173176
```dotnetcli
174177
dotnet add package Microsoft.Extensions.ApiDescription.Server
175178
```
179+
176180
---
177181

178-
Upon installation, this package will automatically generate the Open API document(s) associated with the application during build and populate them into the application's output directory.
182+
Upon installation, this package:
183+
184+
* Automatically generates the Open API document(s) associated with the app during build.
185+
* Populates the Open API documents in the app's output directory.
186+
187+
If multiple documents are registered, ***and*** document name is ***not*** `v1`, it's post-fixed with the document name. E.g., `{ProjectName}_{DocumentName}.json`.
188+
189+
# [Visual Studio Code](#tab/visual-studio-code)
190+
191+
```powershell
192+
dotnet build
193+
type obj\{ProjectName}.json
194+
```
195+
196+
# [.NET Core CLI](#tab/netcore-cli)
179197

180198
```cli
181-
$ dotnet build
182-
$ cat bin/Debug/net9.0/{ProjectName}.json
199+
dotnet build
200+
cat obj/{ProjectName}.json
183201
```
184202

203+
---
204+
185205
### Customizing build-time document generation
186206

187207
#### Modifying the output directory of the generated Open API file
188208

189-
By default, the generated OpenAPI document will be emitted to the application's output directory. To modify the location of the emitted file, set the target path in the `OpenApiDocumentsDirectory` property.
209+
By default, the generated OpenAPI document will be emitted to the app's output directory. To modify the location of the emitted file, set the target path in the `OpenApiDocumentsDirectory` property.
190210

191211
```xml
192212
<PropertyGroup>
@@ -198,7 +218,7 @@ The value of `OpenApiDocumentsDirectory` is resolved relative to the project fil
198218

199219
#### Modifying the output file name
200220

201-
By default, the generated OpenAPI document will have the same name as the application's project file. To modify the name of the emitted file, set the `--file-name` argument in the `OpenApiGenerateDocumentsOptions` property.
221+
By default, the generated OpenAPI document will have the same name as the app's project file. To modify the name of the emitted file, set the `--file-name` argument in the `OpenApiGenerateDocumentsOptions` property.
202222

203223
```xml
204224
<PropertyGroup>
@@ -208,7 +228,7 @@ By default, the generated OpenAPI document will have the same name as the applic
208228

209229
#### Selecting the OpenAPI document to generate
210230

211-
Some applications may be configured to emit multiple OpenAPI documents, for various versions of an API or to distinguish between public and internal APIs. By default, the build-time document generator will emit files for all documents that are configured in an application. To only emit for a single document name, set the `--document-name` argument in the `OpenApiGenerateDocumentsOptions` property.
231+
Some apps may be configured to emit multiple OpenAPI documents. Multiple OpenAPI documents may be generated for different versions of an API or to distinguish between public and internal APIs. By default, the build-time document generator emits files for all documents that are configured in an app. To only emit for a single document name, set the `--document-name` argument in the `OpenApiGenerateDocumentsOptions` property.
212232

213233
```xml
214234
<PropertyGroup>

0 commit comments

Comments
 (0)