Swagger Editor
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.
These prerequisites are required both for installing SwaggerEditor as a npm package and local development setup.
>=2.29Assuming 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:
$ npm install swagger-editor@alphaNOTE: 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".
Use the package in your application:
index.js:
…webpack.config.js (webpack@5)
Install dependencies needed for webpack@5 to properly build SwaggerEditor.
$ 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.
$ 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…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.
If you use nvm, running following command inside this repository will automatically pick the right Node.js version for you:
$ nvm useRun the following commands to set up the repository for local development:
$ git clone https://github.com/swagger-api/swagger-editor.git
$ cd swagger-editor
$ npm i
$ npm startLint
$ npm run lintRuns unit tests
$ npm test # watch mode
$ npm run test:run # single run (CI)
$ npm run test:coverage # with coverage reportRuns E2E tests
Usage in development environment:
$ npx playwright test --headed # Run with browser visible
$ npx playwright test --ui # Run with Playwright UI
$ npx playwright test --debug # Run in debug modeUsage in Continuous Integration (CI) environment:
$ npx playwright test # Run all tests headlessView test report:
$ npx playwright show-report test/playwright/reportBuild
$ npm run buildThis script will build all the SwaggerEditor build artifacts - app, esm and umd.
After building artifacts, every two new directories will be created: build/ and dist/.
build/
$ npm run build:app
$ npm run build:app:serveBuilds and serves standalone SwaggerEditor application and all it's assets on http://localhost:3050/.
dist/esm/
$ npm run build:bundle:esmThis 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/
$ npm run build:bundle:umdSwaggerEditor 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):
$ npm run build:bundle:esm
$ npm run build:bundle:umd
$ npm packSwaggerEditor 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.
[!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].
In order to inform swagger-editor@5 npm package that I require it to use my React version, I need to use npm overrides.
{
"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.
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.
{
"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
$reactor$react-domas npm does. You'll need to specify the exact versions.
SwaggerEditor supports two syntax highlighting modes for the Monaco editor:
The simplified mode is enabled by default. If you need more sophisticated semantic highlighting, you can enable ApiDOM mode.
Using Simplified Mode (default):
import EditorMonacoLanguageApiDOMPlugin from 'swagger-editor/plugins/editor-monaco-language-apidom';
// Default behavior - uses simplified syntax highlighting
const plugins = [
EditorMonacoLanguageApiDOMPlugin,
// ... other plugins
];Enabling ApiDOM Mode:
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:
plain.keyword, plain.value.string, plain.value.number, plain.value.booleanApiDOM mode:
Both modes support:
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.
SwaggerEditor comes with number of preview plugins that are responsible for rendering
the definition that's being created in the editor. These plugins include:
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.
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
SwaggerEditor@5: UMD bundle throws `require is not defined`, leaving `window.SwaggerEditor` undefined
SwaggerEditor@5: `PACKAGE_VERSION` is not substituted in the UMD build, breaking the Monaco editor (regression in 5.8.6)
Feature request: Pluggable document transformation API for AI-assisted editing and automation
OpenAPI 3.2.0 - path template expressions is not matched with Parameter Object(s)
Valid OpenAPI parameters with same name but different `in` are flagged as duplicates
Allow to set customizable codegen URLs at build time
Swagger editor intellisense/autocomplete not working on certain network environments
Provide a way to optionally not send a request body if optional
"Collapse all/Expand all" Bug
bug: `deepObject` is not allowed