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/include-metadata.md
+4-25Lines changed: 4 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -314,8 +314,6 @@ app.MapGet("/todos",
314
314
async (TodoDbdb) =>awaitdb.Todos.ToListAsync());
315
315
```
316
316
317
-
:::moniker range=">= aspnetcore-10.0"
318
-
319
317
[`[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
318
321
319
```csharp
@@ -327,8 +325,6 @@ app.MapGet("/todos/{id}",
327
325
async (intid, TodoDbdb) =>/* Code here */);
328
326
```
329
327
330
-
:::moniker-end
331
-
332
328
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
329
334
330
```csharp
@@ -398,8 +394,6 @@ Only one [`[Produces]`](xref:Microsoft.AspNetCore.Mvc.ProducesAttribute) or <xre
398
394
399
395
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
396
401
-
:::moniker range=">= aspnetcore-10.0"
402
-
403
397
[`[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
398
405
399
```csharp
@@ -412,8 +406,6 @@ All of the above attributes can be applied to individual action methods or to th
* The status code for the response defaults to 200.
@@ -493,8 +485,6 @@ of the property in the schema.
493
485
494
486
### type and format
495
487
496
-
:::moniker range="< aspnetcore-10.0"
497
-
498
488
The JSON Schema library maps standard C# types to OpenAPI `type` and `format` as follows:
499
489
500
490
| C# Type | OpenAPI `type`| OpenAPI `format`|
@@ -522,10 +512,6 @@ Note that object and dynamic types have _no_ type defined in the OpenAPI because
522
512
523
513
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
514
525
-
:::moniker-end
526
-
527
-
:::moniker range=">= aspnetcore-10.0"
528
-
529
515
#### Numeric types
530
516
531
517
The JSON Schema library maps standard C# numeric types to OpenAPI `type` and `format` based on the
@@ -593,8 +579,6 @@ Other C# types are represented in the generated OpenAPI document as shown in the
593
579
| object |_omitted_||
594
580
| dynamic |_omitted_||
595
581
596
-
:::moniker-end
597
-
598
582
### Use attributes to add metadata
599
583
600
584
ASP.NET uses metadata from attributes on class or record properties to set metadata on the corresponding properties of the generated schema.
@@ -675,13 +659,6 @@ An enum type without a [`[JsonConverter]`](xref:System.Text.Json.Serialization.
675
659
676
660
#### nullable
677
661
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
662
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
663
687
664
For example, a C# property defined as `string?` is represented in the generated schema as:
@@ -698,8 +675,6 @@ For example, a C# property defined as `string?` is represented in the generated
698
675
699
676
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
677
701
-
:::moniker-end
702
-
703
678
#### additionalProperties
704
679
705
680
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 +697,7 @@ A schema transformer can be used to override any default metadata or add additio
0 commit comments