Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: added the link property in validation error
  • Loading branch information
snitin315 committed Jun 30, 2021
1 parent b281bb1 commit 589aa59
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions declarations/validate.d.ts
Expand Up @@ -7,6 +7,7 @@ export type Extend = {
formatMaximum?: number | undefined;
formatExclusiveMinimum?: boolean | undefined;
formatExclusiveMaximum?: boolean | undefined;
link?: string | undefined;
};
export type Schema = (JSONSchema4 | JSONSchema6 | JSONSchema7) & Extend;
export type SchemaUtilErrorObject = ErrorObject & {
Expand Down
4 changes: 4 additions & 0 deletions src/ValidationError.js
Expand Up @@ -852,6 +852,10 @@ class ValidationError extends Error {
schemaText += `\n-> ${schemaPart.description}`;
}

if (schemaPart.link) {
schemaText += `\n-> Read more at ${schemaPart.link}`;
}

return schemaText;
}

Expand Down
1 change: 1 addition & 0 deletions src/validate.js
Expand Up @@ -17,6 +17,7 @@ const ajvKeywords = require("ajv-keywords");
* @property {number=} formatMaximum
* @property {boolean=} formatExclusiveMinimum
* @property {boolean=} formatExclusiveMaximum
* @property {string=} link
*/

/** @typedef {(JSONSchema4 | JSONSchema6 | JSONSchema7) & Extend} Schema */
Expand Down
2 changes: 2 additions & 0 deletions test/__snapshots__/index.test.js.snap
Expand Up @@ -626,6 +626,7 @@ exports[`Validation should fail validation for enum 1`] = `
- configuration.devtool should be one of these:
string | false
-> A developer tool to enhance debugging.
-> Read more at https://webpack.js.org/configuration/devtool/
Details:
* configuration.devtool should be a string.
* configuration.devtool should be false."
Expand Down Expand Up @@ -1537,6 +1538,7 @@ exports[`Validation should fail validation for oneOf #1 1`] = `
- configuration.entry should be one of these:
function | object { <key>: non-empty string | [non-empty string, ...] (should not have fewer than 1 item, should not have duplicate items) } (should not have fewer than 1 property) | non-empty string | [non-empty string, ...] (should not have fewer than 1 item, should not have duplicate items)
-> The entry point(s) of the compilation.
-> Read more at https://webpack.js.org/configuration/entry-context/#entry
Details:
* configuration.entry['foo'] should be one of these:
non-empty string | [non-empty string, ...] (should not have fewer than 1 item, should not have duplicate items)
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/schema.json
Expand Up @@ -2081,6 +2081,7 @@
},
"devtool": {
"description": "A developer tool to enhance debugging.",
"link": "https://webpack.js.org/configuration/devtool/",
"anyOf": [
{
"type": "string"
Expand All @@ -2092,6 +2093,7 @@
},
"entry": {
"description": "The entry point(s) of the compilation.",
"link": "https://webpack.js.org/configuration/entry-context/#entry",
"anyOf": [
{
"$ref": "#/definitions/Entry"
Expand Down

0 comments on commit 589aa59

Please sign in to comment.