Add an OpenAPI specification file
To document your endpoints with OpenAPI, you need a valid OpenAPI document in either JSON or YAML format that follows the OpenAPI specification 3.0+. You can create API pages from a single or multiple OpenAPI documents.Describing your API
We recommend the following resources to learn about and construct your OpenAPI documents.- Swagger’s OpenAPI Guide to learn the OpenAPI syntax.
- The OpenAPI specification Markdown sources to reference details of the latest OpenAPI specification.
- Swagger Editor to edit, validate, and debug your OpenAPI document.
- The Mint CLI to validate your OpenAPI document with the command:
mint openapi-check <openapiFilenameOrUrl>
.
Swagger’s OpenAPI Guide is for OpenAPI v3.0, but nearly all of the information
is applicable to v3.1. For more information on the differences between v3.0
and v3.1, see Migrating from OpenAPI 3.0 to
3.1.0
in the OpenAPI blog.
Specifying the URL for your API
To enable Mintlify features like the API playground, add aservers
field to your OpenAPI document with your API’s base URL.
/users/{id}
or simply /
. The base URL defines where these paths should be appended. For more information on how to configure the servers
field, see API Server and Base Path in the OpenAPI documentation.
The API playground uses these server URLs to determine where to send requests. If you specify multiple servers, a dropdown will allow users to toggle between servers. If you do not specify a server, the API playground will use simple mode since it cannot send requests without a base URL.
If your API has endpoints that exist at different URLs, you can override the server field for a given path or operation.
Specifying authentication
To enable authentication in your API documentation and playground, configure thesecuritySchemes
and security
fields in your OpenAPI document. The API descriptions and API Playground will add authentication fields based on the security configurations in your OpenAPI document.
1
Define your authentication method.
Add a
securitySchemes
field to define how users authenticate.This example shows a configuration for bearer authentication.2
Apply authentication to your endpoints.
Add a
security
field to require authentication.- API Keys: For header, query, or cookie-based keys.
- Bearer: For JWT or OAuth tokens.
- Basic: For username and password.
x-mint
extension
The x-mint
extension is a custom OpenAPI extension that provides additional control over how your API documentation is generated and displayed.
Metadata
Override the default metadata for generated API pages by addingx-mint: metadata
to any operation. You can use any metadata field that would be valid in MDX
frontmatter except for openapi
:
Content
Add content before the auto-generated API documentation usingx-mint: content
:
content
extension supports all Mintlify MDX components and formatting.
Href
Change the URL of the endpoint page in your docs usingx-mint: href
:
x-mint: href
is present, the navigation entry will link directly to the specified URL instead of generating an API page.
MCP
Selectively expose endpoints as Model Context Protocol (MCP) tools by usingx-mint: mcp
. Only enable endpoints that are safe for public access through AI tools.
The MCP configuration for the endpoint.
Auto-populate API pages
Add anopenapi
field to any navigation element in your docs.json
to automatically generate pages for OpenAPI endpoints. You can control where these pages appear in your navigation structure, as dedicated API sections or with other pages.
The openapi
field accepts either a file path in your docs repo or a URL to a hosted OpenAPI document.
Generated endpoint pages have these default metadata values:
title
: The operation’ssummary
field, if present. If there is nosummary
, the title is generated from the HTTP method and endpoint.description
: The operation’sdescription
field, if present.version
: Theversion
value from the parent anchor or tab, if present.deprecated
: The operation’sdeprecated
field. Iftrue
, a deprecated label will appear next to the endpoint title in the side navigation and on the endpoint page.
To exclude specific endpoints from your auto-generated API pages, add the
x-hidden
property to the operation in your OpenAPI spec.
- Dedicated API sections: Reference OpenAPI specs in navigation elements for dedicated API sections.
- Selective endpoints: Reference specific endpoints in your navigation alongside other pages.
Dedicated API sections
Generate dedicated API sections by adding anopenapi
field to a navigation element and no other pages. All endpoints in the specification will be included:
The
directory
field is optional and specifies where generated API pages are
stored in your docs repo. If not specified, defaults to the api-reference
directory of your repo.Selective endpoints
When you want more control over where endpoints appear in your documentation, you can reference specific endpoints in your navigation. This approach allows you to generate pages for API endpoints alongside other content.Set a default OpenAPI spec
Configure a default OpenAPI specification for a navigation element. Then reference specific endpoints in thepages
field:
METHOD /path
will generate an API page for that endpoint using the default OpenAPI spec.
OpenAPI spec inheritance
OpenAPI specifications are inherited down the navigation hierarchy. Child navigation elements inherit their parent’s OpenAPI specification unless they define their own:Individual endpoints
Reference specific endpoints without setting a default OpenAPI specification by including the file path:Create MDX
files for API pages
For control over individual endpoint pages, create MDX
pages for each operation. This lets you customize page metadata, add content, omit certain operations, or reorder pages in your navigation at the page level.
See an example MDX OpenAPI page from MindsDB and how it appears in their live documentation.
Manually specify files
Create anMDX
page for each endpoint and specify which OpenAPI operation to display using the openapi
field in the frontmatter.
When you reference an OpenAPI operation this way, the name, description, parameters, responses, and API playground are automatically generated from your OpenAPI document.
If you have multiple OpenAPI files, include the file path in your reference to ensure Mintlify finds the correct OpenAPI document. If you have only one OpenAPI file, Mintlify will detect it automatically.
This approach works regardless of whether you have set a default OpenAPI spec
in your navigation. You can reference any endpoint from any OpenAPI spec by
including the file path in the frontmatter.
docs.json
.
The method and path must exactly match the definition in your OpenAPI
specification. If the endpoint doesn’t exist in the OpenAPI file, the page
will be empty.
Autogenerate MDX
files
Use our Mintlify scraper to autogenerate MDX
pages for large OpenAPI documents.
Your OpenAPI document must be valid or the files will not autogenerate.
- An
MDX
page for each operation in thepaths
field of your OpenAPI document. - If your OpenAPI document is version 3.1+, an
MDX
page for each operation in thewebhooks
field of your OpenAPI document. - An array of navigation entries that you can add to your
docs.json
.
1
Generate `MDX` files.
2
Specify an output folder.
-o
flag to specify a folder to populate the files into. If a folder is not specified, the files will populate in the working directory.Create MDX
files for OpenAPI schemas
You can create individual pages for any OpenAPI schema defined in an OpenAPI document’s components.schema
field:
Webhooks
Webhooks are HTTP callbacks that your API sends to notify external systems when events occur. Webhooks are supported in OpenAPI 3.1+ documents.Define webhooks in your OpenAPI specification
Add awebhooks
field to your OpenAPI document alongside the paths
field.
For more information on defining webhooks, see Webhooks in the OpenAPI documentation.
Reference webhooks in MDX files
When creating MDX pages for webhooks, usewebhook
instead of HTTP methods like GET
or POST
:
The webhook name must exactly match the key defined in your OpenAPI
specification’s
webhooks
field.