Skip to content

Commit 9cb6560

Browse files
author
Sander ten Brinke
committed
Add documentation for endpoint-specific OpenAPI operation transformers
1 parent a7b09b2 commit 9cb6560

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

aspnetcore/release-notes/aspnetcore-10.0.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author: wadepickett
44
description: Learn about the new features in ASP.NET Core in .NET 10.
55
ms.author: wpickett
66
ms.custom: mvc
7-
ms.date: 09/15/2025
7+
ms.date: 11/11/2025
88
uid: aspnetcore-10
99
---
1010
# What's new in ASP.NET Core in .NET 10
@@ -67,6 +67,8 @@ This section describes new features for OpenAPI.
6767

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

70+
[!INCLUDE[](~/release-notes/aspnetcore-10/includes/endpoint-specific-operation-transformers.md)]
71+
7072
[!INCLUDE[](~/release-notes/aspnetcore-10/includes/upgrade-microsoft-openapi-2.md)]
7173

7274
[!INCLUDE[](~/release-notes/aspnetcore-10/includes/openapi-schema-enhancements.md)]
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
### Endpoint-specific OpenAPI operation transformers
2+
3+
OpenAPI [operation transformers](<xref:fundamentals/openapi/customize-openapi#use-operation-transformers>) can now be registered directly on individual endpoints using the `AddOpenApiOperationTransformer` extension method. This allows customization of OpenAPI metadata to be colocated with the endpoint definition, rather than requiring global configuration with path-based conditional logic.
4+
5+
Prior to this feature, modifying OpenAPI data for specific endpoints required registering a global operation transformer and implementing conditional logic to target specific endpoints. For example:
6+
7+
```csharp
8+
builder.Services.AddOpenApi(options =>
9+
{
10+
options.AddOperationTransformer((operation, context, ct) =>
11+
{
12+
if (context.Description.RelativePath == "deprecated-endpoint")
13+
{
14+
operation.Deprecated = true;
15+
}
16+
17+
return Task.CompletedTask;
18+
});
19+
});
20+
```
21+
22+
With the new `AddOpenApiOperationTransformer` API, the same customization can be applied directly to the endpoint, with access to the full operation context as well:
23+
24+
```csharp
25+
app.MapGet("/deprecated-endpoint", () => "This endpoint is old and should not be used anymore")
26+
.AddOpenApiOperationTransformer((operation, context, cancellationToken) =>
27+
{
28+
operation.Deprecated = true;
29+
30+
return Task.CompletedTask;
31+
});
32+
```
33+
34+
This approach improves code readability and maintainability by keeping endpoint-specific customizations close to the endpoint definitions. The `AddOpenApiOperationTransformer` method provides access to the full <xref:Microsoft.AspNetCore.OpenApi.OpenApiOperationTransformerContext>, enabling comprehensive customization of the OpenAPI operation, including:
35+
36+
* Setting operation properties like `Deprecated`, `Summary`, or `Description`
37+
* Customizing response descriptions
38+
* Adding or modifying security requirements
39+
* Modifying parameters or request bodies

0 commit comments

Comments
 (0)