Skip to content

Commit 718b04d

Browse files
authored
refactor(state-management): manage state outside of spec plugin (#3241)
- state management now exclusively uses concepts of selectors, actions, reducers and standard async thunks (this allows overrides on plugin level) - editor state is not maintained within SwaggerUI spec plugin but has it's own allocated place - editor content type detection is now centralized into single plugin and uses power of ApiDOM - performance of editing is now instant without any typing lag - splash screen now displays while editor loads - around 70% of codebase have been rewritten - every implementation that could be simplified or fixed along the way was simplified or fiexed - plugins have been reorganized BREAKING CHANGE: plugin reorganization, redux actions and selectors usage and naming made consistent Refs #3217
1 parent 2568a04 commit 718b04d

File tree

225 files changed

+7502
-4819
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

225 files changed

+7502
-4819
lines changed

.env

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ REACT_APP_COMPACT_BUNDLE=true
66
# Tip: Should not set both REACT_APP_SWAGGER_FILE and REACT_APP_SWAGGER_URL flags
77

88
# Create-React-App expects static directory within /public to contain FILE
9-
# REACT_APP_SWAGGER_FILE=/static/petstore-oas3.yml
9+
# REACT_APP_DEFINITION_FILE=/static/petstore-oas3.yml
1010

11-
# OAS3.0 remote URI
12-
# REACT_APP_SWAGGER_URL=https://petstore3.swagger.io/api/v3/openapi.json
11+
# OAS3.0 remote absolute URI
12+
# REACT_APP_DEFINITION_URL=https://petstore3.swagger.io/api/v3/openapi.json
1313

14-
# OAS2.x remote URI
15-
# REACT_APP_SWAGGER_URL=https://petstore.swagger.io/v2/swagger.json
14+
# OAS2.x remote absolute URI
15+
# REACT_APP_DEFINITION_URL=https://petstore.swagger.io/v2/swagger.json
1616

17-
# AsyncAPI 2.x.x remote URI
18-
# REACT_APP_SWAGGER_URL=https://raw.githubusercontent.com/asyncapi/spec/v2.4.0/examples/streetlights-kafka.yml
17+
# AsyncAPI 2.x.x remote absolute URI
18+
REACT_APP_DEFINITION_URL=https://raw.githubusercontent.com/asyncapi/spec/v2.4.0/examples/streetlights-kafka.yml
19+
20+
REACT_APP_VERSION=$npm_package_version

NOTICE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Copy of the Apache 2.0 license can be found in `LICENSES/Apache-2.0.txt` file.
55

66
react-dd-menu
77
Copyright (c) 2015 Mikkel Laursen
8-
Specific Sass Cascading Style Sheet in `_react-dd-menu.scss` (the file) were originally created under MIT license in https://github.com/mlaursen/react-dd-menu repository.
8+
Specific Sass Cascading Style Sheet in `_dropdown-menu.scss` (the file) were originally created under MIT license in https://github.com/mlaursen/react-dd-menu repository.
99
Specific Sass Cascading Style Sheet have been copied into this project and modified. All modifications are licensed under Apache 2.0 License.
1010
Copy of the MIT license can be found in `LICENSES/MIT.txt` file.
1111

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,14 +427,20 @@ or to [Node.js Modules: Packages documentation](https://nodejs.org/docs/latest-v
427427
428428
### Environment Variables
429429
430-
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. However, there is a limitation that any changes to the environment variable(s) will also require a rebuild and restart of the application. This is a constraint of Create React App infrastructure.
430+
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.
431+
These environment variables will get baked in during build time into build artifacts.
431432
432-
Two environment variables are currently available: `REACT_APP_SWAGGER_FILE` and `REACT_APP_SWAGGER_URL`. Disabled sample environment variables can be found in `.env`. Other `.env` files may also be used, for more information plese refer to [custom CRA environemnt variables](https://create-react-app.dev/docs/adding-custom-environment-variables/).
433+
Environment variables currently available:
433434
434-
`REACT_APP_SWAGGER_FILE` specifies a local file path, and the specified file must also be present in the `/public/static` directory.
435-
436-
`REACT_APP_SWAGGER_URL` specifies a remote URL. This environment variable currently takes precedence over `REACT_APP_SWAGGER_FILE`.
435+
| Variable name | Description |
436+
|-----------------------------|:----------------------------------------------------------------------------------------------------------:|
437+
| `REACT_APP_DEFINITION_FILE` | Specifies a local file path, and the specified file must also be present in the `/public/static` directory |
438+
| `REACT_APP_DEFINITION_URL` | Specifies a remote URL. This environment variable currently takes precedence over `REACT_APP_SWAGGER_FILE` |
439+
| `REACT_APP_VERSION` | Specifies the version of this app. The version is read from `package.json` file. |
437440
441+
Sample environment variable values can be found in `.env` file. For more information about using
442+
environment variables, please refer to [adding Custom Environment Variables](https://create-react-app.dev/docs/adding-custom-environment-variables/)
443+
section of Create React App documentation.
438444
439445
## Docker
440446
Once we build the app, we can also build and run a Docker container.

package-lock.json

Lines changed: 1115 additions & 127 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
}
3333
},
3434
"scripts": {
35-
"start": "cross-env DISABLE_ESLINT_PLUGIN=true ENABLE_PROGRESS_PLUGIN=true react-scripts start",
35+
"start": "cross-env DISABLE_ESLINT_PLUGIN=false ENABLE_PROGRESS_PLUGIN=true react-scripts start",
3636
"build": "npm run build:app && npm run build:bundle:esm && npm run build:bundle:umd",
37-
"build:app": "cross-env ENABLE_PROGRESS_PLUGIN=false DISABLE_ESLINT_PLUGIN=false react-scripts build",
37+
"build:app": "cross-env NODE_OPTIONS='--max_old_space_size=4096' ENABLE_PROGRESS_PLUGIN=false DISABLE_ESLINT_PLUGIN=false react-scripts build",
3838
"build:app:serve": "serve -s build -l 3050",
3939
"build:bundle:esm": "rimraf ./dist/esm && cross-env DISABLE_ESLINT_PLUGIN=false ENABLE_PROGRESS_PLUGIN=false GENERATE_SOURCEMAP=true BUILD_ESM_BUNDLE=true DIST_PATH=dist/esm react-scripts build-bundle && rimraf ./dist/esm/swagger-editor.css*",
40-
"build:bundle:umd": "rimraf ./dist/umd ./dist/swagger-editor.css && cross-env DISABLE_ESLINT_PLUGIN=false ENABLE_PROGRESS_PLUGIN=false GENERATE_SOURCEMAP=false BUILD_UMD_BUNDLE=true DIST_PATH=dist/umd react-scripts build-bundle && copyfiles -u 2 ./dist/umd/swagger-editor.css ./dist && rimraf ./dist/umd/swagger-editor.css",
41-
"analyze": "source-map-explorer 'dist/umd/swagger-editor.js'",
40+
"build:bundle:umd": "rimraf ./dist/umd ./dist/swagger-editor.css && cross-env NODE_OPTIONS='--max_old_space_size=4096' DISABLE_ESLINT_PLUGIN=false ENABLE_PROGRESS_PLUGIN=false GENERATE_SOURCEMAP=false BUILD_UMD_BUNDLE=true DIST_PATH=dist/umd react-scripts build-bundle && copyfiles -u 2 ./dist/umd/swagger-editor.css ./dist && rimraf ./dist/umd/swagger-editor.css",
41+
"analyze": "source-map-explorer 'build/static/js/main.js'",
4242
"test": "react-scripts test",
4343
"cy:dev": "start-server-and-test cy:dev:server http://localhost:3003 cy:dev:open",
4444
"cy:dev:open": "CYPRESS_BASE_URL=http://localhost:3003 cypress open --e2e",
@@ -63,14 +63,19 @@
6363
"@mui/material": "^5.9.1",
6464
"@primer/octicons-react": "^17.3.0",
6565
"@swagger-api/apidom-ls": "^0.36.0",
66+
"@swagger-api/apidom-parser-adapter-asyncapi-json-2": "^0.35.0",
67+
"@swagger-api/apidom-parser-adapter-asyncapi-yaml-2": "^0.35.0",
68+
"@swagger-api/apidom-parser-adapter-openapi-json-3-1": "^0.35.0",
69+
"@swagger-api/apidom-parser-adapter-openapi-yaml-3-1": "^0.35.0",
6670
"axios": "^0.27.2",
71+
"classnames": "^2.3.1",
6772
"deepmerge": "^4.2.2",
6873
"file-dialog": "^0.0.8",
6974
"immutable": "^3.8.2",
7075
"is-json": "^2.0.1",
7176
"js-file-download": "^0.4.12",
7277
"js-yaml": "^4.1.0",
73-
"json-beautify": "^1.1.1",
78+
"lodash": "^4.17.21",
7479
"monaco-editor-core": "^0.33.0",
7580
"monaco-languageclient": "^2.1.0",
7681
"prop-types": "^15.8.1",
@@ -83,6 +88,7 @@
8388
"react-resize-detector": "^7.1.2",
8489
"react-table": "^7.8.0",
8590
"reselect": "^4.1.6",
91+
"short-unique-id": "^4.4.4",
8692
"styled-components": "^5.3.5",
8793
"swagger-ui-react": "^4.13.0",
8894
"vscode-languageserver-textdocument": "^1.0.5"

public/index.html

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4+
<link rel="preload" href="%PUBLIC_URL%/static/media/splash-screen/loader.gif" as="image" type="image/gif" />
5+
<link rel="preload" href="%PUBLIC_URL%/static/media/splash-screen/logo.svg" as="image" type="image/svg+xml" />
6+
<link rel="preload" href="%PUBLIC_URL%/static/media/splash-screen/styles.css" as="style" type="text/css" />
47
<meta charset="utf-8" />
5-
<link rel="icon" href="%PUBLIC_URL%/favicon-32x32.png" />
68
<meta name="viewport" content="width=device-width, initial-scale=1" />
79
<meta name="theme-color" content="#000000" />
810
<meta
911
name="description"
1012
content="SwaggerEditor"
1113
/>
14+
<link rel="icon" href="%PUBLIC_URL%/favicon-32x32.png" />
1215
<link rel="apple-touch-icon" href="%PUBLIC_URL%/favicon-32x32.png" />
16+
<link rel="stylesheet" href="%PUBLIC_URL%/static/media/splash-screen/styles.css" />
1317
<!--
1418
manifest.json provides metadata used when your web app is installed on a
1519
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
@@ -33,7 +37,23 @@
3337
</head>
3438
<body>
3539
<noscript>You need to enable JavaScript to run this app.</noscript>
36-
<div id="swagger-editor"></div>
40+
<div id="swagger-editor">
41+
<div class="swagger-editor">
42+
<div class="swagger-editor__splash-screen">
43+
<figure class="swagger-editor__splash-screen-figure">
44+
<img width="100%" src="%PUBLIC_URL%/static/media/splash-screen/logo.svg" alt="Swagger Editor" />
45+
<figcaption>%REACT_APP_VERSION%</figcaption>
46+
<img
47+
width="25"
48+
height="25"
49+
class="swagger-editor__splash-screen-spinner"
50+
src="%PUBLIC_URL%/static/media/splash-screen/loader.gif"
51+
alt="Loading..."
52+
/>
53+
</figure>
54+
</div>
55+
</div>
56+
</div>
3757
<!--
3858
This HTML file is a template.
3959
If you open it directly in the browser, you will see an empty page.
44.6 KB
Loading
File renamed without changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
html, body {
2+
width: 100%;
3+
height: 100%;
4+
margin: 0;
5+
padding: 0;
6+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
7+
}
8+
9+
.swagger-editor .swagger-editor__splash-screen {
10+
position: absolute;
11+
z-index: 10000;
12+
background-color: #173647;
13+
width: 100vw;
14+
height: 100vh;
15+
text-align: center;
16+
}
17+
18+
.swagger-editor .swagger-editor__splash-screen-figure {
19+
position: relative;
20+
top: calc(50% - 126px);
21+
width: 15vw;
22+
display: inline-block;
23+
color: lightslategrey;
24+
font-size: 0.8rem;
25+
font-weight: bold;
26+
}
27+
28+
.swagger-editor .swagger-editor__splash-screen-spinner {
29+
padding-top: 20px;
30+
}

0 commit comments

Comments
 (0)