Set Up an API Reference
Add an OpenAPI spec to your Mordoc project and see generated API pages in minutes.
This page takes you from an OpenAPI file to a running API reference.
You need an existing Mordoc project. If you do not have one, start with Create a Project.
Step 1: Add the spec
Copy your OpenAPI file into the api/specs/ folder. Create the folders if they do not exist.
api/specs/rings.yamlNot sure the spec is ready? See Prepare Your Spec.
Step 2: Register the spec
Create config/api.yaml and give the spec an id and its file name:
- id: rings
spec: rings.yamlThe id names the API in folders and URLs. Use letters, digits, hyphens, and underscores only. See API Registry for every option.
Step 3: Link operations in the sidebar
Add the operations to your sidebar with operation: and the spec's operationId:
- label: Rings API
expanded: true
children:
- operation: forgeRing
- operation: getRingSee Link Operations in Navigation for groups, labels, and guide pages.
Step 4: Run the site
npm run devOpen the site and click one of the new sidebar links.
Where the pages live
Each operation gets a page at /api/<id>/<operation-slug>. The slug is the operationId in kebab-case:
operationId | Page URL |
|---|---|
forgeRing | /api/rings/forge-ring |
getRing | /api/rings/get-ring |
You can change the /api/<id> part with routePrefix. See API Registry.
The Retrieve a ring page was generated from a spec with no extra work.
More than one spec
Add one entry per spec. Each spec gets its own id, its own URL prefix, and its own enrichment folder:
- id: fellowship
spec: fellowship.yaml
- id: rings
spec: rings.yaml