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,496stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
48/100Fair
Development Activity0
Maintenance20
Community72
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
64/100Good
Architecture68
Code Quality62
Innovation40
Learning Curve85

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

Developer Tools · Automation · AI Assistants

65,696

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
JavaScript95%
Updated 3 days ago
TypeScript
92%
GPL 3.0

Blinko

Knowledge Management · Note Taking

10,992

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
80
Repo Health
69
Technical
63
Dependency
Built with
TypeScript92%
Updated 1 weeks ago
TypeScript
98%
AGPL 3.0

Checkmate

Devops · Analytics · Monitoring

10,794

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

View details
91
Repo Health
82
Technical
68
Dependency
Built with
TypeScript98%
Updated yesterday
TypeScript
84%
Apache 2.0

Continue

Developer Tools · AI Development · AI Code Assistants

35,808

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

View details
81
Repo Health
88
Technical
62
Dependency
Built with
TypeScript84%
Updated yesterday
TypeScript
62%
Other

Flowise

Developer Tools · Automation · No Code Platforms

55,427

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

View details
86
Repo Health
77
Technical
63
Dependency
Built with
TypeScript62%
JavaScript27%
Updated 3 weeks ago
TypeScript
91%
Apache 2.0

Helicone

Monitoring · AI Development · Analytics

6,133

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
69
Repo Health
81
Technical
65
Dependency
Built with
TypeScript91%
Updated 1 weeks ago
TypeScript
96%
MIT

HyperDX

Developer Tools · Analytics · Monitoring

9,873

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

View details
88
Repo Health
83
Technical
68
Dependency
Built with
TypeScript96%
Updated yesterday
TypeScript
98%
Other

Kibana

Analytics · Monitoring

21,284

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
66
Dependency
Built with
TypeScript98%
Updated yesterday
TypeScript
99%
Apache 2.0

Mastra Code

AI Code Assistants

27,743

"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
88
Repo Health
73
Technical
65
Dependency
Built with
TypeScript99%
Updated today

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

Search