|
| 1 | +--- |
| 2 | +title: "Migrating MDX API pages to OpenAPI navigation" |
| 3 | +sidebarTitle: "Migrating from MDX" |
| 4 | +description: "Update from individual MDX endpoint pages to automated OpenAPI generation with flexible navigation" |
| 5 | +icon: "arrow-big-right-dash" |
| 6 | +--- |
| 7 | + |
| 8 | +If you are currently using individual `MDX` pages for your API endpoints, you can migrate to autogenerating pages from your OpenAPI specification while retaining the customizability of individual pages. |
| 9 | + |
| 10 | +You can define metadata and content for each endpoint in your OpenAPI specification and organize endpoints precisely where you want them in your navigation. |
| 11 | + |
| 12 | +Follow this migration guide to start building your API documentation from your OpenAPI specification with these benefits: |
| 13 | + |
| 14 | +- Automatic page generation from your OpenAPI spec |
| 15 | +- Flexible navigation options |
| 16 | +- Fewer files to maintain |
| 17 | +- Consistent API documentation format |
| 18 | + |
| 19 | +## Before: Individual MDX pages |
| 20 | + |
| 21 | +Previously, you created separate MDX files for each endpoint and referenced them in your navigation: |
| 22 | + |
| 23 | +```json |
| 24 | +{ |
| 25 | + "navigation": [ |
| 26 | + { |
| 27 | + "group": "API Reference", |
| 28 | + "pages": [ |
| 29 | + "api/get-users", |
| 30 | + "api/post-users", |
| 31 | + "api/delete-users" |
| 32 | + ] |
| 33 | + } |
| 34 | + ] |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +Each endpoint required its own MDX file with manual configuration and content. |
| 39 | + |
| 40 | +## After: OpenAPI navigation |
| 41 | + |
| 42 | +When you complete the migration, you will reference your OpenAPI specification directly in navigation and automatically generate endpoint pages: |
| 43 | + |
| 44 | +```json |
| 45 | +{ |
| 46 | + "navigation": [ |
| 47 | + { |
| 48 | + "group": "API Reference", |
| 49 | + "openapi": "openapi.json" |
| 50 | + } |
| 51 | + ] |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +Or selectively include specific endpoints: |
| 56 | + |
| 57 | +```json |
| 58 | +{ |
| 59 | + "navigation": [ |
| 60 | + { |
| 61 | + "group": "API Reference", |
| 62 | + "openapi": "openapi.json", |
| 63 | + "pages": [ |
| 64 | + "GET /users", |
| 65 | + "POST /users", |
| 66 | + "DELETE /users" |
| 67 | + ] |
| 68 | + } |
| 69 | + ] |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +## Migration steps |
| 74 | + |
| 75 | +<Steps> |
| 76 | + <Step title="Prepare your OpenAPI specification."> |
| 77 | + Ensure your OpenAPI specification is valid and includes all endpoints you want to document. |
| 78 | + |
| 79 | + For any endpoints that you want to customize the metadata or content, add the `x-mint` extension to the endpoint. See [x-mint extension](/api-playground/openapi-setup#x-mint-extension) for more details. |
| 80 | + |
| 81 | + For any endpoints that you want to exclude from your documentation, add the `x-hidden` extension to the endpoint. |
| 82 | + |
| 83 | + <Info> |
| 84 | + Validate your OpenAPI file using the [Swagger Editor](https://editor.swagger.io/) or [Mint CLI](https://www.npmjs.com/package/mint). |
| 85 | + </Info> |
| 86 | + </Step> |
| 87 | + |
| 88 | + <Step title="Update your navigation structure."> |
| 89 | + Replace `MDX` page references with OpenAPI endpoints in your `docs.json`. |
| 90 | + |
| 91 | + ```json |
| 92 | + { |
| 93 | + "navigation": { |
| 94 | + "openapi": "/path/to/openapi.json", |
| 95 | + "pages": [ |
| 96 | + "introduction", |
| 97 | + "GET /health", |
| 98 | + "quickstart", |
| 99 | + "POST /users", |
| 100 | + "GET /users/{id}", |
| 101 | + "advanced-features" |
| 102 | + ] |
| 103 | + } |
| 104 | + } |
| 105 | + ``` |
| 106 | + |
| 107 | + </Step> |
| 108 | + |
| 109 | + <Step title="Remove old MDX files."> |
| 110 | + After verifying your new navigation works correctly, remove the `MDX` endpoint files that you no longer need. |
| 111 | + </Step> |
| 112 | +</Steps> |
| 113 | + |
| 114 | +## Navigation patterns |
| 115 | + |
| 116 | +You can customize how your API documentation appears in your navigation. |
| 117 | + |
| 118 | +### Mixed content navigation |
| 119 | + |
| 120 | +Combine automatically generated API pages with other pages: |
| 121 | + |
| 122 | +```json |
| 123 | +{ |
| 124 | + "navigation": [ |
| 125 | + { |
| 126 | + "group": "API Reference", |
| 127 | + "openapi": "openapi.json", |
| 128 | + "pages": [ |
| 129 | + "api/overview", |
| 130 | + "GET /users", |
| 131 | + "POST /users", |
| 132 | + "api/authentication" |
| 133 | + ] |
| 134 | + } |
| 135 | + ] |
| 136 | +} |
| 137 | +``` |
| 138 | + |
| 139 | +### Multiple API versions |
| 140 | + |
| 141 | +Organize different API versions using tabs or groups: |
| 142 | + |
| 143 | +```json |
| 144 | +{ |
| 145 | + "navigation": { |
| 146 | + "tabs": [ |
| 147 | + { |
| 148 | + "tab": "API v1", |
| 149 | + "openapi": "specs/v1.json" |
| 150 | + }, |
| 151 | + { |
| 152 | + "tab": "API v2", |
| 153 | + "openapi": "specs/v2.json" |
| 154 | + } |
| 155 | + ] |
| 156 | + } |
| 157 | +} |
| 158 | +``` |
| 159 | + |
| 160 | +## When to use individual `MDX` pages |
| 161 | + |
| 162 | +Consider keeping individual `MDX` pages when you need: |
| 163 | + |
| 164 | +- Extensive custom content per endpoint like React components or lengthy examples |
| 165 | +- Unique page layouts |
| 166 | +- Experimental documentation approaches for specific endpoints |
| 167 | + |
| 168 | +For most use cases, OpenAPI navigation provides better maintainability and consistency. |
0 commit comments