Skip to content

Commit d1f57a2

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

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

aspnetcore/fundamentals/openapi/include-metadata.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,31 @@ 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+
:::moniker range=">= aspnetcore-10.0"
674+
675+
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.
676+
677+
For example, a C# property defined as `string?` is represented in the generated schema as:
678+
679+
```json
680+
"nullableString": {
681+
"description": "A property defined as string?",
682+
"type": [
683+
"null",
684+
"string"
685+
]
686+
},
687+
```
688+
689+
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.
690+
691+
::moniker-end
692+
670693
#### additionalProperties
671694

672695
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)