-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
336 additions
and
100 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const jsonPointer = require("../json-pointer"); | ||
|
||
/** | ||
* @this {import('src').Context} | ||
* @param {*} value | ||
* @param {*} currentSchema | ||
* @param {(string | number)[]} position | ||
*/ | ||
function validateRef(value, currentSchema, position) { | ||
const match = currentSchema.$ref.match(/^#\/(.*)$/); | ||
if (match && match[1]) { | ||
const schema = jsonPointer(this.schema, match[1].split("/")); | ||
this.validateSchema(value, position, schema); | ||
return; | ||
} | ||
} | ||
|
||
module.exports = validateRef; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const validateItems = require("../items"); | ||
|
||
/** | ||
* @this {import('src').Context} | ||
* @param {*} value | ||
* @param {*} currentSchema | ||
* @param {(string | number)[]} position | ||
*/ | ||
function validateArray(value, currentSchema, position) { | ||
if (!Array.isArray(value)) { | ||
this.error('Incorrect type. Expected "array".', "type", position); | ||
return; | ||
} | ||
|
||
if (!this.shallow && currentSchema.items) { | ||
validateItems.call(this, value, currentSchema.items, position); | ||
} | ||
} | ||
|
||
module.exports = validateArray; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const validateEnum = require("../enum"); | ||
|
||
/** | ||
* @this {import('src').Context} | ||
* @param {*} value | ||
* @param {*} currentSchema | ||
* @param {(string | number)[]} position | ||
*/ | ||
function validateBoolean(value, currentSchema, position) { | ||
if (typeof value !== "boolean") { | ||
this.error(`"${value}" should be boolean`, "type", position); | ||
return; | ||
} | ||
|
||
if (currentSchema.enum) { | ||
validateEnum.call(this, value, currentSchema.enum, position); | ||
} | ||
} | ||
|
||
module.exports = validateBoolean; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const validateEnum = require("../enum"); | ||
|
||
/** | ||
* @this {import('src').Context} | ||
* @param {*} value | ||
* @param {*} currentSchema | ||
* @param {(string | number)[]} position | ||
*/ | ||
function validateMultiple(value, currentSchema, position) { | ||
let errorCount = 0; | ||
let skip = false; | ||
|
||
for (const type of currentSchema.type) { | ||
try { | ||
this.validateSchema.call( | ||
{...this, shallow: true}, | ||
value, | ||
position, | ||
{ | ||
type, | ||
}, | ||
); | ||
skip = true; | ||
break; | ||
} catch (e) { | ||
errorCount++; | ||
} | ||
} | ||
|
||
if (!skip && errorCount >= currentSchema.type.length) { | ||
this.error( | ||
`"${value}" should be ${currentSchema.type.join(" or ")}`, | ||
"type", | ||
position, | ||
); | ||
} | ||
|
||
if (currentSchema.enum) { | ||
validateEnum.call(this, value, currentSchema.enum, position); | ||
} | ||
} | ||
|
||
module.exports = validateMultiple; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const validateEnum = require("../enum"); | ||
|
||
/** | ||
* @this {import('src').Context} | ||
* @param {*} value | ||
* @param {*} currentSchema | ||
* @param {(string | number)[]} position | ||
*/ | ||
function validateNull(value, currentSchema, position) { | ||
if (value !== null) { | ||
this.error(`"${value}" should be null`, "type", position); | ||
return; | ||
} | ||
|
||
if (currentSchema.enum) { | ||
validateEnum.call(this, value, currentSchema.enum, position); | ||
} | ||
} | ||
|
||
module.exports = validateNull; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const validateEnum = require("../enum"); | ||
|
||
/** | ||
* @this {import('src').Context} | ||
* @param {*} value | ||
* @param {*} currentSchema | ||
* @param {(string | number)[]} position | ||
*/ | ||
function validateNumber(value, currentSchema, position) { | ||
if (typeof value !== "number") { | ||
this.error(`"${value}" should be number`, "type", position); | ||
return; | ||
} | ||
|
||
if (currentSchema.enum) { | ||
validateEnum.call(this, value, currentSchema.enum, position); | ||
} | ||
} | ||
|
||
module.exports = validateNumber; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const validateRequired = require("../required"); | ||
const validateProperties = require("../properties"); | ||
|
||
/** | ||
* @this {import('src').Context} | ||
* @param {*} value | ||
* @param {*} currentSchema | ||
* @param {(string | number)[]} position | ||
*/ | ||
function validateObject(value, currentSchema, position) { | ||
if (!value || typeof value !== "object" || Array.isArray(value)) { | ||
this.error('Incorrect type. Expected "object".', "type", position); | ||
return; | ||
} | ||
|
||
if (!this.shallow && currentSchema.required) { | ||
validateRequired.call(this, value, currentSchema.required, position); | ||
} | ||
|
||
if (currentSchema.properties) { | ||
validateProperties.call(this, value, currentSchema, position); | ||
} | ||
} | ||
|
||
module.exports = validateObject; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const validateEnum = require("../enum"); | ||
|
||
/** | ||
* @this {import('src').Context} | ||
* @param {*} value | ||
* @param {*} currentSchema | ||
* @param {(string | number)[]} position | ||
*/ | ||
function validateString(value, currentSchema, position) { | ||
if (typeof value !== "string") { | ||
this.error(`"${value}" should be string`, "type", position); | ||
return; | ||
} | ||
|
||
if (currentSchema.enum) { | ||
validateEnum.call(this, value, currentSchema.enum, position); | ||
} | ||
} | ||
|
||
module.exports = validateString; |
Oops, something went wrong.