yaml-dsl-spec 0.2.0 → 0.2.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
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
/* How a schema problem is worded: the field it names and the sentence about it. */
|
|
4
4
|
|
|
5
|
-
const { descriptionText } = require('./
|
|
5
|
+
const { descriptionText } = require('./requiredness-markers');
|
|
6
6
|
|
|
7
7
|
const DEPENDENCY_KEYWORDS = ['dependencies', 'dependentRequired', 'dependentSchemas'];
|
|
8
8
|
const SCHEMA_MAP_KEYWORDS = [
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
/*
|
|
4
|
-
*
|
|
4
|
+
* Requiredness markers: a field's `description` opening with `[required]`,
|
|
5
5
|
* `[~required]` or `[optional]` decides whether the field is required, over its
|
|
6
6
|
* parent's `required` array.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
const REQUIRED_MARKER = '[required]';
|
|
10
|
-
const
|
|
10
|
+
const REQUIREDNESS_MARKERS = [REQUIRED_MARKER, '[~required]', '[optional]'];
|
|
11
11
|
const CONDITION_KEYWORDS = new Set(['if', 'not']);
|
|
12
12
|
const FORM_SELECTING_KEYWORDS = new Set(['anyOf', 'oneOf']);
|
|
13
13
|
const SAME_INSTANCE_SCHEMA_KEYWORDS = new Set(['else', 'if', 'not', 'then']);
|
|
@@ -67,16 +67,16 @@ const DRAFT_KEYWORDS = {
|
|
|
67
67
|
const isObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
68
68
|
|
|
69
69
|
/** The marker a schema node's `description` opens with, or `null`. */
|
|
70
|
-
function
|
|
70
|
+
function requirednessMarker(node) {
|
|
71
71
|
if (!isObject(node) || typeof node.description !== 'string') return null;
|
|
72
72
|
const description = node.description.trimStart();
|
|
73
|
-
return
|
|
73
|
+
return REQUIREDNESS_MARKERS.find((marker) => description.startsWith(marker)) || null;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
/** A node's description without the marker it opens with, or `null`. */
|
|
77
77
|
function descriptionText(node) {
|
|
78
78
|
if (!isObject(node) || typeof node.description !== 'string') return null;
|
|
79
|
-
const marker =
|
|
79
|
+
const marker = requirednessMarker(node);
|
|
80
80
|
const text = marker ? node.description.trimStart().slice(marker.length) : node.description;
|
|
81
81
|
return text.trim() || null;
|
|
82
82
|
}
|
|
@@ -89,7 +89,7 @@ function markedSchema(schema, draftName) {
|
|
|
89
89
|
function markersOfFields(properties) {
|
|
90
90
|
const markers = new Map();
|
|
91
91
|
for (const [key, field] of Object.entries(properties)) {
|
|
92
|
-
const marker =
|
|
92
|
+
const marker = requirednessMarker(field);
|
|
93
93
|
if (marker) markers.set(key, marker);
|
|
94
94
|
}
|
|
95
95
|
return markers;
|
|
@@ -125,4 +125,4 @@ function markedNode(node, inheritedMarkers, keywords) {
|
|
|
125
125
|
return marked;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
module.exports = {
|
|
128
|
+
module.exports = { requirednessMarker, descriptionText, markedSchema };
|
package/lib/schema-validation.js
CHANGED
|
@@ -7,7 +7,7 @@ const AjvDraft202012 = require('ajv/dist/2020').default;
|
|
|
7
7
|
const { Diagnostic } = require('./diagnostic-report');
|
|
8
8
|
const { FunctionTable } = require('./function-table');
|
|
9
9
|
const { numberJson, integerOfText } = require('./yaml-node');
|
|
10
|
-
const { descriptionText, markedSchema } = require('./
|
|
10
|
+
const { descriptionText, markedSchema } = require('./requiredness-markers');
|
|
11
11
|
const { compilePattern } = require('./pattern-dialect');
|
|
12
12
|
const {
|
|
13
13
|
fieldName,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yaml-dsl-spec",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.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": {
|