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:
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 you application:
webpack.config.js (webpack@5)
Install dependencies needed for webpack@5 to properly build SwaggerEditor.
Alternative webpack.config.js (webpack@5)
We’ve already built Web Workers fragments for you, and they’re located inside our npm distribution
package in dist/umd/ directory. In order to avoid complexity of building the Web Worker fragments you can
use those fragments 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.
Development
Prerequisites
Assuming prerequisites are already installed, Node.js>=20.3.0 and npm >=9.6.7
are the minimum required versions that this repo runs on, but we recommend using the latest version of Node.js@20.
Setting up
If you use nvm, running following command inside this repository
will automatically pick the right Node.js version for you:
Run the following commands to set up the repository for local development:
npm scripts
Lint
Runs unit and integration tests
Runs E2E Cypress tests
Usage in development environment:
Usage in Continuos Integration (CI) environment:
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/
Builds and serves standalone SwaggerEditor application and all it’s assets on http://localhost:3050/.
dist/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/
SwaggerEditor UMD bundle exports SwaggerEditor symbol on global object.
It’s bundled with React defined as external. This allows 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 following commands (assuming you’re already followed setting up steps):
Package mapping
SwaggerEditor maps its build artifacts in package.json file in following way:
[!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 React@17.0.2.
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.
[!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.
[!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.
It is possible to use an environment variable to specify a local JSON/YAML file or a remote URL for SwaggerEditor to load on startup.
These environment variables will get baked in during build time into build artifacts.
Environment variables currently available:
Variable name
Description
REACT_APP_DEFINITION_FILE
Specifies a local file path, and the specified file must also be present in the /public/static directory
REACT_APP_DEFINITION_URL
Specifies a remote URL. This environment variable currently takes precedence over REACT_APP_SWAGGER_FILE
REACT_APP_VERSION
Specifies the version of this app. The version is read from package.json file.
Sample environment variable values can be found in .env file. For more information about using
environment variables, please refer to adding Custom Environment Variables
section of Create React App documentation.
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 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 subsequently loaded
by the SwaggerUI.
It’s possible to utilize preview plugins in a build-free way via unpkg.com to create a standalone
multi-spec supporting version of SwaggerUI.
Composing customized SwaggerEditor version
SwaggerEditor is just a number of SwaggerUI plugins used with swagger-ui-react.
Customized SwaggerEditor can be created by composing individual plugins with either swagger-ui and swagger-ui-react.
Plugins
List of available plugins:
dialogs
dropdown-menu
dropzone
editor-content-fixtures
editor-content-origin
editor-content-persistence
editor-content-read-only
editor-content-type
editor-monaco
editor-monaco-language-apidom
editor-preview
editor-preview-api-design-systems
editor-preview-asyncapi
editor-preview-swagger-ui
editor-safe-render
editor-textarea
layout
modals
splash-screen
swagger-ui-adapter
top-bar
versions
Individual plugins can be imported in the following way:
Presets
Along with plugins, presets are available as well. Preset is a collection of plugins
that are design to work together to provide a compound feature.
List of available presets:
textarea
monaco
Individual presets can be imported in the following way:
NOTE: Please refer to the Plug points documentation
of SwaggerUI to understand how presets are passed to SwaggerUI.
Composing with swagger-ui
Composing with swagger-ui-react
Docker
Pre-built DockerHub image
SwaggerEditor is available as a pre-built docker image hosted on DockerHub.
Building locally
Privileged image:
Now open your browser at http://localhost:8080/.
Unprivileged image:
Now open your browser at http://localhost:8080/.
No custom environment variables are currently supported by SwaggerEditor.
License
SwaggerEditor is licensed under Apache 2.0 license.
SwaggerEditor comes with an explicit NOTICE file
containing additional legal notifications and information.
This project uses REUSE specification that defines a standardized method
for declaring copyright and licensing for software projects.
Software Bill Of Materials (SBOM)
Software Bill Of materials is available in this repository dependency graph.
Click on Export SBOM button to download the SBOM in SPDX format.