Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions pages/learn/json-schema-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,44 @@ In this page, you will find examples illustrating different use cases to help yo
- [Movie](#movie)
- [User profile](#user-profile)

- [Choosing between oneOf, anyOf, and allOf](#choosing-between-oneof-anyof-and-allof)
## Choosing between oneOf, anyOf, and allOf

When combining schemas, `oneOf`, `anyOf`, and `allOf` behave differently.
The examples below show common real-world scenarios and pitfalls.

### anyOf — at least one schema must match

```json
{
"anyOf": [
{ "type": "string" },
{ "type": "number" }
]
}
```

### oneOf — exactly one schema must match

```json
{
"oneOf": [
{ "type": "number", "minimum": 0 },
{ "type": "number", "maximum": 100 }
]
}
```

### allOf — all schemas must match

```json
{
"allOf": [
{ "type": "string" },
{ "minLength": 5 }
]
}
```

## Address

Expand Down
Loading