Skip to content

Commit 75b241e

Browse files
committed
Make validators more robust; less error-prone
1 parent 74411ee commit 75b241e

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

src/plugins/validation/semantic-validators/validators/operations.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export function validate({ resolvedSpec }) {
1717
let pathOps = pick(path, ["get", "head", "post", "put", "patch", "delete", "options"])
1818
each(pathOps, (op, opKey) => {
1919

20+
if(!op) {
21+
return
22+
}
23+
2024
// Assertation 1
2125
let bodyParamIndex = findIndex(op.parameters, ["in", "body"])
2226
let formDataParamIndex = findIndex(op.parameters, ["in", "formData"])

src/plugins/validation/semantic-validators/validators/paths.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function validate({ resolvedSpec }) {
4141
}
4242

4343
each(resolvedSpec.paths, (path, pathName) => {
44-
if(!path) {
44+
if(!path || !pathName) {
4545
return
4646
}
4747

@@ -73,7 +73,7 @@ export function validate({ resolvedSpec }) {
7373
})
7474

7575
each(path, (thing, thingName) => {
76-
if(thing.parameters) {
76+
if(thing && thing.parameters) {
7777
availableParameters.push(...thing.parameters.map((param, i) => {
7878
if(!isObject(param)) {
7979
return

src/plugins/validation/semantic-validators/validators/schema.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function validate({ resolvedSpec }) {
1616
if(resolvedSpec.paths) {
1717
each(resolvedSpec.paths, (path, pathName) => {
1818
each(path, (op, opName) => {
19-
if(op.parameters) {
19+
if(op && op.parameters) {
2020
op.parameters.forEach((parameter, parameterIndex) => {
2121
if(parameter.in === "body" && parameter.schema) {
2222
schemas.push({
@@ -26,9 +26,9 @@ export function validate({ resolvedSpec }) {
2626
}
2727
})
2828
}
29-
if(op.responses) {
29+
if(op && op.responses) {
3030
each(op.responses, (response, responseName) => {
31-
if(response.schema) {
31+
if(response && response.schema) {
3232
schemas.push({
3333
schema: response.schema,
3434
path: ["paths", pathName, opName, "responses", responseName, "schema"]

src/plugins/validation/semantic-validators/validators/walker.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ export function validate({ jsSpec }) {
1414

1515
function walk(value, path) {
1616
let curr = path[path.length - 1]
17+
18+
if(typeof value !== "object" || value === null) {
19+
return
20+
}
21+
1722
///// "type" should always be a string, everywhere.
1823
if(curr === "type" && ["definitions", "properties"].indexOf(path[path.length - 2]) === -1) {
1924
if(typeof value !== "string") {
@@ -73,10 +78,6 @@ export function validate({ jsSpec }) {
7378
}
7479
}
7580

76-
if(typeof value !== "object" || value === null) {
77-
return
78-
}
79-
8081
let keys = Object.keys(value)
8182

8283
if(keys.length) {

0 commit comments

Comments
 (0)