yaml-dsl-spec 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/problem-wording.js +14 -0
- package/lib/schema-validation.js +11 -7
- package/package.json +1 -1
package/lib/problem-wording.js
CHANGED
|
@@ -99,6 +99,19 @@ function definitionDescription(schema, holderPointer) {
|
|
|
99
99
|
return descriptionText(schemaNodeAt(schema, holderPointer));
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
/**
|
|
103
|
+
* The constants an `anyOf` or `oneOf` allows, in the schema's order, where every
|
|
104
|
+
* alternative states a `const`; else `null`.
|
|
105
|
+
*/
|
|
106
|
+
function alternativeConstants(alternatives) {
|
|
107
|
+
if (!Array.isArray(alternatives) || alternatives.length === 0) return null;
|
|
108
|
+
const statesConstant = (alternative) => alternative !== null && typeof alternative === 'object'
|
|
109
|
+
&& Object.prototype.hasOwnProperty.call(alternative, 'const');
|
|
110
|
+
return alternatives.every(statesConstant)
|
|
111
|
+
? alternatives.map((alternative) => alternative.const)
|
|
112
|
+
: null;
|
|
113
|
+
}
|
|
114
|
+
|
|
102
115
|
/**
|
|
103
116
|
* The dependency keyword's pointer and the key it names, `{ keywordPointer, key }`,
|
|
104
117
|
* where `keywordPointer` lies inside a dependency: the key read from the pointer,
|
|
@@ -367,6 +380,7 @@ module.exports = {
|
|
|
367
380
|
codeSpan,
|
|
368
381
|
numberText,
|
|
369
382
|
definitionDescription,
|
|
383
|
+
alternativeConstants,
|
|
370
384
|
dependencyOf,
|
|
371
385
|
dependencyMessage,
|
|
372
386
|
duplicateItems,
|
package/lib/schema-validation.js
CHANGED
|
@@ -15,6 +15,7 @@ const {
|
|
|
15
15
|
codeSpan,
|
|
16
16
|
numberText,
|
|
17
17
|
definitionDescription,
|
|
18
|
+
alternativeConstants,
|
|
18
19
|
dependencyOf,
|
|
19
20
|
dependencyMessage,
|
|
20
21
|
duplicateItems,
|
|
@@ -453,8 +454,7 @@ class LoadedSchema {
|
|
|
453
454
|
.withHelp(suggestion(name, allowed)),
|
|
454
455
|
}];
|
|
455
456
|
}
|
|
456
|
-
|
|
457
|
-
const options = Array.isArray(error.schema) ? error.schema : [];
|
|
457
|
+
const listedValueProblems = (options, schemaNote = null) => {
|
|
458
458
|
const allowed = options.filter((option) => typeof option === 'string');
|
|
459
459
|
const shown = options.map((option) => codeSpan(jsonText(option))).join(', ');
|
|
460
460
|
return [{
|
|
@@ -463,10 +463,14 @@ class LoadedSchema {
|
|
|
463
463
|
instance.valuePosition(pointer),
|
|
464
464
|
`${field} must be one of ${shown}`,
|
|
465
465
|
)
|
|
466
|
-
.withLabel(`not one of the ${options.length} values
|
|
466
|
+
.withLabel(`not one of the ${options.length} values ${codeSpan(error.keyword)} allows`)
|
|
467
467
|
.withRule(rule)
|
|
468
|
+
.withSchema(schemaNote)
|
|
468
469
|
.withHelp(typeof error.data === 'string' ? suggestion(error.data, allowed) : null),
|
|
469
470
|
}];
|
|
471
|
+
};
|
|
472
|
+
if (error.keyword === 'enum') {
|
|
473
|
+
return listedValueProblems(Array.isArray(error.schema) ? error.schema : []);
|
|
470
474
|
}
|
|
471
475
|
if (error.keyword === 'type') {
|
|
472
476
|
const expected = [].concat(error.schema).map(codeSpan);
|
|
@@ -494,10 +498,10 @@ class LoadedSchema {
|
|
|
494
498
|
return atValue(`${field} matches more than one of its allowed forms`);
|
|
495
499
|
}
|
|
496
500
|
const holderPointer = schemaPointer.slice(0, schemaPointer.lastIndexOf('/'));
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
);
|
|
501
|
+
const definitionNote = definitionDescription(this.schema, holderPointer);
|
|
502
|
+
const constants = alternativeConstants(error.schema);
|
|
503
|
+
if (constants !== null) return listedValueProblems(constants, definitionNote);
|
|
504
|
+
return atValue(`${field} matches none of its allowed forms`, definitionNote);
|
|
501
505
|
}
|
|
502
506
|
if (hasOwn(BOUND_COMPARISONS, error.keyword)) {
|
|
503
507
|
const comparison = BOUND_COMPARISONS[error.keyword];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yaml-dsl-spec",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "The YAML DSL standard: the JSON Schemas of yaml-dsl.yml and of a DSL's function table, and a reader returning a yaml-dsl.yml's DSL definitions validated.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|