Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: replace is-my-json-valid with Ajv (#8852)
* Upgrade: replace is-my-json-valid with Ajv This PR replaces the validation functionality. epoberezkin needs to have a look into how to handle the error message formatting. * Fix: error message code and messages in tests * Chore: use one instance of ajv, JSON-schema draft-04 compatibility * Chore: use meta-schema in ajv, disable default meta-schema validation * Chore: validate config-schema against meta-schema * Chore: compile config-schema only once * Fix: RuleTester error message for invalid schema * Fix: ignore missing $ref in schemas for backward compatibility
- Loading branch information
1 parent
7c8de92
commit 72f22eb
Showing
8 changed files
with
95 additions
and
184 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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,29 @@ | ||
/** | ||
* @fileoverview The instance of Ajv validator. | ||
* @author Evgeny Poberezkin | ||
*/ | ||
"use strict"; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
|
||
const Ajv = require("ajv"), | ||
metaSchema = require("ajv/lib/refs/json-schema-draft-04.json"); | ||
|
||
//------------------------------------------------------------------------------ | ||
// Public Interface | ||
//------------------------------------------------------------------------------ | ||
|
||
const ajv = new Ajv({ | ||
meta: false, | ||
validateSchema: false, | ||
missingRefs: "ignore", | ||
verbose: true | ||
}); | ||
|
||
ajv.addMetaSchema(metaSchema); | ||
// eslint-disable-next-line no-underscore-dangle | ||
ajv._opts.defaultMeta = metaSchema.id; | ||
|
||
module.exports = ajv; |
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,26 @@ | ||
/** | ||
* @fileoverview Tests for config-schema. | ||
* @author Evgeny Poberezkin | ||
*/ | ||
|
||
"use strict"; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
|
||
const ajv = require("../../lib/util/ajv"), | ||
configSchema = require("../../conf/config-schema.js"), | ||
assert = require("assert"); | ||
|
||
//------------------------------------------------------------------------------ | ||
// Tests | ||
//------------------------------------------------------------------------------ | ||
|
||
describe("config-schema", () => { | ||
it("should be valid against meta-schema", () => { | ||
const valid = ajv.validateSchema(configSchema); | ||
|
||
assert.strictEqual(valid, true); | ||
}); | ||
}); |
Oops, something went wrong.