swagger-ui-express

Serves interactive Swagger UI API documentation directly from your Express app based on a Swagger/OpenAPI JSON or YAML document.

Library
npm
v5.0.1
1,494 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
48 /100 Fair
Development Activity 0
Maintenance 20
Community 72
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
64 /100 Good
Architecture 68
Code Quality 62
Innovation 40
Learning Curve 85

swagger-ui-express is a small piece of Express middleware that renders the Swagger UI single-page app inside your own server, bound to a Swagger/OpenAPI document you supply. Instead of hosting a separate static docs site, you mount it on a route (commonly /api-docs) and it serves the same interactive, explorable documentation UI that swagger.io uses, styled and driven by whatever spec your app produces.

The spec can come from a static JSON file, a dynamically generated object (for example from swagger-jsdoc), a remote URL, or even be computed per-request by attaching it to req.swaggerDoc. The library ships extensive customization hooks — custom CSS (inline or via URL), custom JavaScript (inline or via URL), custom page titles, favicon overrides, robots meta tags, and OAuth/API-key preauthorization — so the hosted docs page can be made to match a product’s branding rather than looking like generic tooling.

Because the actual rendering is handled by the versioned swagger-ui-dist package, swagger-ui-express stays a thin, focused wrapper: its job is templating the HTML shell, serving the static Swagger UI assets, and wiring options through to the client-side SwaggerUIBundle call. This keeps the middleware itself tiny while still exposing nearly all of Swagger UI’s underlying configuration surface to Express developers.

What You Get

  • serve + setup(swaggerDoc, opts) middleware pair to mount interactive API docs on any Express route
  • Support for static JSON specs, dynamically generated specs (e.g. from swagger-jsdoc), or specs loaded from a remote URL
  • Per-request spec support via req.swaggerDoc, so different documentation can be served to different callers
  • Custom CSS, custom JS (inline or external URL), custom page title, and custom favicon options for branding the docs page
  • A dropdown “explorer” mode for switching between multiple Swagger documents from one page
  • OAuth and API-key preauthorization hooks (customOptions.oauth, customOptions.preauthorizeApiKey) so testers don’t have to manually authenticate every session
  • serveFiles/serveWithOptions variants for hosting two or more independent Swagger UI instances from the same app

Common Use Cases

  • Hosting living API documentation for an Express-based REST API directly from the same process that serves the API
  • Pairing with swagger-jsdoc to generate the OpenAPI spec from JSDoc comments and immediately render it as browsable docs
  • Exposing a /api-docs endpoint internal teams and API consumers can use to try requests via the built-in “Authorize” and “Try it out” UI
  • Serving two versions of an API (e.g. /v1/api-docs and /v2/api-docs) with distinct Swagger documents via serveFiles
  • Preauthorizing a documentation page with an API key or OAuth token so internal reviewers don’t re-enter credentials

Under The Hood

Architecture The module is a single index.js file built around one core function, generateHTML, which takes a Swagger document plus an options bag and does pure string templating: it substitutes placeholders (<% customCss %>, <% favIconString %>, <% title %>, and so on) into an HTML template string and a companion JS template string that ultimately calls SwaggerUIBundle in the browser. setup() wraps this in an Express handler that re-renders per-request when req.swaggerDoc is present (letting different requests see different specs), while serve/serveFiles compose that handler with express.static pointed at swagger-ui-dist’s asset directory (getAbsoluteSwaggerFsPath()). There is no class hierarchy, router, or plugin system — the entire surface area is a handful of exported functions operating on plain objects, which keeps the blast radius of a spec/options change limited to the templating layer itself.

Tech Stack The library targets Node’s CommonJS module system and Express (>=4.0.0 as a peer dependency, with 5.x beta also declared compatible), with swagger-ui-dist as its one runtime dependency for the actual Swagger UI static bundle. Development tooling is Mocha for the test runner, nyc/istanbul-badges-readme for coverage, and Puppeteer to drive a real headless Chromium instance against a small Express testapp fixture for integration-style assertions rather than mocking the browser layer. CI is configured via a legacy .travis.yml targeting Node 8 and 10, which is older than the package’s stated >= v0.10.32 engines field and likely predates the project’s more recent 5.x releases.

Code Quality Testing is integration-first: test/test.spec.js boots a real Express server backed by test/testapp/app.js, launches Puppeteer, and asserts against rendered DOM selectors (.information-container, .swagger-ui, auth-button lock state) rather than unit-testing generateHTML in isolation. This gives strong end-to-end confidence that the shipped HTML/JS actually renders correctly in a browser, at some cost to fast, isolated coverage of individual option combinations. The source itself uses plain var declarations, informal legacy-JS style (matching its 2016 origins), and no TypeScript types; error handling is minimal since the module does no I/O beyond serving static files and templating strings, so there is little that can throw at runtime. There is no linter configuration in the repo.

API Design The public API is small and pragmatic: serve + setup(doc, opts) covers the common case in two lines, while power users reach for serveFiles, serveWithOptions, or generateHTML directly for multi-spec or fully custom setups. Options are a single flat object (explorer, customCss, customJs, swaggerOptions, customSiteTitle, etc.) documented thoroughly in the README with runnable examples for every variant, which keeps the learning curve low even though the options surface itself is fairly large. The one legacy wrinkle is setup’s positional-arguments overload (opts, options, customCss, customfavIcon, swaggerUrl, customSiteTitle as separate parameters) kept alongside the newer single-options-object form for backward compatibility, which is undocumented as deprecated but still present in the function signature.

Used by 16 apps in this directory

JavaScript
95%
MIT

AnythingLLM

AI Assistants · Automation · Developer Tools

66,533

The all-in-one AI platform for private document chat, no-code agents, and local LLMs with zero setup friction.

View details
90
Repo Health
78
Technical
64
Dependency
Built with
JavaScript 95%
Updated 6 days ago
TypeScript
92%
GPL 3.0

Blinko

Knowledge Management · Note Taking

11,049

A self-hosted, AI-powered card note-taking tool that lets you capture fleeting thoughts instantly and retrieve them with natural language search.

View details
75
Repo Health
69
Technical
63
Dependency
Built with
TypeScript 92%
Updated 1 months ago
TypeScript
98%
AGPL 3.0

Checkmate

Analytics · Devops · Monitoring

10,895

Self-hosted uptime and infrastructure monitoring with multi-protocol checks, global geo-coverage, and beautiful real-time dashboards.

View details
90
Repo Health
82
Technical
67
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago
TypeScript
84%
Apache 2.0

Continue

AI Code Assistants · AI Development · Automation

36,049

Open-source coding agent for VS Code, JetBrains, and CLI with support for 30+ LLM providers.

View details
73
Repo Health
88
Technical
62
Dependency
Built with
TypeScript 84%
Updated 5 days ago
TypeScript
62%
Other

Flowise

AI Development · Automation · Developer Tools

55,490

Drag-and-drop visual builder for AI agents, RAG pipelines, and multi-agent systems—deploy anywhere in minutes.

View details
82
Repo Health
77
Technical
63
Dependency
Built with
TypeScript 62%
JavaScript 27%
Updated 1 months ago
TypeScript
91%
Apache 2.0

Helicone

AI Development · Analytics · Monitoring

6,182

An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.

View details
70
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 91%
Updated 2 weeks ago
TypeScript
96%
MIT

HyperDX

Analytics · Developer Tools · Monitoring

9,916

Open source observability platform that unifies logs, traces, metrics, and session replays on ClickHouse — now the core of ClickStack.

View details
87
Repo Health
83
Technical
65
Dependency
Built with
TypeScript 96%
Updated 1 weeks ago
TypeScript
98%
Other

Kibana

Analytics · Monitoring

21,301

Your open source window into the Elastic Stack — query, visualize, and act on data stored in Elasticsearch with real-time dashboards, AI-assisted search, and automated alerting.

View details
98
Repo Health
87
Technical
63
Dependency
Built with
TypeScript 98%
Updated 4 days ago
TypeScript
99%
Apache 2.0

Mastra Code

AI Code Assistants

28,378

"A coding agent that never compacts" — a terminal-based AI coding agent built on the Mastra framework, with Observational Memory instead of context compaction, multi-model support, and OAuth login for Claude Max or ChatGPT Plus.

View details
90
Repo Health
73
Technical
65
Dependency
Built with
TypeScript 99%
Updated 4 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers