Skip to content

Commit 12a9c3b

Browse files
authored
Merge pull request #1517 from swagger-api/feature/validation-refactor-pr
Refactor validation plugin into a pluggable system itself.
2 parents dba2a32 + dbf8563 commit 12a9c3b

Some content is hidden

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

63 files changed

+2890
-3801
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"rules": {
2323
"semi": [2, "never"],
2424
"strict": 0,
25-
"quotes": 2,
25+
"quotes": [2, "double", { "allowTemplateLiterals": true }],
2626
"no-unused-vars": 2,
2727
"no-multi-spaces": 1,
2828
"camelcase": 1,

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"test-in-node": "npm run lint-errors && npm run just-test-in-node",
3535
"just-test": "karma start --config karma.conf.js",
3636
"just-test-in-node": "mocha --recursive --compilers js:babel-core/register test",
37+
"just-test-in-node-watch": "npm run just-test-in-node -- -w",
3738
"serve-static": "http-server -i -a 0.0.0.0 -p 3001",
3839
"prestart": "npm install",
3940
"start": "npm-run-all --parallel serve-static open-static",
@@ -42,7 +43,6 @@
4243
"dependencies": {
4344
"ajv": "^5.2.2",
4445
"boron": "^0.2.3",
45-
"bowser": "1.6.1",
4646
"classnames": "^2.1.3",
4747
"core-js": "^2.4.1",
4848
"deepmerge": "^1.3.2",
@@ -60,6 +60,7 @@
6060
"redux": "^3.x.x",
6161
"swagger-client": "^3.4.2",
6262
"swagger-ui": "^3.7.0",
63+
"traverse": "^0.6.6",
6364
"whatwg-fetch": "^2.0.3"
6465
},
6566
"devDependencies": {

src/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import "swagger-ui/dist/swagger-ui.css"
55

66
import EditorPlugin from "./plugins/editor"
77
import LocalStoragePlugin from "./plugins/local-storage"
8-
import ValidationPlugin from "./plugins/validation"
9-
import ValidationApiPlugin from "./plugins/validation/apis"
8+
import ValidatePlugin from "./plugins/validate"
9+
import ValidateJsonSchemaPlugin from "./plugins/validate-json-schema"
1010
import EditorAutosuggestPlugin from "./plugins/editor-autosuggest"
1111
import EditorAutosuggestSnippetsPlugin from "./plugins/editor-autosuggest-snippets"
1212
import EditorAutosuggestKeywordsPlugin from "./plugins/editor-autosuggest-keywords"
1313
import EditorAutosuggestOAS3KeywordsPlugin from "./plugins/editor-autosuggest-oas3-keywords"
1414
import EditorAutosuggestRefsPlugin from "./plugins/editor-autosuggest-refs"
15+
import PerformancePlugin from "./plugins/performance"
1516
import JumpToPathPlugin from "./plugins/jump-to-path"
1617

1718
// eslint-disable-next-line no-undef
@@ -21,14 +22,15 @@ window.versions = window.versions || {}
2122
window.versions.swaggerEditor = `${PACKAGE_VERSION}/${GIT_COMMIT || "unknown"}${GIT_DIRTY ? "-dirty" : ""}`
2223
const plugins = {
2324
EditorPlugin,
24-
ValidationPlugin,
25-
ValidationApiPlugin,
25+
ValidatePlugin,
26+
ValidateJsonSchemaPlugin,
2627
LocalStoragePlugin,
2728
EditorAutosuggestPlugin,
2829
EditorAutosuggestSnippetsPlugin,
2930
EditorAutosuggestKeywordsPlugin,
3031
EditorAutosuggestRefsPlugin,
3132
EditorAutosuggestOAS3KeywordsPlugin,
33+
PerformancePlugin,
3234
JumpToPathPlugin,
3335
}
3436

src/plugins/performance/index.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
const getTimestamp = ((that) => {
2+
if(that.performance && that.performance.now) {
3+
return that.performance.now.bind(that.performance)
4+
}
5+
return Date.now.bind(Date)
6+
})(self || window)
7+
8+
export default function PerformancePlugin() {
9+
if(!(window || {}).LOG_PERF) {
10+
return {
11+
fn: {
12+
getTimestamp,
13+
Timer: TimerStub,
14+
timeCall: (name,fn) => fn(),
15+
}
16+
}
17+
}
18+
19+
return {
20+
fn: {
21+
getTimestamp,
22+
Timer,
23+
timeCall,
24+
}
25+
}
26+
}
27+
28+
function timeCall(name,fn) {
29+
fn = fn || name
30+
name = typeof name === "function" ? "that" : name
31+
const a = getTimestamp()
32+
const r = fn()
33+
const b = getTimestamp()
34+
console.log(name,"took", b - a, "ms") // eslint-disable-line no-console
35+
return r
36+
}
37+
38+
function TimerStub() {
39+
this.start = this.mark = this.print = Function.prototype
40+
}
41+
42+
function Timer(name, _getTimestamp=getTimestamp) {
43+
this._name = name
44+
this.getTimestamp = _getTimestamp
45+
this._markers = []
46+
this.start()
47+
}
48+
49+
Timer.prototype.start = function() {
50+
this._start = this.getTimestamp()
51+
}
52+
53+
Timer.prototype.mark = function(name) {
54+
this._markers = this._markers || []
55+
this._markers.push({
56+
time: this.getTimestamp(),
57+
name
58+
})
59+
}
60+
61+
Timer.prototype.print = function(name) {
62+
this.mark(name)
63+
this._markers.forEach(m => {
64+
// eslint-disable-next-line no-console
65+
console.log(this._name, m.name, m.time - this._start, "ms")
66+
})
67+
this._markers = []
68+
this.start()
69+
}

src/plugins/validation/helpers.js renamed to src/plugins/validate-json-schema/helpers.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ export function makeValidationWorker() {
2626
errActions.clear({
2727
source: "schema"
2828
})
29-
errActions.clear({
30-
source: "semantic"
31-
})
3229

3330
// Filter out anything funky
3431
validationErrors = validationErrors
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Apis from "./apis"
2+
3+
export default function ValidateJsonSchemaPlugin() {
4+
return Apis
5+
}
File renamed without changes.

0 commit comments

Comments
 (0)