Skip to content

Commit 90c3421

Browse files
committed
Update doc on nullable properties
1 parent a4dcbd4 commit 90c3421

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

aspnetcore/fundamentals/openapi/include-metadata.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,32 @@ An enum type without a [`[JsonConverter]`](xref:System.Text.Json.Serialization.
665665

666666
#### nullable
667667

668+
:::moniker range="< aspnetcore-10.0"
669+
668670
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.
669671

672+
:::moniker-end
673+
674+
:::moniker range=">= aspnetcore-10.0"
675+
676+
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.
677+
678+
For example, a C# property defined as `string?` is represented in the generated schema as:
679+
680+
```json
681+
"nullableString": {
682+
"description": "A property defined as string?",
683+
"type": [
684+
"null",
685+
"string"
686+
]
687+
},
688+
```
689+
690+
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.
691+
692+
:::moniker-end
693+
670694
#### additionalProperties
671695

672696
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

Comments
 (0)