Advanced Features
Learn how to use powerful OpenAPI features
OpenAPI 3 offers several advanced ways to describe complex APIs. Let’s explore how to use these features with Mintlify.
oneOf
, anyOf
, allOf
OpenAPI provides three special keywords to help you work with complex data types: oneOf
, anyOf
, and allOf
. These keywords let you combine different data structures. Here’s what each one does:
oneOf
: Means “pick exactly one option from the list”anyOf
: Means “pick one or more options from the list”allOf
: Means “include everything from all options”
oneOf
and anyOf
the same way. We’ve found that most developers use these terms interchangeably, and the difference rarely matters to users.not
keyword at this time.Using allOf
to Combine Data Structures
Mintlify makes it easy to read combined data structures. For example, when you join two objects with allOf
, we show all their properties together in one place. This is especially helpful when you’re using reusable components in OpenAPI.
Offering Choices with oneOf
and anyOf
When you use oneOf
or anyOf
, Mintlify shows the options in tabs. To make these tabs easy to understand, give each option a clear title. Here’s an example showing two different ways to write a delivery address:
x-codeSamples
If your users work with your API through an SDK instead of direct API calls, you can add example code to your documentation. Use the x-codeSamples
feature to add these examples. You can add this to any API endpoint, and it needs:
The programming language used in the example
A name for the example (helpful when you have multiple examples)
The actual code for the example
Here’s an example from a plant tracking app that has both a command-line tool and a JavaScript SDK: