Markdown for API Documentation: OpenAPI, Stoplight, and the Docs-as-Code Stack
API documentation sits at the intersection of technical writing, software development, and developer experience. It’s also one of the areas where Markdown has quietly become essential — often in ways that aren’t obvious until you’re knee-deep in an OpenAPI spec or fighting a Stoplight rendering issue.
This guide covers where Markdown appears in API documentation, how the major platforms handle it, how to set up a docs-as-code workflow, and what to watch out for when writing descriptions that survive the journey from spec to rendered docs.
Where Markdown Lives in an OpenAPI Spec
If you’re working with OpenAPI (formerly Swagger), Markdown appears in several places:
Description fields are the most common. Nearly every object in the OpenAPI spec accepts a description field, and these support CommonMark Markdown:
info:
title: Payments API
version: "2.0"
description: |
The **Payments API** lets you create, capture, and refund charges.
## Authentication
All requests require a Bearer token in the `Authorization` header.
Rate limits apply: 100 requests/second per API key.
The description field on paths, operations, parameters, request bodies, and response schemas all support Markdown:
paths:
/charges:
post:
summary: Create a charge
description: |
Creates a new charge. The `amount` is in the **smallest currency unit**
(e.g., cents for USD, pence for GBP).
See [currency codes](/docs/currencies) for a full list.
parameters:
- name: idempotency_key
in: header
description: |
A unique key to safely retry requests. If you send the same key twice,
the API returns the original response rather than creating a duplicate.
Recommended for all `POST` requests.
Markdown guide files alongside the spec are the second major use case. Most teams write long-form content — tutorials, quickstart guides, authentication flows — as .md files that live in the same repository as openapi.yaml, versioned and reviewed together.
Changelog files are almost always Markdown. Your CHANGELOG.md lives in git alongside the spec and gets rendered by whatever platform you use for documentation.
The API Documentation Platforms Compared
Most teams don’t render OpenAPI specs manually — they use a platform that reads the spec and generates documentation. These platforms differ significantly in how they handle Markdown.
| Platform | Markdown in descriptions | Custom Markdown pages | Self-hostable | Pricing model |
|---|---|---|---|---|
| Redocly | Full CommonMark + extensions | Yes (docs-as-code) | Yes | Open-source CLI; hosted plans |
| Stoplight | Full CommonMark | Yes (separate .md files) |
Limited | Freemium SaaS |
| Scalar | Full CommonMark | Yes | Yes (open-source) | Open-source; hosted option |
| Readme.io | CommonMark + custom blocks | Yes (guides section) | No | Commercial SaaS |
| Swagger UI | Limited (sanitized HTML) | No (spec only) | Yes | Open-source |
| RapiDoc | CommonMark | No (spec only) | Yes | Open-source |
Redocly is the go-to choice for teams who want full docs-as-code. You write OpenAPI + Markdown files, run redocly build-docs, and get a self-hosted documentation site. Their @redocly/cli also lints your OpenAPI spec for correctness, consistency, and style. Markdown support is robust: admonitions (callouts), tabs, code blocks with syntax highlighting, and cross-references between guides and reference docs.
Stoplight Studio is the most popular visual editor for OpenAPI. It renders Markdown in description fields faithfully and lets you write standalone Markdown pages that appear alongside the generated reference docs. The tradeoff: the visual editor can sometimes mangle complex Markdown in descriptions — always verify in preview mode before committing.
Scalar is newer and gaining momentum fast. It’s fully open-source, renders OpenAPI specs with a modern, clean UI, and handles CommonMark properly in all description fields. Worth considering for teams who want something that looks great without vendor lock-in.
Readme.io is the commercial choice for teams that want a hosted developer portal with analytics, user authentication for private docs, and API key management built in. Their Markdown support includes custom callout blocks and interactive example makers. The tradeoff: more lock-in than the open-source alternatives, and the pricing climbs quickly.
Swagger UI is the original and still widely deployed — many teams use it for internal reference or expose it directly from their API. Its Markdown support is limited, though: descriptions pass through a sanitized HTML pipeline, and complex Markdown elements don’t always behave as expected. Stick to basic formatting (bold, italic, inline code, links) if Swagger UI is your target.
Setting Up Docs-as-Code for API Documentation
The docs-as-code approach treats documentation like code: stored in git, reviewed in pull requests, deployed through CI/CD. For API docs, this means your repository looks something like:
api-docs/
├── openapi.yaml
├── docs/
│ ├── getting-started.md
│ ├── authentication.md
│ ├── rate-limits.md
│ └── changelog.md
├── redocly.yaml
└── .github/
└── workflows/
└── docs.yml
A minimal GitHub Actions workflow with Redocly:
name: API Docs
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
lint-and-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Redocly CLI
run: npm install -g @redocly/cli
- name: Lint OpenAPI spec
run: redocly lint openapi.yaml
- name: Build docs
run: redocly build-docs openapi.yaml --output dist/
- name: Deploy to GitHub Pages
if: github.ref == 'refs/heads/main'
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: dist/
The redocly lint step catches spec errors and missing descriptions before they reach production. For Markdown files, adding markdownlint to the same workflow catches style issues in your guide files — the same rules you’d run locally with our Markdown Linter.
Writing Good Markdown API Descriptions
The descriptions in your OpenAPI spec are often the first thing a developer reads about an endpoint. A few principles that make a meaningful difference:
Lead with the “what”, not the “how”. The operation name already tells you what it does; the description should explain when to use it and what to watch for.
Instead of:
description: Creates a user in the database.
Write:
description: |
Creates a new user account. Returns the created user object including the generated `id`.
**Rate limit:** 10 requests/minute per IP. Creating users in bulk? Use the
[batch import endpoint](/reference/users/import) instead.
Always show the unit, not just the type. For numeric fields, clarify what the number represents:
parameters:
- name: amount
description: |
The charge amount in the **smallest currency unit** for the given currency.
For USD: `100` = $1.00. For JPY (zero-decimal): `100` = ¥100.
Use code fences for examples. Most platforms (Redocly, Stoplight, Scalar) syntax-highlight fenced code blocks in description fields:
description: |
Include a unique idempotency key on every `POST` request:
```
X-Idempotency-Key: 550e8400-e29b-41d4-a716-446655440000
```
Keys expire after 24 hours. Reusing an expired key creates a new request.
Note the nested code fences here — a triple-backtick block inside a YAML string. Most OpenAPI renderers handle this correctly; Swagger UI is the common exception.
Link between operations. Relative links ([see also](/reference/refunds)) connect related endpoints and keep users in the docs. Most platforms render these as proper links; the Markdown source stays readable in the raw spec.
What Doesn’t Work Well
Complex tables in Swagger UI. Swagger UI renders Markdown tables inconsistently — the cell contents are sometimes sanitized in ways that strip inline formatting. Test tables in your target platform before relying on them for critical information.
Nested code blocks. Showing a code block example that contains another code block (meta-documentation) trips up some renderers. If you need to demonstrate nested fences, use an indented code block (4 spaces) for the inner example instead of triple backticks.
HTML in descriptions. OpenAPI allows HTML in description fields, and CommonMark allows inline HTML in Markdown. But documentation platforms sanitize it — <script>, <iframe>, <style>, and sometimes even <details> get stripped. Don’t rely on raw HTML for anything load-bearing.
Relative paths across platforms. A link like [authentication](/docs/authentication) works perfectly when self-hosting with Redocly but breaks in Stoplight if your docs live at a different base path. Always test cross-links in the actual deployed environment.
Checking Your Markdown Before It Ships
Before committing an updated OpenAPI spec or guide file:
- Run the platform’s linter.
redocly lint openapi.yamlcatches spec-level issues;markdownlintcatches Markdown style problems in your.mdfiles. - Preview in the target platform. What looks right in VS Code may render differently in Stoplight or Readme.io — especially for tables and nested code blocks.
- Check every code block manually. Unterminated fences are the most common rendering failure. They can silently swallow everything below them.
- Verify all cross-links. Use a link-checker in CI for large doc sets; manual spot-checking for smaller ones.
For catching Markdown style issues locally before pushing, the Markdown Linter at Markdown Tools checks heading hierarchy, bare URLs, missing alt text, unclosed code blocks, and more. The Markdown Editor gives you live preview so you can see how your guide content will look before it hits the platform.
Platform Support Quick Reference
| Format | OpenAPI descriptions | Guide .md files |
Swagger UI |
|---|---|---|---|
| Bold, italic | All platforms | All platforms | Yes |
| Inline code | All platforms | All platforms | Yes |
| Fenced code blocks | Redocly, Stoplight, Scalar, Readme | All platforms | Limited |
| Tables | Redocly, Stoplight, Scalar, Readme | All platforms | Inconsistent |
| Links | All platforms | All platforms | Yes |
| Task lists | Some | Redocly, Readme | No |
| Footnotes | Some | Redocly (MDX), Readme | No |
| Admonitions / callouts | Redocly, Readme (custom blocks) | Redocly, Readme | No |
| Raw HTML | Varies — most sanitize | Varies | No |
Related Resources
- Markdown Linter — catch style issues before committing
- Markdown Editor — live preview while drafting guide content
- Markdown to HTML — export clean HTML for platforms that accept HTML
- Our guide: Markdown for Technical Writers: The Docs-as-Code Workflow
- Our guide: Markdown Syntax Highlighting — getting language tags right in code blocks
- Our guide: MkDocs vs Docusaurus vs GitBook — choosing the right docs platform