@speclynx/apidom-ns-json-schema-draft-6 1.12.1 → 2.0.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/CHANGELOG.md +25 -0
- package/NOTICE +16 -7
- package/README.md +24 -24
- package/dist/apidom-ns-json-schema-draft-6.browser.js +1 -1
- package/package.json +11 -9
- package/src/elements/JSONSchema.cjs +14 -6
- package/src/elements/JSONSchema.mjs +14 -6
- package/src/elements/LinkDescription.cjs +4 -0
- package/src/elements/LinkDescription.mjs +4 -0
- package/src/index.cjs +8 -21
- package/src/index.mjs +2 -5
- package/src/predicates.cjs +4 -15
- package/src/predicates.mjs +2 -15
- package/src/refractor/index.cjs +38 -17
- package/src/refractor/index.mjs +33 -15
- package/src/refractor/inspect.cjs +47 -0
- package/src/refractor/inspect.mjs +39 -0
- package/src/refractor/plugins/replace-empty-element.cjs +28 -26
- package/src/refractor/plugins/replace-empty-element.mjs +14 -11
- package/src/refractor/specification.cjs +14 -2
- package/src/refractor/specification.mjs +14 -2
- package/src/refractor/toolbox.cjs +8 -3
- package/src/refractor/toolbox.mjs +6 -2
- package/src/refractor/visitors/json-schema/ExamplesVisitor.cjs +2 -3
- package/src/refractor/visitors/json-schema/ExamplesVisitor.mjs +2 -3
- package/src/refractor/visitors/json-schema/ItemsVisitor.cjs +3 -4
- package/src/refractor/visitors/json-schema/ItemsVisitor.mjs +3 -4
- package/src/refractor/visitors/json-schema/index.cjs +4 -3
- package/src/refractor/visitors/json-schema/index.mjs +4 -3
- package/src/refractor/visitors/json-schema/link-description/index.cjs +2 -0
- package/src/refractor/visitors/json-schema/link-description/index.mjs +2 -0
- package/types/apidom-ns-json-schema-draft-6.d.ts +90 -245
- package/src/refractor/registration.cjs +0 -13
- package/src/refractor/registration.mjs +0 -6
- package/src/traversal/visitor.cjs +0 -17
- package/src/traversal/visitor.mjs +0 -13
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { ArrayElement, ObjectElement,
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*/
|
|
1
|
+
import { ArrayElement, ObjectElement, isArrayElement, isElement, isMemberElement, isStringElement, includesClasses, cloneDeep, SourceMapElement } from '@speclynx/apidom-datamodel';
|
|
2
|
+
import { toValue } from '@speclynx/apidom-core';
|
|
3
|
+
import { getNodeType } from '@speclynx/apidom-traverse';
|
|
5
4
|
import { MediaElement } from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
6
5
|
import JSONSchemaElement from "../../elements/JSONSchema.mjs";
|
|
7
6
|
import LinkDescriptionElement from "../../elements/LinkDescription.mjs";
|
|
8
|
-
import { getNodeType } from "../../traversal/visitor.mjs";
|
|
9
7
|
/**
|
|
10
8
|
* This plugin is specific to YAML 1.2 format, which allows defining key-value pairs
|
|
11
9
|
* with empty key, empty value, or both. If the value is not provided in YAML format,
|
|
@@ -39,7 +37,7 @@ import { getNodeType } from "../../traversal/visitor.mjs";
|
|
|
39
37
|
* (StringElement)
|
|
40
38
|
* (JSONSchemaElement))
|
|
41
39
|
*/
|
|
42
|
-
const isEmptyElement = element => isStringElement(element) && includesClasses(['yaml-e-node', 'yaml-e-scalar']
|
|
40
|
+
const isEmptyElement = element => isStringElement(element) && includesClasses(element, ['yaml-e-node', 'yaml-e-scalar']);
|
|
43
41
|
const schema = {
|
|
44
42
|
JSONSchemaDraft6Element: {
|
|
45
43
|
additionalItems(...args) {
|
|
@@ -182,9 +180,12 @@ const findElementFactory = (ancestor, keyName) => {
|
|
|
182
180
|
*/
|
|
183
181
|
const plugin = () => () => ({
|
|
184
182
|
visitor: {
|
|
185
|
-
StringElement(
|
|
186
|
-
|
|
187
|
-
|
|
183
|
+
StringElement(path) {
|
|
184
|
+
const element = path.node;
|
|
185
|
+
if (!isEmptyElement(element)) return;
|
|
186
|
+
|
|
187
|
+
// getAncestorNodes() returns [parent, grandparent, ..., root], so reverse to get [root, ..., parent]
|
|
188
|
+
const lineage = path.getAncestorNodes().reverse().filter(isElement);
|
|
188
189
|
const parentElement = lineage.at(-1);
|
|
189
190
|
let elementFactory;
|
|
190
191
|
let context;
|
|
@@ -197,10 +198,12 @@ const plugin = () => () => ({
|
|
|
197
198
|
}
|
|
198
199
|
|
|
199
200
|
// no element factory found
|
|
200
|
-
if (typeof elementFactory !== 'function') return
|
|
201
|
-
|
|
201
|
+
if (typeof elementFactory !== 'function') return;
|
|
202
|
+
const replacement = elementFactory.call({
|
|
202
203
|
context
|
|
203
204
|
}, undefined, cloneDeep(element.meta), cloneDeep(element.attributes));
|
|
205
|
+
SourceMapElement.transfer(element, replacement);
|
|
206
|
+
path.replaceWith(replacement);
|
|
204
207
|
}
|
|
205
208
|
}
|
|
206
209
|
});
|
|
@@ -11,7 +11,19 @@ var _ExamplesVisitor = _interopRequireDefault(require("./visitors/json-schema/Ex
|
|
|
11
11
|
var _index2 = _interopRequireDefault(require("./visitors/json-schema/link-description/index.cjs"));
|
|
12
12
|
const specification = (0, _ramda.pipe)(
|
|
13
13
|
// JSON Schema object modifications
|
|
14
|
-
(0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', '
|
|
14
|
+
(0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'element'], 'jSONSchemaDraft6'), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', '$visitor'], _index.default), (0, _ramda.dissocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'id']), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', '$id'], {
|
|
15
|
+
$ref: '#/visitors/value'
|
|
16
|
+
}), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'contains'], {
|
|
17
|
+
$visitor: _apidomNsJsonSchemaDraft.specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor,
|
|
18
|
+
alias: 'containsField'
|
|
19
|
+
}), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'items'], {
|
|
20
|
+
$visitor: _ItemsVisitor.default,
|
|
21
|
+
alias: 'itemsField'
|
|
22
|
+
}), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'propertyNames'], _apidomNsJsonSchemaDraft.specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'const'], {
|
|
23
|
+
$ref: '#/visitors/value'
|
|
24
|
+
}), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'examples'], _ExamplesVisitor.default),
|
|
15
25
|
// Link Description object modifications
|
|
16
|
-
(0, _ramda.assocPath)(['visitors', 'document', 'objects', 'LinkDescription', '$visitor'], _index2.default), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'hrefSchema'], _apidomNsJsonSchemaDraft.specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor), (0, _ramda.dissocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'schema']), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'submissionSchema'], _apidomNsJsonSchemaDraft.specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor), (0, _ramda.dissocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'method']), (0, _ramda.dissocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'encType']), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'submissionEncType'],
|
|
26
|
+
(0, _ramda.assocPath)(['visitors', 'document', 'objects', 'LinkDescription', '$visitor'], _index2.default), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'hrefSchema'], _apidomNsJsonSchemaDraft.specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor), (0, _ramda.dissocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'schema']), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'submissionSchema'], _apidomNsJsonSchemaDraft.specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor), (0, _ramda.dissocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'method']), (0, _ramda.dissocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'encType']), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'submissionEncType'], {
|
|
27
|
+
$ref: '#/visitors/value'
|
|
28
|
+
}))(_apidomNsJsonSchemaDraft.specificationObj);
|
|
17
29
|
var _default = exports.default = specification;
|
|
@@ -6,7 +6,19 @@ import JSONSchemaExamplesVisitor from "./visitors/json-schema/ExamplesVisitor.mj
|
|
|
6
6
|
import LinkDescriptionVisitor from "./visitors/json-schema/link-description/index.mjs";
|
|
7
7
|
const specification = pipe(
|
|
8
8
|
// JSON Schema object modifications
|
|
9
|
-
assocPath(['visitors', 'document', 'objects', 'JSONSchema', '
|
|
9
|
+
assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'element'], 'jSONSchemaDraft6'), assocPath(['visitors', 'document', 'objects', 'JSONSchema', '$visitor'], JSONSchemaVisitor), dissocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'id']), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', '$id'], {
|
|
10
|
+
$ref: '#/visitors/value'
|
|
11
|
+
}), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'contains'], {
|
|
12
|
+
$visitor: specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor,
|
|
13
|
+
alias: 'containsField'
|
|
14
|
+
}), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'items'], {
|
|
15
|
+
$visitor: JSONSchemaItemsVisitor,
|
|
16
|
+
alias: 'itemsField'
|
|
17
|
+
}), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'propertyNames'], specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'const'], {
|
|
18
|
+
$ref: '#/visitors/value'
|
|
19
|
+
}), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'examples'], JSONSchemaExamplesVisitor),
|
|
10
20
|
// Link Description object modifications
|
|
11
|
-
assocPath(['visitors', 'document', 'objects', 'LinkDescription', '$visitor'], LinkDescriptionVisitor), assocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'hrefSchema'], specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor), dissocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'schema']), assocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'submissionSchema'], specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor), dissocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'method']), dissocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'encType']), assocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'submissionEncType'],
|
|
21
|
+
assocPath(['visitors', 'document', 'objects', 'LinkDescription', '$visitor'], LinkDescriptionVisitor), assocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'hrefSchema'], specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor), dissocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'schema']), assocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'submissionSchema'], specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor), dissocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'method']), dissocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'encType']), assocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'submissionEncType'], {
|
|
22
|
+
$ref: '#/visitors/value'
|
|
23
|
+
}))(specificationObj);
|
|
12
24
|
export default specification;
|
|
@@ -4,15 +4,20 @@ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequ
|
|
|
4
4
|
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
|
|
5
5
|
exports.__esModule = true;
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
8
8
|
var jsonSchemaDraft6Predicates = _interopRequireWildcard(require("../predicates.cjs"));
|
|
9
9
|
var _namespace = _interopRequireDefault(require("../namespace.cjs"));
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
|
|
10
14
|
const createToolbox = () => {
|
|
11
|
-
const namespace =
|
|
15
|
+
const namespace = new _apidomDatamodel.Namespace();
|
|
12
16
|
const predicates = {
|
|
13
17
|
...jsonSchemaDraft6Predicates,
|
|
14
|
-
isStringElement:
|
|
18
|
+
isStringElement: _apidomDatamodel.isStringElement
|
|
15
19
|
};
|
|
20
|
+
namespace.use(_namespace.default);
|
|
16
21
|
return {
|
|
17
22
|
predicates,
|
|
18
23
|
namespace
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isStringElement, Namespace } from '@speclynx/apidom-datamodel';
|
|
2
2
|
import * as jsonSchemaDraft6Predicates from "../predicates.mjs";
|
|
3
3
|
import jsonSchemaDraft6Namespace from "../namespace.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
4
7
|
const createToolbox = () => {
|
|
5
|
-
const namespace =
|
|
8
|
+
const namespace = new Namespace();
|
|
6
9
|
const predicates = {
|
|
7
10
|
...jsonSchemaDraft6Predicates,
|
|
8
11
|
isStringElement
|
|
9
12
|
};
|
|
13
|
+
namespace.use(jsonSchemaDraft6Namespace);
|
|
10
14
|
return {
|
|
11
15
|
predicates,
|
|
12
16
|
namespace
|
|
@@ -7,10 +7,9 @@ var _apidomNsJsonSchemaDraft = require("@speclynx/apidom-ns-json-schema-draft-4"
|
|
|
7
7
|
* @public
|
|
8
8
|
*/
|
|
9
9
|
class ExamplesVisitor extends _apidomNsJsonSchemaDraft.FallbackVisitor {
|
|
10
|
-
ArrayElement(
|
|
11
|
-
|
|
10
|
+
ArrayElement(path) {
|
|
11
|
+
this.enter(path);
|
|
12
12
|
this.element.classes.push('json-schema-examples');
|
|
13
|
-
return result;
|
|
14
13
|
}
|
|
15
14
|
}
|
|
16
15
|
var _default = exports.default = ExamplesVisitor;
|
|
@@ -3,10 +3,9 @@ import { FallbackVisitor } from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
|
3
3
|
* @public
|
|
4
4
|
*/
|
|
5
5
|
class ExamplesVisitor extends FallbackVisitor {
|
|
6
|
-
ArrayElement(
|
|
7
|
-
|
|
6
|
+
ArrayElement(path) {
|
|
7
|
+
this.enter(path);
|
|
8
8
|
this.element.classes.push('json-schema-examples');
|
|
9
|
-
return result;
|
|
10
9
|
}
|
|
11
10
|
}
|
|
12
11
|
export default ExamplesVisitor;
|
|
@@ -2,15 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.default = void 0;
|
|
5
|
-
var _apidomCore = require("@speclynx/apidom-core");
|
|
6
5
|
var _apidomNsJsonSchemaDraft = require("@speclynx/apidom-ns-json-schema-draft-4");
|
|
7
6
|
/**
|
|
8
7
|
* @public
|
|
9
8
|
*/
|
|
10
9
|
class ItemsVisitor extends _apidomNsJsonSchemaDraft.ItemsVisitor {
|
|
11
|
-
BooleanElement(
|
|
12
|
-
this.element = this.toRefractedElement(['document', 'objects', 'JSONSchema'],
|
|
13
|
-
|
|
10
|
+
BooleanElement(path) {
|
|
11
|
+
this.element = this.toRefractedElement(['document', 'objects', 'JSONSchema'], path.node);
|
|
12
|
+
path.stop();
|
|
14
13
|
}
|
|
15
14
|
}
|
|
16
15
|
var _default = exports.default = ItemsVisitor;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { BREAK } from '@speclynx/apidom-core';
|
|
2
1
|
import { ItemsVisitor as JSONSchemaDraft4ItemsVisitor } from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
3
2
|
/**
|
|
4
3
|
* @public
|
|
5
4
|
*/
|
|
6
5
|
class ItemsVisitor extends JSONSchemaDraft4ItemsVisitor {
|
|
7
|
-
BooleanElement(
|
|
8
|
-
this.element = this.toRefractedElement(['document', 'objects', 'JSONSchema'],
|
|
9
|
-
|
|
6
|
+
BooleanElement(path) {
|
|
7
|
+
this.element = this.toRefractedElement(['document', 'objects', 'JSONSchema'], path.node);
|
|
8
|
+
path.stop();
|
|
10
9
|
}
|
|
11
10
|
}
|
|
12
11
|
export default ItemsVisitor;
|
|
@@ -9,6 +9,8 @@ var _JSONSchema = _interopRequireDefault(require("../../../elements/JSONSchema.c
|
|
|
9
9
|
* @public
|
|
10
10
|
*/
|
|
11
11
|
class JSONSchemaVisitor extends _apidomNsJsonSchemaDraft.JSONSchemaVisitor {
|
|
12
|
+
// @ts-expect-error - element can be BooleanElement (boolean schemas introduced in draft-6)
|
|
13
|
+
|
|
12
14
|
constructor(options) {
|
|
13
15
|
super(options);
|
|
14
16
|
this.element = new _JSONSchema.default();
|
|
@@ -16,10 +18,9 @@ class JSONSchemaVisitor extends _apidomNsJsonSchemaDraft.JSONSchemaVisitor {
|
|
|
16
18
|
get defaultDialectIdentifier() {
|
|
17
19
|
return 'http://json-schema.org/draft-06/schema#';
|
|
18
20
|
}
|
|
19
|
-
BooleanElement(
|
|
20
|
-
|
|
21
|
+
BooleanElement(path) {
|
|
22
|
+
this.enter(path);
|
|
21
23
|
this.element.classes.push('boolean-json-schema');
|
|
22
|
-
return result;
|
|
23
24
|
}
|
|
24
25
|
handleSchemaIdentifier(objectElement, identifierKeyword = '$id') {
|
|
25
26
|
return super.handleSchemaIdentifier(objectElement, identifierKeyword);
|
|
@@ -4,6 +4,8 @@ import JSONSchemaElement from "../../../elements/JSONSchema.mjs";
|
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
6
|
class JSONSchemaVisitor extends JSONSchemaDraft4Visitor {
|
|
7
|
+
// @ts-expect-error - element can be BooleanElement (boolean schemas introduced in draft-6)
|
|
8
|
+
|
|
7
9
|
constructor(options) {
|
|
8
10
|
super(options);
|
|
9
11
|
this.element = new JSONSchemaElement();
|
|
@@ -11,10 +13,9 @@ class JSONSchemaVisitor extends JSONSchemaDraft4Visitor {
|
|
|
11
13
|
get defaultDialectIdentifier() {
|
|
12
14
|
return 'http://json-schema.org/draft-06/schema#';
|
|
13
15
|
}
|
|
14
|
-
BooleanElement(
|
|
15
|
-
|
|
16
|
+
BooleanElement(path) {
|
|
17
|
+
this.enter(path);
|
|
16
18
|
this.element.classes.push('boolean-json-schema');
|
|
17
|
-
return result;
|
|
18
19
|
}
|
|
19
20
|
handleSchemaIdentifier(objectElement, identifierKeyword = '$id') {
|
|
20
21
|
return super.handleSchemaIdentifier(objectElement, identifierKeyword);
|
|
@@ -9,6 +9,8 @@ var _LinkDescription = _interopRequireDefault(require("../../../../elements/Link
|
|
|
9
9
|
* @public
|
|
10
10
|
*/
|
|
11
11
|
class LinkDescriptionVisitor extends _apidomNsJsonSchemaDraft.LinkDescriptionVisitor {
|
|
12
|
+
// @ts-expect-error - widening type to include BooleanElement (boolean schemas introduced in draft-6)
|
|
13
|
+
|
|
12
14
|
constructor(options) {
|
|
13
15
|
super(options);
|
|
14
16
|
this.element = new _LinkDescription.default();
|
|
@@ -4,6 +4,8 @@ import LinkDescriptionElement from "../../../../elements/LinkDescription.mjs";
|
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
6
|
class LinkDescriptionVisitor extends JSONSchemaDraft4LinkDescriptionVisitor {
|
|
7
|
+
// @ts-expect-error - widening type to include BooleanElement (boolean schemas introduced in draft-6)
|
|
8
|
+
|
|
7
9
|
constructor(options) {
|
|
8
10
|
super(options);
|
|
9
11
|
this.element = new LinkDescriptionElement();
|