Skip to content

Commit 2682582

Browse files
authored
Merge pull request #1609 from shockey/master
Validation improvements
2 parents 512a01d + 0f601a4 commit 2682582

File tree

17 files changed

+92
-42
lines changed

17 files changed

+92
-42
lines changed

src/index.js

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

66
import EditorPlugin from "./plugins/editor"
77
import LocalStoragePlugin from "./plugins/local-storage"
8-
import ValidatePlugin from "./plugins/validate"
8+
import ValidateBasePlugin from "./plugins/validate-base"
9+
import ValidateSemanticPlugin from "./plugins/validate-semantic"
910
import ValidateJsonSchemaPlugin from "./plugins/validate-json-schema"
1011
import EditorAutosuggestPlugin from "./plugins/editor-autosuggest"
1112
import EditorAutosuggestSnippetsPlugin from "./plugins/editor-autosuggest-snippets"
@@ -22,7 +23,8 @@ window.versions = window.versions || {}
2223
window.versions.swaggerEditor = `${PACKAGE_VERSION}/${GIT_COMMIT || "unknown"}${GIT_DIRTY ? "-dirty" : ""}`
2324
const plugins = {
2425
EditorPlugin,
25-
ValidatePlugin,
26+
ValidateBasePlugin,
27+
ValidateSemanticPlugin,
2628
ValidateJsonSchemaPlugin,
2729
LocalStoragePlugin,
2830
EditorAutosuggestPlugin,

src/plugins/validate-base/index.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Base validate plugin that provides a placeholder `validateSpec` that fires
2+
// after `updateResolved` is dispatched.
3+
4+
export const updateResolved = (ori, {specActions}) => (...args) => {
5+
ori(...args)
6+
/*
7+
To allow us to remove this, we should prefer the practice of
8+
only _composing_ inside of wrappedActions. It keeps us free to
9+
remove pieces added by plugins. In this case, I want to toggle validation.
10+
But I can't look inside the updateResolved action,
11+
I can only remove it ( which isn't desirable ). However I _can_ remove `validateSpec` action,
12+
making it a noop. That way, the only overhead I end up with is a bunch of noops inside wrappedActions.
13+
Which isn't bad.
14+
*/
15+
const [ spec ] = args
16+
specActions.validateSpec(spec)
17+
}
18+
19+
//eslint-disable-next-line no-unused-vars
20+
export const validateSpec = (resolvedSpec) => ({ specSelectors, errActions }) => {
21+
22+
}
23+
24+
export default function() {
25+
return {
26+
statePlugins: {
27+
spec: {
28+
actions: {
29+
validateSpec,
30+
},
31+
wrapActions: {
32+
updateResolved
33+
}
34+
}
35+
}
36+
}
37+
}

src/plugins/validate-json-schema/apis/index.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,6 @@ import { makeValidationWorker } from "../helpers"
44

55
let debouncedValidation = makeValidationWorker()
66

7-
export const updateResolved = (ori, {specActions}) => (...args) => {
8-
ori(...args)
9-
/*
10-
To allow us to remove this, we should prefer the practice of
11-
only _composing_ inside of wrappedActions. It keeps us free to
12-
remove pieces added by plugins. In this case, I want to toggle validation.
13-
But I can't look inside the updateResolved action,
14-
I can only remove it ( which isn't desirable ). However I _can_ remove `validateSpec` action,
15-
making it a noop. That way, the only overhead I end up with is a bunch of noops inside wrappedActions.
16-
Which isn't bad.
17-
*/
18-
const [ spec ] = args
19-
specActions.validateSpec(spec)
20-
}
21-
227
export const validateSpec = (resolvedSpec) => ({ specSelectors, errActions }) => {
238
const isOAS3 = specSelectors.isOAS3 ? specSelectors.isOAS3() : false
249
const ourMode = isOAS3 ? "oas3" : "swagger2"
@@ -31,9 +16,6 @@ export default function() {
3116
spec: {
3217
actions: {
3318
validateSpec,
34-
},
35-
wrapActions: {
36-
updateResolved
3719
}
3820
}
3921
}

src/plugins/validate-json-schema/modes.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ export default {
55
"swagger2": {
66
schemas: [swagger2Schema], // the swagger2 schema references itself by URL, so we have to preload it
77
testSchema: swagger2Schema,
8-
runStructural: true,
9-
runSemantic: true
8+
runStructural: true
109
},
1110
"oas3": {
1211
schemas: [oas3Schema],
1312
testSchema: oas3Schema,
14-
runStructural: true,
15-
runSemantic: false
13+
runStructural: true
1614
}
1715
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)