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
+98
Original file line number
Diff line number
Diff line change
@@ -493,6 +493,8 @@ of the property in the schema.
493
493
494
494
### type and format
495
495
496
+
:::moniker range="< aspnetcore-10.0"
497
+
496
498
The JSON Schema library maps standard C# types to OpenAPI `type` and `format` as follows:
497
499
498
500
| C# Type | OpenAPI `type`| OpenAPI `format`|
@@ -520,6 +522,79 @@ Note that object and dynamic types have _no_ type defined in the OpenAPI because
520
522
521
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`.
522
524
525
+
:::moniker-end
526
+
527
+
:::moniker range=">= aspnetcore-10.0"
528
+
529
+
#### Numeric types
530
+
531
+
The JSON Schema library maps standard C# numeric types to OpenAPI `type` and `format` based on the
532
+
<xref:System.Text.Json.JsonSerializerOptions.NumberHandling> property of the <xref:System.Text.Json.JsonSerializerOptions>
533
+
used in the app. In ASP.NET Core Web API apps, the default value of this property is `JsonNumberHandling.AllowReadingFromString`.
534
+
535
+
When the <xref:System.Text.Json.JsonSerializerOptions.NumberHandling> property is set to `JsonNumberHandling.AllowReadingFromString`, the numeric types are mapped as follows:
536
+
537
+
| C# Type | OpenAPI `type`| OpenAPI `format`| Other assertions |
If the app is configured to produce OpenAPI 3.0 or OpenAPI v2 documents, where the `type` field cannot have an array value, the `type` field is dropped.
558
+
559
+
When the <xref:System.Text.Json.JsonSerializerOptions.NumberHandling> property is set to `JsonNumberHandling.Strict`, the numeric types are mapped as follows:
ASP.NET uses metadata from attributes on class or record properties to set metadata on the corresponding properties of the generated schema.
@@ -600,8 +675,31 @@ An enum type without a [`[JsonConverter]`](xref:System.Text.Json.Serialization.
600
675
601
676
#### nullable
602
677
678
+
:::moniker range="< aspnetcore-10.0"
679
+
603
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.
604
681
682
+
:::moniker-end
683
+
:::moniker range=">= aspnetcore-10.0"
684
+
685
+
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
+
687
+
For example, a C# property defined as `string?` is represented in the generated schema as:
688
+
689
+
```json
690
+
"nullableString": {
691
+
"description": "A property defined as string?",
692
+
"type": [
693
+
"null",
694
+
"string"
695
+
]
696
+
},
697
+
```
698
+
699
+
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
+
701
+
:::moniker-end
702
+
605
703
#### additionalProperties
606
704
607
705
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.
0 commit comments