Skip to content

Commit 8929c2e

Browse files
committed
add content for complex data types
1 parent fd3c41c commit 8929c2e

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
title: "Complex data types"
3+
description: "Describe APIs with flexible schemas, optional properties, and multiple data formats using `oneOf`, `anyOf`, and `allOf` keywords"
4+
---
5+
6+
When your API accepts multiple data formats, has conditional fields, or uses inheritance patterns, OpenAPI's schema composition keywords help you document these flexible structures clearly. Using `oneOf`, `anyOf`, and `allOf`, you can describe APIs that handle different input types or combine multiple schemas into comprehensive data models.
7+
8+
## `oneOf`, `anyOf`, `allOf` keywords
9+
10+
For complex data types, OpenAPI provides keywords for combining schemas:
11+
12+
- `allOf`: Combines multiple schemas (like merging objects or extending a base schema). Functions like an "and" operator.
13+
- `anyOf`: Accepts data matching any of the provided schemas. Functions like an "or" operator.
14+
- `oneOf`: Accepts data matching exactly one of the provided schemas. Functions like an "exclusive-or" operator.
15+
16+
<Warning>Mintlify treats `oneOf` and `anyOf` identically. Most APIs work fine with `anyOf` since the practical difference is rarely important to users.</Warning>
17+
18+
For detailed specifications of these keywords see the [OpenAPI documentation](https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/).
19+
20+
<Info>The `not` keyword is not currently supported.</Info>
21+
22+
### Combining schemas with `allOf`
23+
24+
When you use `allOf`, Mintlify performs some preprocessing on your OpenAPI document to display complex combinations in a readable way. For example, when you combine two object schemas with `allOf`, Mintlify combines the properties of both into a single object. This becomes especially useful when leveraging OpenAPI's [reusable `components`](https://swagger.io/docs/specification/components/).
25+
26+
```yaml
27+
org_with_users:
28+
allOf:
29+
- $ref: '#/components/schemas/Org'
30+
- type: object
31+
properties:
32+
users:
33+
type: array
34+
description: An array containing all users in the organization
35+
...
36+
components:
37+
schemas:
38+
Org:
39+
type: object
40+
properties:
41+
id:
42+
type: string
43+
description: The ID of the organization
44+
```
45+
46+
<ParamField body="org_with_users" type="object">
47+
<Expandable>
48+
<ParamField body="id" type="string">
49+
The ID of the organization
50+
</ParamField>
51+
<ParamField body="users" type="object[]">
52+
An array containing all users in the organization
53+
</ParamField>
54+
</Expandable>
55+
</ParamField>
56+
57+
### Providing options with `oneOf` and `anyOf`
58+
59+
When you use `oneOf` or `anyOf`, Mintlify displays the options in a tabbed container. To give your options helpful names, specify a `title` field in each subschema. For example, here's how you might display two different types of delivery addresses:
60+
61+
```yaml
62+
delivery_address:
63+
oneOf:
64+
- title: StreetAddress
65+
type: object
66+
properties:
67+
address_line_1:
68+
type: string
69+
description: The street address of the recipient
70+
...
71+
- title: POBox
72+
type: object
73+
properties:
74+
box_number:
75+
type: string
76+
description: The number of the PO Box
77+
...
78+
```
79+
80+
<ParamField body="delivery_address" type="object">
81+
<div className="mt-4 rounded-xl border border-gray-100 px-4 pb-4 pt-2 dark:border-white/10">
82+
<Tabs>
83+
<Tab title="StreetAddress">
84+
<ParamField body="address_line_1" type="string">
85+
The street address of the residence
86+
</ParamField>
87+
</Tab>
88+
<Tab title="POBox">
89+
<ParamField body="box_number" type="string">
90+
The number of the PO Box
91+
</ParamField>
92+
</Tab>
93+
</Tabs>
94+
</div>
95+
</ParamField>

0 commit comments

Comments
 (0)