@medusajs/medusa-oas-cli is a CLI for generating and processing the OpenAPI Specifications (OAS) of the Medusa Store and Admin APIs. Use its oas command to produce an OAS file for Medusa's API routes (optionally merged with OAS JSDoc from your own routes), and its docs command to prepare an OAS file for Redocly's API documentation tools. The Medusa monorepo uses it to build the API reference.
At a glance
|
|
| Package |
@medusajs/medusa-oas-cli |
| Type |
Internal tooling |
| Binary |
medusa-oas |
Installation
npm install --save-dev @medusajs/medusa-oas-cli
Usage
Generate the Store API OAS, merged with the OAS JSDoc in your project's src directory:
npx medusa-oas oas --type store --paths ./src --out-dir ./oas
Preview it with Redocly:
npx medusa-oas docs --src-file ./oas/store.oas.json --preview
In the Medusa monorepo, run it with yarn medusa-oas <command> from the repository root.
Commands
oas
Generates <type>.oas.json (admin.oas.json, store.oas.json, or combined.oas.json). By default, it starts from the published OAS of the installed @medusajs/medusa version at https://docs.medusajs.com/api/download/<type>?version=<version>, falling back to the latest published OAS if that version has none; with --local, it builds the OAS from the JSDoc in the installed @medusajs/medusa package. Invalid OAS throws an error and no file is written, unless --force is passed.
| Option |
Description |
Default |
-t, --type <type> |
Required. API to generate: admin, store, or combined (admin and store merged). |
- |
-o, --out-dir <outDir> |
Output directory. Created if missing. |
Current directory |
-p, --paths <paths...> |
Additional directories to crawl for OAS JSDoc. Their paths and schemas are merged into the output. |
- |
-b, --base <base> |
Custom base OAS file. Its paths, tags, and components are merged; other properties override the base. |
- |
-D, --dry-run |
Validate without writing files. |
false |
-F, --force |
Ignore OAS validation errors and write the files. |
false |
--local |
Build from the local @medusajs/medusa JSDoc instead of the published OAS. |
false |
docs
Sanitizes an OAS file for Redocly's API documentation viewer and writes it as YAML.
| Option |
Description |
Default |
-s, --src-file <srcFile> |
Required. Path to the source OAS file. |
- |
-o, --out-dir <outDir> |
Output directory. Created if missing. |
Current directory |
--config <config> |
Redocly config file merged with the default configuration. |
- |
-D, --dry-run |
Sanitize without writing files. |
false |
--clean |
Delete the output directory's contents first. |
false |
--split |
Write a multi-file structure (redocly split). |
false |
--preview |
Open a browser preview (redocly preview-docs). Doesn't write files. |
false |
--html |
Generate a static HTML file (redocly build-docs). |
false |
--main-file-name <mainFileName> |
Name of the main YAML file. |
openapi.yaml |