Skip to content

Commit a75e380

Browse files
authored
Merge pull request #35410 from dotnet/main
2 parents 8d20f9e + c7ffbdb commit a75e380

File tree

4 files changed

+58
-4
lines changed

4 files changed

+58
-4
lines changed

aspnetcore/blazor/security/webassembly/additional-scenarios.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,15 @@ public class CustomAuthorizationMessageHandler : AuthorizationMessageHandler
300300
}
301301
```
302302

303+
> [!NOTE]
304+
> In this section, the preceding message handler is used when a configured <xref:System.Net.Http.HttpClient> is created from an injected <xref:System.Net.Http.IHttpClientFactory>. If you don't use an <xref:System.Net.Http.IHttpClientFactory>, you must create an <xref:System.Net.Http.HttpClientHandler> instance and assign it to the <xref:Microsoft.AspNetCore.Components.WebAssembly.Authentication.AuthorizationMessageHandler>'s <xref:System.Net.Http.DelegatingHandler.InnerHandler%2A?displayProperty=nameWithType>:
305+
>
306+
> ```csharp
307+
> InnerHandler = new HttpClientHandler();
308+
> ```
309+
>
310+
> You don't need to make the preceding <xref:System.Net.Http.DelegatingHandler.InnerHandler> assignment if you use <xref:System.Net.Http.IHttpClientFactory>, as the `ExampleAPIMethod` call later in this section demonstrates.
311+
303312
In the preceding code, the scopes `example.read` and `example.write` are generic examples not meant to reflect valid scopes for any particular provider.
304313

305314
In the `Program` file, `CustomAuthorizationMessageHandler` is registered as a transient service and is configured as the <xref:System.Net.Http.DelegatingHandler> for outgoing <xref:System.Net.Http.HttpResponseMessage> instances made by a named <xref:System.Net.Http.HttpClient>.
@@ -378,7 +387,10 @@ builder.Services.AddScoped(sp => new HttpClient(
378387
});
379388
```
380389

381-
In the preceding code, the scopes `example.read` and `example.write` are generic examples not meant to reflect valid scopes for any particular provider.
390+
In the preceding code:
391+
392+
* The scopes `example.read` and `example.write` are generic examples not meant to reflect valid scopes for any particular provider.
393+
* <xref:System.Net.Http.IHttpClientFactory> isn't used to create <xref:System.Net.Http.HttpClient> instances, so an <xref:System.Net.Http.HttpClientHandler> instance is manually created and assigned to the <xref:Microsoft.AspNetCore.Components.WebAssembly.Authentication.AuthorizationMessageHandler>'s <xref:System.Net.Http.DelegatingHandler.InnerHandler%2A?displayProperty=nameWithType>.
382394

383395
:::moniker range="< aspnetcore-8.0"
384396

aspnetcore/fundamentals/openapi/overview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
title: Overview of OpenAPI support in ASP.NET Core API apps
3-
author: wadepickett
3+
author: rick-anderson
44
description: Learn about OpenAPI features in ASP.NET Core.
5-
ms.author: wpickett
5+
ms.author: riande
66
monikerRange: '>= aspnetcore-6.0'
77
ms.date: 8/02/2024
88
uid: fundamentals/openapi/overview

aspnetcore/performance/rate-limit-samples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Rate limiting middleware samsples
2+
title: Rate limiting middleware samples
33
author: rick-anderson
44
ms.author: riande
55
monikerRange: '>= aspnetcore-7.0'
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
### Support for generating OpenApiSchemas in transformers
2+
<!-- https://github.com/dotnet/aspnetcore/pull/61050 -->
3+
4+
Developers can now generate a schema for a C# type, using the same logic as ASP.NET Core OpenAPI document generation,
5+
and add it to the OpenAPI document. The schema can then be referenced from elsewhere in the OpenAPI document.
6+
7+
The context passed to document, operation, and schema transformers now has a `GetOrCreateSchemaAsync` method that can be used to generate a schema for a type.
8+
This method also has an optional `ApiParameterDescription` parameter to specify additional metadata for the generated schema.
9+
10+
To support adding the schema to the OpenAPI document, a `Document` property has been added to the Operation and Schema transformer contexts. This allows any transformer to add a schema to the OpenAPI document using the document's `AddComponent` method.
11+
12+
#### Example
13+
14+
To use this feature in an document, operation, or schema transformer, create the schema using the `GetOrCreateSchemaAsync` method provided in the context
15+
and add it to the OpenAPI document using the document's `AddComponent` method.
16+
17+
<!-- In the docs, highlight the lines with the call to "GetOrCreateSchemaAsync" and "AddComponent" -->
18+
```csharp
19+
builder.Services.AddOpenApi(options =>
20+
{
21+
options.AddOperationTransformer(async (operation, context, cancellationToken) =>
22+
{
23+
// Generate schema for error responses
24+
var errorSchema = await context.GetOrCreateSchemaAsync(typeof(ProblemDetails), null, cancellationToken);
25+
context.Document?.AddComponent("Error", errorSchema);
26+
27+
operation.Responses ??= new OpenApiResponses();
28+
// Add a "4XX" response to the operation with the newly created schema
29+
operation.Responses["4XX"] = new OpenApiResponse
30+
{
31+
Description = "Bad Request",
32+
Content = new Dictionary<string, OpenApiMediaType>
33+
{
34+
["application/problem+json"] = new OpenApiMediaType
35+
{
36+
Schema = new OpenApiSchemaReference("Error", context.Document)
37+
}
38+
}
39+
};
40+
});
41+
});
42+
```

0 commit comments

Comments
 (0)