You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/fundamentals/openapi/customize-openapi.md
+26-10Lines changed: 26 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ description: Learn how to customize OpenAPI documents in an ASP.NET Core app
5
5
ms.author: safia
6
6
monikerRange: '>= aspnetcore-9.0'
7
7
ms.custom: mvc
8
-
ms.date: 10/26/2024
8
+
ms.date: 05/15/2025
9
9
uid: fundamentals/openapi/customize-openapi
10
10
---
11
11
# Customize OpenAPI documents
@@ -44,18 +44,18 @@ Transformers can be registered onto the document by calling the <xref:Microsoft.
44
44
45
45
### Execution order for transformers
46
46
47
-
Transformers are executed as follows:
47
+
Transformers execute in the following order:
48
48
49
-
* Schema transformers are executed when a schema is registered to the document. Schema transformers are executed in the order in which they were added.
50
-
All schemas are added to the document before any operation processing occurs, so all schema transformers are executed before any operation transformers.
51
-
* Operation transformers are executed when an operation is added to the document. Operation transformers are executed in the order in which they were added.
52
-
All operations are added to the document before any document transformers are executed.
53
-
* Document transformers are executed when the document is generated. This is the final pass over the document, and all operations and schemas have been add by this point.
54
-
* When an app is configured to generate multiple OpenAPI documents, transformers are executed for each document independently.
49
+
* Schema transformers execute when a schema is registered to the document. They execute in the order they're added.
50
+
All schemas are added to the document before any operation processing occurs, so schema transformers execute before operation transformers.
51
+
* Operation transformers execute when an operation is added to the document. They execute in the order they're added.
52
+
All operations are added to the document before any document transformers execute.
53
+
* Document transformers execute when the document is generated. This is the final pass over the document, and all operations and schemas are added by this point.
54
+
* When an app is configured to generate multiple OpenAPI documents, transformers execute for each document independently.
55
55
56
56
For example, in the following snippet:
57
57
*`SchemaTransformer2` is executed and has access to the modifications made by `SchemaTransformer1`.
58
-
* Both `OperationTransformer1` and `OperationTransformer2` have access to the modifications made by both schema transformers for the types involved in the operation they are called to process.
58
+
* Both `OperationTransformer1` and `OperationTransformer2` have access to the modifications made by both schema transformers for the types involved in the operation they're called to process.
59
59
*`OperationTransformer2` is executed after `OperationTransformer1`, so it has access to the modifications made by `OperationTransformer1`.
60
60
* Both `DocumentTransformer1` and `DocumentTransformer2` are executed after all operations and schemas have been added to the document, so they have access to all modifications made by the operation and schema transformers.
61
61
*`DocumentTransformer2` is executed after `DocumentTransformer1`, so it has access to the modifications made by `DocumentTransformer1`.
@@ -119,6 +119,22 @@ For example, the following schema transformer sets the `format` of decimal types
Developers can generate a schema for a C# type using the same logic as ASP.NET Core OpenAPI document generation and add it to the OpenAPI document. The schema can then be referenced from elsewhere in the OpenAPI document. This capability is available starting with .NET 10.
126
+
127
+
The context passed to document, operation, and schema transformers includes a new `GetOrCreateSchemaAsync` method that can be used to generate a schema for a type.
128
+
This method also has an optional `ApiParameterDescription` parameter to specify additional metadata for the generated schema.
129
+
130
+
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.
131
+
132
+
### Example
133
+
134
+
To use this feature in a document, operation, or schema transformer, create the schema using the `GetOrCreateSchemaAsync` method provided in the context and add it to the OpenAPI document using the document's `AddComponent` method.
0 commit comments