Requestly
API ClientHTTP InterceptorPricingRequestly vs PostmanBlogDocsDownload

Home / Blog / API Client

How to Auto-Generate API Documentation

Hand-written API documentation goes stale the moment an endpoint changes. The fix is to generate your docs from a machine-readable source of truth - an OpenAPI specification - so the docs always match the API. This guide shows you how to auto-generate clean, interactive API documentation from an OpenAPI/Swagger spec using popular open-source and commercial tools.

We will cover Swagger UI, Redoc, Stoplight Elements, and a couple of static generators, so you can pick the approach that fits how you host and ship docs.

Start with a single source of truth: OpenAPI

OpenAPI (formerly Swagger) is a standard, language-agnostic description of a REST API in YAML or JSON. It lists every path, method, parameter, request body, and response schema. Because it is structured data, tools can read it and render documentation automatically - no copy-pasting endpoint tables by hand.

A minimal spec looks like this:

openapi: 3.0.3
info:
  title: Orders API
  version: 1.0.0
paths:
  /orders/{id}:
    get:
      summary: Get an order by ID
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: The order
          content:
            application/json:
              schema:
                type: object
                properties:
                  id: { type: string }
                  total: { type: number }

Keep this file in your repository. Every generator below consumes it, which means a single edit propagates to your published docs.

Option 1: Swagger UI (interactive, “try it out”)

Swagger UI renders your spec as an interactive page where readers can expand each endpoint and even send live requests. The fastest way to preview it is the official Docker image:

docker run -p 8080:8080 \
  -e SWAGGER_JSON=/spec/openapi.yaml \
  -v "$(pwd)":/spec \
  swaggerapi/swagger-ui

Open localhost:8080 and you have browsable docs. To embed Swagger UI in your own site, drop in its assets and point it at your spec:

<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist/swagger-ui.css">
<div id="swagger"></div>
<script src="https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js"></script>
<script>
  SwaggerUIBundle({ url: "/openapi.yaml", dom_id: "#swagger" });
</script>

Option 2: Redoc (clean three-panel reference)

Redoc produces a polished, three-panel reference site that many teams prefer for read-only documentation. You can render it from a single HTML tag or build a static file with its CLI:

<redoc spec-url="/openapi.yaml"></redoc>
<script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"></script>
# Produce a single self-contained HTML file you can host anywhere
npx @redocly/cli build-docs openapi.yaml -o docs/index.html

Option 3: Stoplight Elements

Stoplight Elements is another web component that renders OpenAPI into attractive docs with a “try it” console. Like Redoc, you embed a single element and point it at your spec - handy when you want docs inside an existing app shell.

<elements-api apiDescriptionUrl="/openapi.yaml" router="hash"></elements-api>

Option 4: Static docs in your CI pipeline

For docs that ship automatically, generate a static site as part of your build. The Redocly CLI (above) outputs a single HTML file; you can publish it to GitHub Pages, Netlify, or any static host. Because generation is a single command, it slots neatly into automation - regenerate on every merge so published docs never drift from the spec.

# Validate the spec, then build docs - fail the build if the spec is broken
npx @redocly/cli lint openapi.yaml
npx @redocly/cli build-docs openapi.yaml -o public/index.html

Choosing between the renderers

All four options above read the same OpenAPI file, so switching later is cheap. The differences are about audience and hosting:

  • Swagger UI shines for internal and developer-facing docs where the “try it out” console matters. Engineers can fire a request straight from the page while reading the schema, which shortens the feedback loop during integration.
  • Redoc is the usual pick for public, marketing-grade reference sites. Its three-panel layout - navigation, description, and code samples side by side - reads cleanly and prints well, and the static build is a single file you can drop on any CDN.
  • Stoplight Elements is the middle ground: a web component you embed inside an existing app or docs portal, with a console like Swagger UI but a look closer to Redoc.
  • Static generators (the Redocly CLI build step) win when you want zero runtime dependencies - the output is plain HTML, so there is no JavaScript bundle to load a spec at view time.

A common pattern is to use a console-style renderer on an internal docs site and a static Redoc build for the public one, both generated from the identical spec.

Documenting multiple API versions

APIs evolve, and readers often need docs for more than one version at a time. Because each generated site is just the product of one spec file, versioning is mostly a file-and-routing concern. Keep a spec per version in your repository and build each into its own path:

# Build a docs page per API version
npx @redocly/cli build-docs specs/v1/openapi.yaml -o public/v1/index.html
npx @redocly/cli build-docs specs/v2/openapi.yaml -o public/v2/index.html

Add a small version switcher in your site navigation and your readers can move between /v1/ and /v2/ without you maintaining a single, sprawling document. The same approach works for staging versus production specs when those diverge.

Keeping the spec accurate

Generated docs are only as good as the spec behind them. A few habits keep them honest:

  • Lint the spec in CI so malformed or incomplete definitions fail fast, before they reach a published page.
  • Generate the spec from code - if your API framework can emit an OpenAPI file, treat that emitted file as the source of truth rather than maintaining the spec by hand, so the description can never drift from the implementation.
  • Add rich descriptions and examples - a bare schema is technically correct but hard to use. Filling in summaries, field descriptions, and example values in the spec makes the generated docs genuinely helpful, because every renderer surfaces that metadata.
  • Review the rendered output - skim the generated page when the spec changes, the same way you would review code, to catch endpoints that are missing examples or have confusing descriptions.

Because all of this lives in the spec, improving the documentation and improving the contract become the same activity - there is no second document to keep in sync.

Generating a spec from captured traffic

If you do not have a spec at all, another route is to build one from real requests and responses. Dedicated external tools - for example Optic or mitmproxy2swagger - run their own proxy, observe traffic, and infer a draft OpenAPI description that you then refine by hand and feed to the renderers above. This is a separate, proxy-based workflow run by those tools, not something an API client does for you. It is a pragmatic starting point for an undocumented legacy API: capture representative calls with one of them, generate a draft spec, clean it up, and from then on treat that spec as the source your docs are generated from.

Where Requestly fits today (and what is coming)

Requestly is a privacy-first, local-first desktop API client. It already understands OpenAPI from the consumer side: you can import an OpenAPI spec (alongside cURL, Postman collections, HAR, and WSDL) and Requestly turns each path into a ready-to-send request inside an organized collection. If you have a spec, you can be exercising the API in Requestly within seconds - see our guide on how to convert an OpenAPI spec to an API collection.

What Requestly does not do yet is the reverse: auto-generating hosted, shareable API documentation from your collection or spec. A built-in documentation generator is on our roadmap, not a shipped feature. Until it lands, use Swagger UI, Redoc, or Stoplight Elements to publish docs, and use Requestly to import the same spec and actually test the endpoints. We will refresh this guide when documentation generation arrives.

Already have an OpenAPI spec? Import it into the Requestly API Client → - a local-first Postman alternative - and every endpoint becomes a ready-to-send request in an organized collection.

Frequently asked questions

What does it mean to auto-generate API documentation?

It means producing human-readable docs automatically from a machine-readable source - typically an OpenAPI specification - instead of writing endpoint tables by hand. Because the docs derive from the spec, they stay in sync with the API whenever you regenerate them.

What is the difference between Swagger UI and Redoc?

Both render an OpenAPI spec as documentation. Swagger UI is interactive and lets readers send live “try it out” requests, which suits exploratory docs. Redoc produces a clean, three-panel read-only reference that many teams prefer for polished public documentation.

Do I need an OpenAPI spec to generate docs?

Practically, yes for these tools - Swagger UI, Redoc, and Stoplight Elements all consume an OpenAPI/Swagger file. If you do not have one, many API frameworks can emit an OpenAPI file from your code, which you then feed to the documentation generator.

Can I publish generated docs automatically?

Yes. Tools like the Redocly CLI build a static HTML file with a single command, so you can run that command in your build pipeline and publish the output to GitHub Pages, Netlify, or any static host on every merge.

Does Requestly auto-generate API documentation?

Not yet. Generating hosted, shareable documentation from a collection or spec is on the Requestly roadmap but is not shipped today. Requestly can import an OpenAPI spec and turn it into a testable collection, which is the consumer side of the same workflow.

Can Requestly import an existing OpenAPI spec?

Yes. Requestly imports OpenAPI specs (as well as cURL, Postman collections, HAR, and WSDL). Each path in the spec becomes an individual request with the method, URL, headers, and body pre-filled inside an organized collection.

Related reading: see the best API testing tools and learn to convert an OpenAPI spec into a collection.

Test any API request visually: import a cURL command or build from scratch in Requestly, the free API client for developers.

Download Free →