You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: 'Generate docs pages for your API endpoints using MDX'
3
+
description: 'Configure API endpoints with MDX'
4
4
---
5
5
6
-
Mintlify allows you to define your API endpoints using a combination of `mint.json` configuration, MDX metadata fields, and the `<ParamFields />` component. From the defined endpoints, we generate an API playground, request examples, and response examples.
6
+
Set up your API documentation using `mint.json` configurationand MDX files. This generates an interactive API playground with request/response examples.
7
7
8
8
<Steps>
9
-
<Steptitle="Configure your API">
10
-
In your `mint.json` file, define your base URL and auth method:
9
+
<Steptitle="Set up mint.json">
10
+
Add your API configuration to `mint.json`:
11
11
12
12
```json
13
13
{
14
14
"api": {
15
-
"baseUrl": "https://mintlify.com/api",// string array for multiple base URLs
If you would not like to show an API playground, you don't need to include auth types. Hide the playground with the following field:
24
-
23
+
To hide the API playground, use:
25
24
```json
26
25
{
27
26
"api": {
@@ -32,12 +31,11 @@ Mintlify allows you to define your API endpoints using a combination of `mint.js
32
31
}
33
32
```
34
33
35
-
Find a full list of API configurations [here](/settings/global#api-configurations).
34
+
See all API options in our [configuration guide](/settings/global#api-configurations).
36
35
</Step>
37
36
38
-
<Steptitle="Create your endpoint pages">
39
-
40
-
Each API endpoint page should have a corresponding MDX file. At the top of each file, define:
37
+
<Steptitle="Create endpoint pages">
38
+
For each endpoint, create an MDX file with:
41
39
42
40
```md
43
41
---
@@ -46,20 +44,17 @@ Mintlify allows you to define your API endpoints using a combination of `mint.js
46
44
---
47
45
```
48
46
49
-
You can specify path parameters by adding the parameter name to the path, wrapped with `{}`:
50
-
47
+
For path parameters, use `{}`:
51
48
```bash
52
49
https://api.example.com/v1/endpoint/{userId}
53
50
```
54
51
55
52
<Note>
56
-
57
-
If you have `baseUrl` configured in [mint.json](/settings/global), you can use relative paths like `/v1/endpoint`.
58
-
53
+
With `baseUrl` configured, you can use relative paths like `/v1/endpoint`
59
54
</Note>
60
55
</Step>
61
56
62
-
<Steptitle="Add your endpoints to your docs">
63
-
Add your endpoint pages to the sidebar by adding the paths to the `navigation` field in your `mint.json`. Learn more about structuring your docs [here](/settings/navigation).
57
+
<Steptitle="Add to navigation">
58
+
Add your endpoint pages to the `navigation` field in `mint.json`. [Learn more](/settings/navigation)
description: "Reference OpenAPI endpoints in your docs pages"
4
4
---
5
5
6
-
## Add an OpenAPI specification file
6
+
## Quick Setup
7
7
8
-
To describe your endpoints with OpenAPI, make sure you have a valid OpenAPI
9
-
document in either JSON or YAML format that follows the
10
-
[OpenAPI specification](https://swagger.io/specification/). Your document must
11
-
follow OpenAPI specification 3.0+.
8
+
1. Have a valid OpenAPI 3.0+ spec file (JSON or YAML)
9
+
2. Add the `openapi` field to your `mint.json`:
12
10
13
-
## Auto-populate API pages
14
-
15
-
The fastest way to get started with OpenAPI is to add an `openapi` field to a tab or anchor in the `mint.json`. This field can contain either the path to an OpenAPI document in your docs repo, or the URL of a hosted OpenAPI document. Mintlify will automatically generate a page for each OpenAPI operation and place them in the tab/anchor.
16
-
17
-
**Example with Anchors:**
18
-
19
-
```json {5}
11
+
```json
20
12
{
21
13
"anchors": [
22
14
{
23
15
"name": "API Reference",
24
-
"openapi": "/path/to/openapi.json",
25
-
"url": "api-reference",
26
-
"icon": "square-terminal"
16
+
"openapi": "/path/to/openapi.json", // Local file path or URL
<Tip>To validate your OpenAPI spec, you can use this command: <br/>`mintlify openapi-check <openapiFilenameOrUrl>`</Tip>
51
-
52
-
53
-
When using this option, the metadata for the generated pages will have the following default values:
54
-
55
-
*`title`: The `summary` field from the OpenAPI operation, if present. Otherwise a title generated from the HTTP method and endpoint.
56
-
57
-
*`description`: The `description` field from the OpenAPI operation, if present.
58
-
59
-
*`version`: The `version` value from the anchor or tab, if present.
60
-
61
-
There are some scenarios in which the default behavior isn't sufficient. If you need more customizability, you can create an MDX page for your OpenAPI operation, and modify it just like any other MDX page.
62
-
63
-
## Create MDX files for API pages
64
-
65
-
If you want to customize the page metadata, add additional content, omit certain OpenAPI operations, or reorder OpenAPI pages in your navigation, you'll need an MDX page for each operation. Here is [an example MDX OpenAPI page](https://github.com/elevenlabs/elevenlabs-docs/blob/e5e267c97b8d1e4c21db1dcdb8b005eb1dfed7da/api-reference/speech-to-speech.mdx?plain=1#L2) from [Elevenlabs](https://elevenlabs.io/docs/api-reference/speech-to-speech). 
That's it! Mintlify will auto-generate API pages for each endpoint.
68
24
69
-
### Autogenerate files
25
+
<Tip>Validate your spec with: `mintlify openapi-check <openapiFilenameOrUrl>`</Tip>
70
26
71
-
For large OpenAPI documents, creating one MDX page for each OpenAPI operation can be a lot of work. To make it easier, we created a local OpenAPI page scraper.
Learn more about our scraping package [here](https://www.npmjs.com/package/@mintlify/scraping).
89
-
90
-
The scraper will output an array of
91
-
[Navigation entries](/settings/global#structure) containing your OpenAPI MDX
92
-
files. You can either append these entries to your existing Navigation, or
93
-
reorder and add the files to your navigation manually.
94
-
95
-
<Note>
96
-
If your OpenAPI document is invalid, the files will not autogenerate.
97
-
</Note>
98
-
99
-
### Manually specify files
100
-
101
-
You can always create an MDX page manually, and reference the OpenAPI operation in the page's metadata using the `openapi` field.
102
-
103
-
<Snippetfile="api-playground/openapi.mdx" />
104
-
105
-
By using the OpenAPI reference, the name, description, parameters, responses,
106
-
and the API playground will be automatically generated from the OpenAPI document.
107
-
108
-
If you have multiple OpenAPI files, include the path to the OpenAPI file to ensure Mintlify finds the correct OpenAPI document. This is not required if you have
109
-
only one OpenAPI file - it will automatically detect your OpenAPI file.
110
-
111
-
<CodeGroup>
112
-
```md Example
113
-
---
114
-
title: "Get users"
115
-
openapi: "/path/to/openapi-1.json GET /users"
116
-
---
117
-
```
118
-
119
-
```md Format
120
-
---
121
-
title: "title of the page"
122
-
openapi: openapi-file-path method path
123
-
---
124
-
```
125
-
</CodeGroup>
126
-
127
-
<br />
128
-
129
-
<Note>
130
-
The method and path must match the method and path specified in the OpenAPI
131
-
document exactly. If the endpoint doesn't exist in the OpenAPI file,
132
-
the page will be empty.
133
-
</Note>
134
-
135
-
## Create MDX files for OpenAPI schemas
136
-
137
-
Mintlify also allows you to create individual pages for any OpenAPI schema
138
-
defined in an OpenAPI document's `components.schemas` field:
Copy file name to clipboardExpand all lines: api-playground/openapi/writing-openapi.mdx
+16-15Lines changed: 16 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,28 +5,29 @@ description: "Use OpenAPI features to enhance your Mintlify docs"
5
5
6
6
## Describing your API
7
7
8
-
There are many great tools online for learning about and constructing OpenAPI documents. Here are our favorites:
9
-
-[Swagger's OpenAPI Guide](https://swagger.io/docs/specification/about/)for familiarizing yourself with the OpenAPI syntax
10
-
-[OpenAPI v3.1.0 Specification](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md)for all the details about the newest OpenAPI specification
11
-
-[Swagger & OpenAPI Validator](https://apitools.dev/swagger-parser/online/)for debugging your OpenAPI document
12
-
-[Swagger's Editor](https://editor.swagger.io/)for seeing examples in action
8
+
Need help writing OpenAPI docs? Here are essential resources:
-[OpenAPI v3.1.0 Spec](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md)- Official documentation
11
+
-[Validator](https://apitools.dev/swagger-parser/online/)- Debug your OpenAPI docs
12
+
-[Swagger Editor](https://editor.swagger.io/)- See live examples
13
13
14
14
<Note>
15
-
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, check out [OpenAPI's blog post](https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0).
15
+
Most examples use OpenAPI v3.0, but they work with v3.1. See the key differences [here](https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0).
16
16
</Note>
17
17
18
-
## Specifying the URL for your API
18
+
## Base URLs
19
19
20
-
In an OpenAPI document, different API endpoints are specified by their paths, like `/users/{id}`, or maybe simply `/`. To specify the base URL to which these paths should be appended, OpenAPI provides the `servers` field. This field is necessary to use some Mintlify features like the API Playground. Read how to configure the `servers` field in the [Swagger documentation](https://swagger.io/docs/specification/api-host-and-base-path/).
20
+
Set your API's base URL using the `servers` field. This enables features like the API Playground. Multiple servers will show as a dropdown in the playground. Without a server URL, the playground runs in simple mode.
21
21
22
-
The API Playground will use these server URLs to determine where to send requests. If multiple servers are specified, a dropdown will appear to allow toggling between servers. If no server is supplied, the API Playground will use simple mode, as there is no way to send a request.
22
+
Need different URLs for specific endpoints? You can override the server URL at the path or operation level.
23
23
24
-
If different endpoints within your API exist at different URLs, you can [override the server field](https://swagger.io/docs/specification/api-host-and-base-path/#:~:text=%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%2D%20southeastasia-,Overriding%20Servers,-The%20global%20servers) for a given path or operation.
24
+
## Authentication
25
25
26
-
## Specifying authentication
26
+
Configure API authentication using `securitySchemes` and `security` fields. OpenAPI supports:
27
+
- Basic auth
28
+
- Bearer tokens
29
+
- API keys
27
30
28
-
Nearly all APIs require some method of authentication. OpenAPI provides the `securitySchemes` field for defining the methods of authentication used throughout your API, with simple configuration for the most common authentication types - [Basic](https://swagger.io/docs/specification/authentication/basic-authentication/), [Bearer](https://swagger.io/docs/specification/authentication/bearer-authentication/), and [API Keys](https://swagger.io/docs/specification/authentication/api-keys/). To apply these authentication methods to your endpoints, OpenAPI uses the `security` field. The syntax for defining and applying authentication is a bit unintuitive, so definitely check out [Swagger's documentation and examples](https://swagger.io/docs/specification/authentication/) on the topic.
31
+
The API Playground automatically adds auth fields based on your security config. You can set different auth methods for specific endpoints by overriding the security field at the operation level.
29
32
30
-
The API descriptions and API Playground will add authentication fields based on the security configurations in your OpenAPI document.
31
-
32
-
If different endpoints within your API require different methods of authentication, you can [override the security field](https://swagger.io/docs/specification/authentication/#:~:text=you%20can%20apply%20them%20to%20the%20whole%20API%20or%20individual%20operations%20by%20adding%20the%20security%20section%20on%20the%20root%20level%20or%20operation%20level%2C%20respectively.) for a given operation.
33
+
Check out [Swagger's auth docs](https://swagger.io/docs/specification/authentication/) for examples.
0 commit comments