- Notifications
You must be signed in to change notification settings - Fork2.3k
swagger-api/swagger-editor
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
⏰️ Looking for the next generation version of Swagger Editor?
SwaggerEditor is now released under two major release channels:
- SwaggerEditor@4 - released frommaster branch and deployed athttps://editor.swagger.io/
- SwaggerEditor@5 - released fromnext branch and deployed athttps://editor-next.swagger.io/
OnlySwaggerEditor@5 supportsOpenAPI 3.1.0.SwaggerEditor@4 will not receive OpenAPI 3.1.0 support and is considered legacy at this point.The plan is to continually migrate fully to SwaggerEditor@5 and deprecate the SwaggerEditor@4 in the future.
🕰️ Looking for the older version of Swagger Editor? Refer to the2.x or3.x branches.
Swagger Editor lets you editOpenAPI API definitions (OpenAPI 2.0 andOpenAPI 3.0.3)in JSON or YAML format inside your browser and to preview documentations in real time.Valid OpenAPI definitions can then be generated and used with the full Swagger tooling (code generation, documentation, etc).
As a brand-new version, written from the ground up, there are some known issues and unimplemented features. Check out theKnown Issues section for more details.
This repository publishes to two different NPM modules:
- swagger-editor is a traditional npm module intended for use in single-page applications that are capable of resolving dependencies (via Webpack, Browserify, etc).
- swagger-editor-dist is a dependency-free module that includes everything you need to serve Swagger Editor in a server-side project, or a web project that can't resolve npm module dependencies.
If you're building a single-page application, usingswagger-editor
is strongly recommended, sinceswagger-editor-dist
is significantly larger.
Swagger Editor usesScarf to collectanonymized installation analytics. These analytics help support the maintainers of this library and ONLY run during installation. Toopt out, you can set thescarfSettings.enabled
field tofalse
in your project'spackage.json
:
// package.json{ // ... "scarfSettings": { "enabled": false } // ...}
Alternatively, you can set the environment variableSCARF_ANALYTICS
tofalse
as part of the environment that installs your npm packages, e.g.,SCARF_ANALYTICS=false npm install
.
Any of the scripts below can be run by typingnpm run <script name>
in the project's root directory.
Script name | Description |
---|---|
dev | Spawn a hot-reloading dev server on port 3200. |
deps-check | Generate a size and licensing report on Swagger Editors's dependencies. |
lint | Report ESLint style errors and warnings. |
lint-errors | Report ESLint style errors, without warnings. |
lint-fix | Attempt to fix style errors automatically. |
watch | Rebuild the core files in/dist when the source code changes. Useful fornpm link . |
Script name | Description |
---|---|
build | Build a new set of JS and CSS assets, and output them to/dist . |
build:bundle | Buildswagger-editor-bundle.js only (commonJS). |
build:core | Buildswagger-editor.(js|css) only (commonJS). |
build:standalone | Buildswagger-editor-standalone-preset.js only (commonJS). |
build:stylesheets | Buildswagger-editor.css only. |
build:es:bundle | Buildswagger-editor-es-bundle.js only (es2015). |
build:es:bundle:core | Buildswagger-editor-es-bundle-core.js only (es2015). |
Script name | Description |
---|---|
test | Run unit tests in Node, run Cypress end-to-end tests, and run ESLint in errors-only mode. |
test:unit-mocha | Run Mocha-based unit tests in Node. |
test:unit-jest | Run Jest-based unit tests in Node. |
e2e | Run end-to-end browser tests with Cypress. |
lint | Run ESLint test |
test:artifact | Run list of bundle artifact tests in Jest |
test:artifact:umd:bundle | Run unit test that confirmsswagger-editor-bundle exports as a Function |
test:artifact:es:bundle | Run unit test that confirmsswagger-editor-es-bundle exports as a Function |
test:artifact:es:bundle:core | Run unit test that confirmsswagger-editor-es-bundle-core exports as a Function |
- git, any version
- Node.js >=20.3.0 andnpm >=9.6.7 are the minimum required versions that this repo runs on, but we always recommend using the latest version of Node.js.
$ npm i --legacy-peer-deps
If you have Node.js and npm installed, you can runnpm start
to spin up a static server.
Otherwise, you can openindex.html
directly from your filesystem in your browser.
If you'd like to make code changes to Swagger Editor, you can start up a Webpack hot-reloading dev server vianpm run dev
.
Swagger Editor works in the latest versions of Chrome, Safari, Firefox, and Edge.
To help with the migration, here are the currently known issues with 3.X. This list will update regularly, and will not include features that were not implemented in previous versions.
- Everything listed inSwagger UI's Known Issues.
- The integration with the codegen is still missing.
There is a docker image published indocker.swagger.io registry.
To use this, run the following:
docker pull docker.swagger.io/swaggerapi/swagger-editordocker run -d -p 80:8080 docker.swagger.io/swaggerapi/swagger-editor
This will run Swagger Editor (in detached mode) on port 80 on your machine, so you can open it by navigating tohttp://localhost
in your browser.
- You can provide a URL pointing to an API definition (may not be available if some security policies such as CSP or CORS are enforced):
docker run -d -p 80:8080 -e URL="https://petstore3.swagger.io/api/v3/openapi.json" docker.swagger.io/swaggerapi/swagger-editor
- You can provide your own
json
oryaml
definition file from your local host:
docker run -d -p 80:8080 -v $(pwd):/tmp -e SWAGGER_FILE=/tmp/swagger.json docker.swagger.io/swaggerapi/swagger-editor
Note: When bothURL
andSWAGGER_FILE
environment variables are set,URL
has priority andSWAGGER_FILE
is ignored.
- You can specify a different base url via
BASE_URL
variable for accessing the application - for example if you want the application to be available athttp://localhost/swagger-editor/
:
docker run -d -p 80:8080 -e BASE_URL=/swagger-editor docker.swagger.io/swaggerapi/swagger-editor
- You can specify a different port via
PORT
variable for accessing the application, default is8080
.
docker run -d -p 80:80 -e PORT=80 docker.swagger.io/swaggerapi/swagger-editor
- You can specify Google Tag Manager ID via
GTM
variable for tracking the usage of the swagger-editor.
docker run -d -p 80:8080 -e GTM=GTM-XXXXXX docker.swagger.io/swaggerapi/swagger-editor
You can also customize the different endpoints used by the Swagger Editor with the following environment variables. For instance, this can be useful if you have your own Swagger generator server:
Environment variable | Default value |
---|---|
URL_SWAGGER2_GENERATOR | https://generator.swagger.io/api/swagger.json |
URL_OAS3_GENERATOR | https://generator3.swagger.io/openapi.json |
URL_SWAGGER2_CONVERTER | https://converter.swagger.io/api/convert |
If you want to run the Swagger Editor locally without the Codegen features (Generate Server and Generate Client) you can set the above environment variables tonull
(URL_SWAGGER2_CONVERTER=null
).
To build and run a docker image with the code checked out on your machine, run the following from the root directory of the project:
# Install npm packages (if needed)npm install# Build the appnpm run build# Build an imagedocker build -t swagger-editor .# Run the containerdocker run -d -p 80:8080 swagger-editor
You can then view the app by navigating tohttp://localhost
in your browser.
Important
By older versions we specifically refer toReact >=17 <18
.
By defaultswagger-editor@4 npm package comes with latest version ofReact@18.It's possible to useswagger-editor@4 npm package with older version of React.
Let's say my application integrates withswagger-editor@4 npm package and usesReact@17.0.2.
In order to informswagger-editor@4
npm package that I require it to use my React version, I need to usenpm 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. Sincereact-redux@9 only supportsReact >= 18
, we need to usereact-redux@8.
In order to informswagger-editor@4
npm package that I require it to use my specific React version, I need to useyarn 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. Unfortunatelyyarn does not support aliasing like$react
or$react-dom
asnpm does. You'll need to specify the exact versions.
Please disclose any security-related issues or vulnerabilities by emailingsecurity@swagger.io, instead of using the public issue tracker.
About
Swagger Editor
Topics
Resources
License
Security policy
Uh oh!
There was an error while loading.Please reload this page.