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+.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.
Auto-populate API pages
You can add anopenapi field to any navigation element in your docs.json to auto-populate your docs with a page for each specified endpoint. The openapi field can contain the path to an OpenAPI document in your docs repo or the URL of a hosted OpenAPI document.
The metadata for the generated pages will have the following default values:
title: Thesummaryfield from the OpenAPI operation, if present. Otherwise a title generated from the HTTP method and endpoint.description: Thedescriptionfield from the OpenAPI operation, if present.version: Theversionvalue from the anchor or tab, if present.deprecated: Thedeprecatedfield from the OpenAPI operation, if present. Iftrue, a deprecated label will appear next to the endpoint title in the side navigation and on the endpoint page.
If you have some endpoints in your OpenAPI schema that you want to exclude from your auto-populated API pages, add the x-hidden property to the endpoint.
Example with navigation tabs
Example with navigation groups
The directory field is optional. If not specified, the files will be placed in the
api-reference directory of the docs repo.Create MDX files for API pages
If you want to customize the page metadata, add additional content, omit certain OpenAPI operations, or reorder OpenAPI pages in your navigation, you can create MDX pages for each operation. 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.
If you want to reference an external OpenAPI file, add the file’s URL to your 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.For webhooks, use
webhook (case insensitive) instead of the HTTP method (like GET or POST) in your reference.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
MDXpage for each operation in thepathsfield of your OpenAPI document. - If your OpenAPI document is version 3.1+, an
MDXpage for each operation in thewebhooksfield 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: