Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

swagger-editor

> DevOps
Open source

Swagger Editor

9.5K stars0 likes3 views
WebsiteGitHub

About

Swagger Editor

SwaggerEditor

Table of Contents

  • Anonymized analytics
  • Getting started
    • Prerequisites
    • Installation
    • Usage
  • Development
    • Prerequisites
    • Setting up
    • npm scripts
    • Build artifacts
    • Package mapping
  • Documentation
  • Docker
  • License
  • Software Bill Of Materials (SBOM)

Anonymized analytics

Swagger Editor uses Scarf to collect anonymized installation analytics. These analytics help support the maintainers of this library and ONLY run during installation. To opt out, you can set the scarfSettings.enabled field to false in your project's package.json:

// package.json
{
  // ...
  "scarfSettings": {
    "enabled": false
  }
  // ...
}

Alternatively, you can set the environment variable SCARF_ANALYTICS to false as part of the environment that installs your npm packages, e.g., SCARF_ANALYTICS=false npm install.

Getting started

Prerequisites

These prerequisites are required both for installing SwaggerEditor as a npm package and local development setup.

  • node-gyp with Python 3.x
  • GLIBC >=2.29
  • emscripten or docker needs to be installed, we recommend going with a docker option

Installation

Assuming prerequisites are already installed, SwaggerEditor npm package is installable and works with Node.js >= 12.22.0. You can install SwaggerEditor via npm CLI by running the following command:

bash
 $ npm install swagger-editor@alpha

NOTE: when using bundler to build your project which is using swagger-editor@5 npm package, you might run into following Node.js error: Reached heap limit Allocation failed - JavaScript heap out of memory. It's caused by significant amount of code that needs to be bundled. This error can be resolved by extending the Node.js max heap limit: export NODE_OPTIONS="--max_old_space_size=4096".

Usage

Use the package in your application:

index.js:

…

webpack.config.js (webpack@5)

Install dependencies needed for webpack@5 to properly build SwaggerEditor.

bash
 $ npm i stream-browserify --save-dev
 $ npm i https-browserify --save-dev
 $ npm i stream-http --save-dev
 $ npm i util --save-dev
 $ npm i buffer --save-dev
 $ npm i process --save-dev
…

Alternative webpack.config.js (webpack@5)

We've already built Web Workers artifacts for you, and they're located inside our npm distribution package in dist/umd/ directory. To avoid the complexity of building the Web Worker artifacts, you can use those artifacts directly. This setup will work both for production and development (webpack-dev-server) and will significantly shorten your build process.

Install copy-webpack-plugin and other needed dependencies.

bash
 $ npm i copy-webpack-plugin --save-dev
 $ npm i stream-browserify --save-dev
 $ npm i https-browserify --save-dev
 $ npm i stream-http --save-dev
 $ npm i util --save-dev
 $ npm i buffer --save-dev
 $ npm i process --save-dev
…

Development

Prerequisites

Assuming prerequisites are already installed, Node.js >=24.18.0 and npm >=11.16.0 are the minimum required versions that this repo runs on, but we recommend using the latest version of Node.js@24.

Setting up

If you use nvm, running following command inside this repository will automatically pick the right Node.js version for you:

bash
 $ nvm use

Run the following commands to set up the repository for local development:

bash
 $ git clone https://github.com/swagger-api/swagger-editor.git
 $ cd swagger-editor
 $ npm i
 $ npm start

npm scripts

Lint

bash
 $ npm run lint

Runs unit tests

bash
 $ npm test              # watch mode
 $ npm run test:run      # single run (CI)
 $ npm run test:coverage # with coverage report

Runs E2E tests

Usage in development environment:

bash
 $ npx playwright test --headed    # Run with browser visible
 $ npx playwright test --ui        # Run with Playwright UI
 $ npx playwright test --debug     # Run in debug mode

Usage in Continuous Integration (CI) environment:

bash
 $ npx playwright test              # Run all tests headless

View test report:

bash
 $ npx playwright show-report test/playwright/report

Build

bash
 $ npm run build

This script will build all the SwaggerEditor build artifacts - app, esm and umd.

Build artifacts

After building artifacts, every two new directories will be created: build/ and dist/.

build/

bash
$ npm run build:app
$ npm run build:app:serve

Builds and serves standalone SwaggerEditor application and all it's assets on http://localhost:3050/.

dist/esm/

bash
$ npm run build:bundle:esm

This bundle is suited for consumption by 3rd parties, which want to use SwaggerEditor as a library in their own applications and have their own build process.

dist/umd/

bash
$ npm run build:bundle:umd

SwaggerEditor UMD bundle exports SwaggerEditor symbol on a global object. It's bundled with React defined as external. This allows the consumer to use his own version of React + ReactDOM and mount SwaggerEditor lazily.

…

npm

SwaggerEditor is released as swagger-editor@5 npm package on npmjs.com. Package can also be produced manually by running the following commands (assuming you're already followed setting up steps):

bash
 $ npm run build:bundle:esm
 $ npm run build:bundle:umd
 $ npm pack

Package mapping

SwaggerEditor maps its build artifacts in package.json file in the following way:

…

To learn more about these fields please refer to webpack mainFields documentation or to Node.js Modules: Packages documentation.

Documentation

Using older version of React

[!IMPORTANT] By older versions we specifically refer to React >=17 <18.

By default swagger-editor@5 npm package comes with latest version of React@18. It's possible to use swagger-editor@5 npm package with older version of React.

Let's say my application integrates with swagger-editor@5 npm package and uses [email protected].

npm

In order to inform swagger-editor@5 npm package that I require it to use my React version, I need to use npm overrides.

json
{
  "dependencies": {
    "react": "=17.0.2",
    "react-dom": "=17.0.2"
  },
  "overrides": {
    "swagger-editor": {
      "react": "$react",
      "react": "$react-dom",
      "react-redux": "^8"
    }
  }
}

[!NOTE] The React and ReactDOM override are defined as a reference to the dependency. Since react-redux@9 only supports React >= 18, we need to use react-redux@8.

yarn

In order to inform swagger-editor@5 npm package that I require it to use my specific React version, I need to use yarn resolutions.

json
{
  "dependencies": {
    "react": "17.0.2",
    "react-dom": "17.0.2"
  },
  "resolutions": {
    "swagger-editor/react": "17.0.2",
    "swagger-editor/react-dom": "17.0.2",
    "swagger-editor/react-redux": "^8"
  }
}

[!NOTE] The React and ReactDOM resolution cannot be defined as a reference to the dependency. Unfortunately yarn does not support aliasing like $react or $react-dom as npm does. You'll need to specify the exact versions.

Customization

  • Plug points

Syntax Highlighting Modes

SwaggerEditor supports two syntax highlighting modes for the Monaco editor:

  1. Simplified Mode (default) - Regex-based syntax highlighting using Monaco's Monarch tokenizer
  2. ApiDOM Mode - Semantic token highlighting provided by ApiDOM Language Service

The simplified mode is enabled by default. If you need more sophisticated semantic highlighting, you can enable ApiDOM mode.

Using Simplified Mode (default):

javascript
import EditorMonacoLanguageApiDOMPlugin from 'swagger-editor/plugins/editor-monaco-language-apidom';

// Default behavior - uses simplified syntax highlighting
const plugins = [
  EditorMonacoLanguageApiDOMPlugin,
  // ... other plugins
];

Enabling ApiDOM Mode:

javascript
import EditorMonacoLanguageApiDOMPlugin from 'swagger-editor/plugins/editor-monaco-language-apidom';

// Enable ApiDOM semantic token highlighting
const plugins = [
  EditorMonacoLanguageApiDOMPlugin({ useApiDOMSyntaxHighlighting: true }),
  // ... other plugins
];

Visual Differences:

The two modes produce different syntax highlighting appearances:

  • Simplified mode:

    • Uses regex-based Monarch tokenizer for syntax coloring
    • Keywords, strings, numbers, and booleans each have distinct colors
    • Does not colorize bracket pairs (brackets are styled as part of the overall token)
    • Color scheme defined by theme token rules: plain.keyword, plain.value.string, plain.value.number, plain.value.boolean
  • ApiDOM mode:

    • Uses semantic token analysis from ApiDOM Language Service
    • Provides context-aware token coloring based on specification structure
    • Enables bracket pair colorization (semantic tokens don't include bracket information, so editor's bracket colorization feature is enabled)
    • Color scheme uses ApiDOM-specific token types with more granular semantic categories

Both modes support:

  • OpenAPI 2.0, 3.0, 3.1, 3.2
  • AsyncAPI 2.x, 3.x
  • JSON and YAML syntax
  • Specification extensions (x- prefixed fields)
  • Inline JSON objects and arrays

Environment Variables

Environment variables are baked in at build time via Vite's define mechanism. The only currently active variable is:

Variable name Description
VITE_VERSION Version displayed in the splash screen. Defaults to $npm_package_version.

Sample values can be found in the .env file at the root of the repository.

Using preview plugins in SwaggerUI

SwaggerEditor comes with number of preview plugins that are responsible for rendering the definition that's being created in the editor. These plugins include:

  • EditorPreviewAsyncAPIPlugin - AsyncAPI specification rendering support
  • EditorPreviewAPIDesignSystemsPlugin - API Design Systems rendering support

With a bit of adapting, we can use these plugins with SwaggerUI to provide an ability to render AsyncAPI or API Design Systems definitions with SwaggerUI.

…

The key here is SwaggerUIAdapter plugin which adapts SwaggerEditor plugins to use directly with SwaggerUI.

Standalone mode

SwaggerUI standalone mode is supported as well. With standalone mode you'll get a TopBar with an input where URL of the definition can be provided and this definition is subsequent

Issues· 32 open

View all issuesOpen on GitHub
  • #5894

    SwaggerEditor@5: UMD bundle throws `require is not defined`, leaving `window.SwaggerEditor` undefined

    Updated Sep 29, 2026
  • #5893

    SwaggerEditor@5: `PACKAGE_VERSION` is not substituted in the UMD build, breaking the Monaco editor (regression in 5.8.6)

    Updated Sep 29, 2026
  • #5845

    Feature request: Pluggable document transformation API for AI-assisted editing and automation

    Updated Aug 12, 2026
  • #5763

    OpenAPI 3.2.0 - path template expressions is not matched with Parameter Object(s)

    Updated Aug 6, 2026
  • #5800

    Valid OpenAPI parameters with same name but different `in` are flagged as duplicates

    Updated Jun 3, 2026
  • #5680

    Allow to set customizable codegen URLs at build time

    enhancementUpdated May 28, 2026
  • #5770

    Swagger editor intellisense/autocomplete not working on certain network environments

    Updated Apr 21, 2026
  • #5659

    Provide a way to optionally not send a request body if optional

    enhancementUpdated Apr 16, 2026
  • #5697

    "Collapse all/Expand all" Bug

    cat: dependenciesbugUpdated Apr 3, 2026
  • #5739

    bug: `deepObject` is not allowed

    Updated Mar 23, 2026

> Tags

JavaScripthacktoberfestopen-sourceopenapi-specificationopenapi3

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 29, 2026
CategoryDevOps
PricingOpen source

> Related tools

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理