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
ASP.NET collects metadata from the web app's endpoints and uses it to generate an OpenAPI document.
16
18
In controller-based apps, metadata is collected from attributes like [`[EndpointDescription]`](xref:Microsoft.AspNetCore.Http.EndpointDescriptionAttribute), [`[HttpPost]`](xref:Microsoft.AspNetCore.Mvc.HttpPostAttribute),
17
19
and [`[Produces]`](xref:Microsoft.AspNetCore.Mvc.ProducesAttribute).
@@ -314,8 +316,6 @@ app.MapGet("/todos",
314
316
async (TodoDbdb) =>awaitdb.Todos.ToListAsync());
315
317
```
316
318
317
-
:::moniker range=">= aspnetcore-10.0"
318
-
319
319
[`[ProducesResponseType]`](xref:Microsoft.AspNetCore.Mvc.ProducesResponseTypeAttribute), [`[Produces]`](xref:Microsoft.AspNetCore.Mvc.ProducesAttribute), and [`[ProducesDefaultResponseType]`](xref:Microsoft.AspNetCore.Mvc.ProducesResponseTypeAttribute) also support an optional string property called `Description` that can be used to describe the response. This is useful for explaining why or when clients can expect a specific response:
320
320
321
321
```csharp
@@ -327,8 +327,6 @@ app.MapGet("/todos/{id}",
327
327
async (intid, TodoDbdb) =>/* Code here */);
328
328
```
329
329
330
-
:::moniker-end
331
-
332
330
Using <xref:Microsoft.AspNetCore.Http.TypedResults> in the implementation of an endpoint's route handler automatically includes the response type metadata for the endpoint. For example, the following code automatically annotates the endpoint with a response under the `200` status code with an `application/json` content type.
333
331
334
332
```csharp
@@ -398,8 +396,6 @@ Only one [`[Produces]`](xref:Microsoft.AspNetCore.Mvc.ProducesAttribute) or <xre
398
396
399
397
All of the above attributes can be applied to individual action methods or to the controller class where it applies to all action methods in the controller.
400
398
401
-
:::moniker range=">= aspnetcore-10.0"
402
-
403
399
[`[ProducesResponseType]`](xref:Microsoft.AspNetCore.Mvc.ProducesResponseTypeAttribute), [`[Produces]`](xref:Microsoft.AspNetCore.Mvc.ProducesAttribute), and [`[ProducesDefaultResponseType]`](xref:Microsoft.AspNetCore.Mvc.ProducesResponseTypeAttribute) also support an optional string property called `Description` that can be used to describe the response. This is useful for explaining why or when clients can expect a specific response:
404
400
405
401
```csharp
@@ -412,8 +408,6 @@ All of the above attributes can be applied to individual action methods or to th
Note that object and dynamic types have _no_ type defined in the OpenAPI because these can contain data of any type, including primitive types like int or string.
522
-
523
-
The `type` and `format` can also be set with a [Schema Transformer](xref:fundamentals/openapi/customize-openapi#use-schema-transformers). For example, you may want the `format` of decimal types to be `decimal` instead of `double`.
524
-
525
-
:::moniker-end
526
-
527
-
:::moniker range=">= aspnetcore-10.0"
528
-
529
490
#### Numeric types
530
491
531
492
The JSON Schema library maps standard C# numeric types to OpenAPI `type` and `format` based on the
@@ -593,8 +554,6 @@ Other C# types are represented in the generated OpenAPI document as shown in the
593
554
| object |_omitted_||
594
555
| dynamic |_omitted_||
595
556
596
-
:::moniker-end
597
-
598
557
### Use attributes to add metadata
599
558
600
559
ASP.NET uses metadata from attributes on class or record properties to set metadata on the corresponding properties of the generated schema.
@@ -675,13 +634,6 @@ An enum type without a [`[JsonConverter]`](xref:System.Text.Json.Serialization.
675
634
676
635
#### nullable
677
636
678
-
:::moniker range="< aspnetcore-10.0"
679
-
680
-
Properties defined as a nullable value or reference type have `nullable: true` in the generated schema. This is consistent with the default behavior of the <xref:System.Text.Json> deserializer, which accepts `null` as a valid value for a nullable property.
681
-
682
-
:::moniker-end
683
-
:::moniker range=">= aspnetcore-10.0"
684
-
685
637
Properties defined as a nullable value or reference type appear in the generated schema with a `type` keyword whose value is an array that includes `null` as one of the types. This is consistent with the default behavior of the <xref:System.Text.Json> deserializer, which accepts `null` as a valid value for a nullable property.
686
638
687
639
For example, a C# property defined as `string?` is represented in the generated schema as:
@@ -698,8 +650,6 @@ For example, a C# property defined as `string?` is represented in the generated
698
650
699
651
If the app is configured to produce OpenAPI v3.0 or OpenAPI v2 documents, nullable value or reference types have `nullable: true` in the generated schema because these OpenAPI versions do not allow the `type` field to be an array.
700
652
701
-
:::moniker-end
702
-
703
653
#### additionalProperties
704
654
705
655
Schemas are generated without an `additionalProperties` assertion by default, which implies the default of `true`. This is consistent with the default behavior of the <xref:System.Text.Json> deserializer, which silently ignores additional properties in a JSON object.
@@ -722,3 +672,9 @@ A schema transformer can be used to override any default metadata or add additio
0 commit comments