@speclynx/apidom-ns-json-schema-draft-7 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-7.browser.js +1 -1
- package/package.json +10 -9
- package/src/elements/JSONSchema.cjs +4 -3
- package/src/elements/JSONSchema.mjs +4 -3
- package/src/index.cjs +7 -20
- package/src/index.mjs +2 -5
- package/src/predicates.cjs +6 -16
- package/src/predicates.mjs +3 -16
- package/src/refractor/index.cjs +38 -18
- package/src/refractor/index.mjs +33 -16
- package/src/refractor/inspect.cjs +46 -0
- package/src/refractor/inspect.mjs +39 -0
- package/src/refractor/plugins/replace-empty-element.cjs +44 -44
- package/src/refractor/plugins/replace-empty-element.mjs +30 -29
- package/src/refractor/specification.cjs +1 -1
- package/src/refractor/specification.mjs +1 -1
- package/src/refractor/toolbox.cjs +8 -3
- package/src/refractor/toolbox.mjs +6 -2
- package/types/apidom-ns-json-schema-draft-7.d.ts +70 -245
- package/src/refractor/registration.cjs +0 -13
- package/src/refractor/registration.mjs +0 -6
- package/src/traversal/visitor.cjs +0 -16
- package/src/traversal/visitor.mjs +0 -12
|
@@ -35,10 +35,11 @@ class JSONSchema extends _apidomNsJsonSchemaDraft.JSONSchemaElement {
|
|
|
35
35
|
/**
|
|
36
36
|
* Validation keywords for arrays
|
|
37
37
|
*/
|
|
38
|
-
|
|
38
|
+
|
|
39
|
+
get itemsField() {
|
|
39
40
|
return this.get('items');
|
|
40
41
|
}
|
|
41
|
-
set
|
|
42
|
+
set itemsField(items) {
|
|
42
43
|
this.set('items', items);
|
|
43
44
|
}
|
|
44
45
|
|
|
@@ -101,7 +102,7 @@ class JSONSchema extends _apidomNsJsonSchemaDraft.JSONSchemaElement {
|
|
|
101
102
|
get media() {
|
|
102
103
|
throw new _apidomError.UnsupportedOperationError('media keyword from Hyper-Schema vocabulary has been moved to validation vocabulary as "contentMediaType" / "contentEncoding"');
|
|
103
104
|
}
|
|
104
|
-
set media(
|
|
105
|
+
set media(_media) {
|
|
105
106
|
throw new _apidomError.UnsupportedOperationError('media keyword from Hyper-Schema vocabulary has been moved to validation vocabulary as "contentMediaType" / "contentEncoding"');
|
|
106
107
|
}
|
|
107
108
|
|
|
@@ -32,10 +32,11 @@ class JSONSchema extends JSONSchemaElement {
|
|
|
32
32
|
/**
|
|
33
33
|
* Validation keywords for arrays
|
|
34
34
|
*/
|
|
35
|
-
|
|
35
|
+
|
|
36
|
+
get itemsField() {
|
|
36
37
|
return this.get('items');
|
|
37
38
|
}
|
|
38
|
-
set
|
|
39
|
+
set itemsField(items) {
|
|
39
40
|
this.set('items', items);
|
|
40
41
|
}
|
|
41
42
|
|
|
@@ -98,7 +99,7 @@ class JSONSchema extends JSONSchemaElement {
|
|
|
98
99
|
get media() {
|
|
99
100
|
throw new UnsupportedOperationError('media keyword from Hyper-Schema vocabulary has been moved to validation vocabulary as "contentMediaType" / "contentEncoding"');
|
|
100
101
|
}
|
|
101
|
-
set media(
|
|
102
|
+
set media(_media) {
|
|
102
103
|
throw new UnsupportedOperationError('media keyword from Hyper-Schema vocabulary has been moved to validation vocabulary as "contentMediaType" / "contentEncoding"');
|
|
103
104
|
}
|
|
104
105
|
|
package/src/index.cjs
CHANGED
|
@@ -3,18 +3,7 @@
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
4
|
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
|
|
5
5
|
exports.__esModule = true;
|
|
6
|
-
exports.specificationObj = exports.refractorPluginReplaceEmptyElement = exports.
|
|
7
|
-
var _apidomCore = require("@speclynx/apidom-core");
|
|
8
|
-
exports.isRefElement = _apidomCore.isRefElement;
|
|
9
|
-
exports.isLinkElement = _apidomCore.isLinkElement;
|
|
10
|
-
exports.isMemberElement = _apidomCore.isMemberElement;
|
|
11
|
-
exports.isObjectElement = _apidomCore.isObjectElement;
|
|
12
|
-
exports.isArrayElement = _apidomCore.isArrayElement;
|
|
13
|
-
exports.isBooleanElement = _apidomCore.isBooleanElement;
|
|
14
|
-
exports.isNullElement = _apidomCore.isNullElement;
|
|
15
|
-
exports.isElement = _apidomCore.isElement;
|
|
16
|
-
exports.isNumberElement = _apidomCore.isNumberElement;
|
|
17
|
-
exports.isStringElement = _apidomCore.isStringElement;
|
|
6
|
+
exports.specificationObj = exports.refractorPluginReplaceEmptyElement = exports.refractLinkDescription = exports.refractJSONSchema = exports.refract = exports.mediaTypes = exports.isLinkDescriptionElement = exports.isJSONSchemaElement = exports.isJSONReferenceLikeElement = exports.isJSONReferenceElement = exports.default = exports.Visitor = exports.SpecificationVisitor = exports.PatternedFieldsVisitor = exports.ParentSchemaAwareVisitor = exports.MapVisitor = exports.LinkDescriptionVisitor = exports.LinkDescriptionElement = exports.JSONSchemaVisitor = exports.JSONSchemaElement = exports.JSONSchemaDraft7MediaTypes = exports.JSONReferenceElement = exports.FixedFieldsVisitor = exports.FallbackVisitor = exports.AlternatingVisitor = void 0;
|
|
18
7
|
var _mediaTypes = _interopRequireWildcard(require("./media-types.cjs"));
|
|
19
8
|
exports.mediaTypes = _mediaTypes.default;
|
|
20
9
|
exports.JSONSchemaDraft7MediaTypes = _mediaTypes.JSONSchemaDraft7MediaTypes;
|
|
@@ -24,7 +13,8 @@ var _replaceEmptyElement = _interopRequireDefault(require("./refractor/plugins/r
|
|
|
24
13
|
exports.refractorPluginReplaceEmptyElement = _replaceEmptyElement.default;
|
|
25
14
|
var _index = _interopRequireWildcard(require("./refractor/index.cjs"));
|
|
26
15
|
exports.refract = _index.default;
|
|
27
|
-
exports.
|
|
16
|
+
exports.refractJSONSchema = _index.refractJSONSchema;
|
|
17
|
+
exports.refractLinkDescription = _index.refractLinkDescription;
|
|
28
18
|
var _specification = _interopRequireDefault(require("./refractor/specification.cjs"));
|
|
29
19
|
exports.specificationObj = _specification.default;
|
|
30
20
|
var _predicates = require("./predicates.cjs");
|
|
@@ -41,14 +31,11 @@ exports.MapVisitor = _apidomNsJsonSchemaDraft.MapVisitor;
|
|
|
41
31
|
exports.AlternatingVisitor = _apidomNsJsonSchemaDraft.AlternatingVisitor;
|
|
42
32
|
exports.ParentSchemaAwareVisitor = _apidomNsJsonSchemaDraft.ParentSchemaAwareVisitor;
|
|
43
33
|
exports.Visitor = _apidomNsJsonSchemaDraft.Visitor;
|
|
44
|
-
exports.JSONReferenceElement = _apidomNsJsonSchemaDraft.JSONReferenceElement;
|
|
45
34
|
var _index2 = _interopRequireDefault(require("./refractor/visitors/json-schema/index.cjs"));
|
|
46
35
|
exports.JSONSchemaVisitor = _index2.default;
|
|
47
36
|
var _index3 = _interopRequireDefault(require("./refractor/visitors/json-schema/link-description/index.cjs"));
|
|
48
37
|
exports.LinkDescriptionVisitor = _index3.default;
|
|
49
|
-
var
|
|
50
|
-
exports.
|
|
51
|
-
exports.
|
|
52
|
-
|
|
53
|
-
exports.JSONSchemaElement = _registration.JSONSchemaElement;
|
|
54
|
-
exports.LinkDescriptionElement = _registration.LinkDescriptionElement;
|
|
38
|
+
var _inspect = require("./refractor/inspect.cjs");
|
|
39
|
+
exports.JSONSchemaElement = _inspect.JSONSchemaElement;
|
|
40
|
+
exports.JSONReferenceElement = _inspect.JSONReferenceElement;
|
|
41
|
+
exports.LinkDescriptionElement = _inspect.LinkDescriptionElement;
|
package/src/index.mjs
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
export { isRefElement, isLinkElement, isMemberElement, isObjectElement, isArrayElement, isBooleanElement, isNullElement, isElement, isNumberElement, isStringElement } from '@speclynx/apidom-core';
|
|
2
1
|
export { default as mediaTypes, JSONSchemaDraft7MediaTypes } from "./media-types.mjs";
|
|
3
2
|
export { default } from "./namespace.mjs";
|
|
4
3
|
export { default as refractorPluginReplaceEmptyElement } from "./refractor/plugins/replace-empty-element.mjs";
|
|
5
|
-
export { default as refract,
|
|
4
|
+
export { default as refract, refractJSONSchema, refractLinkDescription } from "./refractor/index.mjs";
|
|
6
5
|
export { default as specificationObj } from "./refractor/specification.mjs";
|
|
7
6
|
export { isJSONReferenceElement, isJSONSchemaElement, isLinkDescriptionElement } from "./predicates.mjs";
|
|
8
7
|
export { isJSONReferenceLikeElement, SpecificationVisitor, FallbackVisitor, FixedFieldsVisitor, PatternedFieldsVisitor, MapVisitor, AlternatingVisitor, ParentSchemaAwareVisitor, Visitor } from '@speclynx/apidom-ns-json-schema-draft-6';
|
|
9
8
|
export { default as JSONSchemaVisitor } from "./refractor/visitors/json-schema/index.mjs";
|
|
10
9
|
export { default as LinkDescriptionVisitor } from "./refractor/visitors/json-schema/link-description/index.mjs";
|
|
11
|
-
export { keyMap, getNodeType } from "./traversal/visitor.mjs";
|
|
12
10
|
/**
|
|
13
11
|
* JSON Schema Draft 7 specification elements.
|
|
14
12
|
*/
|
|
15
|
-
export { JSONSchemaElement, LinkDescriptionElement } from "./refractor/
|
|
16
|
-
export { JSONReferenceElement } from '@speclynx/apidom-ns-json-schema-draft-6';
|
|
13
|
+
export { JSONSchemaElement, JSONReferenceElement, LinkDescriptionElement } from "./refractor/inspect.mjs";
|
package/src/predicates.cjs
CHANGED
|
@@ -2,30 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
4
|
exports.__esModule = true;
|
|
5
|
-
exports.isLinkDescriptionElement = exports.isJSONSchemaElement = exports.isJSONReferenceElement = void 0;
|
|
6
|
-
var _apidomCore = require("@speclynx/apidom-core");
|
|
5
|
+
exports.isMediaElement = exports.isLinkDescriptionElement = exports.isJSONSchemaElement = exports.isJSONReferenceElement = void 0;
|
|
7
6
|
var _JSONSchema = _interopRequireDefault(require("./elements/JSONSchema.cjs"));
|
|
8
7
|
var _LinkDescription = _interopRequireDefault(require("./elements/LinkDescription.cjs"));
|
|
9
8
|
var _apidomNsJsonSchemaDraft = require("@speclynx/apidom-ns-json-schema-draft-6");
|
|
10
9
|
exports.isJSONReferenceElement = _apidomNsJsonSchemaDraft.isJSONReferenceElement;
|
|
10
|
+
exports.isMediaElement = _apidomNsJsonSchemaDraft.isMediaElement;
|
|
11
11
|
/**
|
|
12
12
|
* @public
|
|
13
13
|
*/
|
|
14
|
-
const isJSONSchemaElement =
|
|
15
|
-
hasBasicElementProps,
|
|
16
|
-
isElementType,
|
|
17
|
-
primitiveEq
|
|
18
|
-
}) => {
|
|
19
|
-
return element => element instanceof _JSONSchema.default || hasBasicElementProps(element) && isElementType('JSONSchemaDraft7', element) && primitiveEq('object', element);
|
|
20
|
-
});
|
|
14
|
+
const isJSONSchemaElement = element => element instanceof _JSONSchema.default;
|
|
21
15
|
|
|
22
16
|
/**
|
|
23
17
|
* @public
|
|
24
18
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
primitiveEq
|
|
29
|
-
}) => {
|
|
30
|
-
return element => element instanceof _LinkDescription.default || hasBasicElementProps(element) && isElementType('linkDescription', element) && primitiveEq('object', element);
|
|
31
|
-
});
|
|
19
|
+
exports.isJSONSchemaElement = isJSONSchemaElement;
|
|
20
|
+
const isLinkDescriptionElement = element => element instanceof _LinkDescription.default;
|
|
21
|
+
exports.isLinkDescriptionElement = isLinkDescriptionElement;
|
package/src/predicates.mjs
CHANGED
|
@@ -1,26 +1,13 @@
|
|
|
1
|
-
import { createPredicate } from '@speclynx/apidom-core';
|
|
2
1
|
import JSONSchemaElement from "./elements/JSONSchema.mjs";
|
|
3
2
|
import LinkDescriptionElement from "./elements/LinkDescription.mjs";
|
|
4
|
-
export { isJSONReferenceElement } from '@speclynx/apidom-ns-json-schema-draft-6';
|
|
3
|
+
export { isJSONReferenceElement, isMediaElement } from '@speclynx/apidom-ns-json-schema-draft-6';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* @public
|
|
8
7
|
*/
|
|
9
|
-
export const isJSONSchemaElement =
|
|
10
|
-
hasBasicElementProps,
|
|
11
|
-
isElementType,
|
|
12
|
-
primitiveEq
|
|
13
|
-
}) => {
|
|
14
|
-
return element => element instanceof JSONSchemaElement || hasBasicElementProps(element) && isElementType('JSONSchemaDraft7', element) && primitiveEq('object', element);
|
|
15
|
-
});
|
|
8
|
+
export const isJSONSchemaElement = element => element instanceof JSONSchemaElement;
|
|
16
9
|
|
|
17
10
|
/**
|
|
18
11
|
* @public
|
|
19
12
|
*/
|
|
20
|
-
export const isLinkDescriptionElement =
|
|
21
|
-
hasBasicElementProps,
|
|
22
|
-
isElementType,
|
|
23
|
-
primitiveEq
|
|
24
|
-
}) => {
|
|
25
|
-
return element => element instanceof LinkDescriptionElement || hasBasicElementProps(element) && isElementType('linkDescription', element) && primitiveEq('object', element);
|
|
26
|
-
});
|
|
13
|
+
export const isLinkDescriptionElement = element => element instanceof LinkDescriptionElement;
|
package/src/refractor/index.cjs
CHANGED
|
@@ -2,53 +2,73 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
4
|
exports.__esModule = true;
|
|
5
|
-
exports.
|
|
6
|
-
var _ramda = require("ramda");
|
|
5
|
+
exports.refractLinkDescription = exports.refractJSONSchema = exports.default = void 0;
|
|
7
6
|
var _apidomCore = require("@speclynx/apidom-core");
|
|
7
|
+
var _apidomTraverse = require("@speclynx/apidom-traverse");
|
|
8
|
+
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
9
|
+
var _ramda = require("ramda");
|
|
8
10
|
var _specification = _interopRequireDefault(require("./specification.cjs"));
|
|
9
|
-
var _visitor = require("../traversal/visitor.cjs");
|
|
10
11
|
var _toolbox = _interopRequireDefault(require("./toolbox.cjs"));
|
|
12
|
+
/**
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
|
|
11
20
|
/**
|
|
12
21
|
* @public
|
|
13
22
|
*/
|
|
14
23
|
const refract = (value, {
|
|
15
|
-
|
|
24
|
+
element = 'jSONSchemaDraft7',
|
|
16
25
|
plugins = [],
|
|
17
26
|
specificationObj = _specification.default
|
|
18
27
|
} = {}) => {
|
|
19
|
-
const
|
|
20
|
-
const resolvedSpec = (0, _apidomCore.
|
|
28
|
+
const genericElement = (0, _apidomDatamodel.refract)(value);
|
|
29
|
+
const resolvedSpec = (0, _apidomCore.resolveSpecification)(specificationObj);
|
|
30
|
+
const elementMap = resolvedSpec.elementMap;
|
|
31
|
+
const specPath = elementMap[element];
|
|
32
|
+
if (!specPath) {
|
|
33
|
+
throw new Error(`Unknown element type: "${element}"`);
|
|
34
|
+
}
|
|
21
35
|
|
|
22
36
|
/**
|
|
23
37
|
* This is where generic ApiDOM becomes semantic (namespace applied).
|
|
24
38
|
* We don't allow consumers to hook into this translation.
|
|
25
|
-
* Though we allow consumers to define their
|
|
39
|
+
* Though we allow consumers to define their own plugins on already transformed ApiDOM.
|
|
26
40
|
*/
|
|
27
41
|
const RootVisitorClass = (0, _ramda.path)(specPath, resolvedSpec);
|
|
28
42
|
const rootVisitor = new RootVisitorClass({
|
|
29
43
|
specObj: resolvedSpec
|
|
30
44
|
});
|
|
31
|
-
(0,
|
|
45
|
+
(0, _apidomTraverse.traverse)(genericElement, rootVisitor);
|
|
32
46
|
|
|
33
47
|
/**
|
|
34
|
-
* Run plugins only when necessary.
|
|
35
48
|
* Running plugins visitors means extra single traversal === performance hit.
|
|
36
49
|
*/
|
|
37
50
|
return (0, _apidomCore.dispatchRefractorPlugins)(rootVisitor.element, plugins, {
|
|
38
|
-
toolboxCreator: _toolbox.default
|
|
39
|
-
visitorOptions: {
|
|
40
|
-
keyMap: _visitor.keyMap,
|
|
41
|
-
nodeTypeGetter: _visitor.getNodeType
|
|
42
|
-
}
|
|
51
|
+
toolboxCreator: _toolbox.default
|
|
43
52
|
});
|
|
44
53
|
};
|
|
45
54
|
|
|
46
55
|
/**
|
|
56
|
+
* Refracts a value into a JSONSchemaElement.
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
const refractJSONSchema = (value, options = {}) => refract(value, {
|
|
60
|
+
...options,
|
|
61
|
+
element: 'jSONSchemaDraft7'
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Refracts a value into a LinkDescriptionElement.
|
|
47
66
|
* @public
|
|
48
67
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
...options
|
|
68
|
+
exports.refractJSONSchema = refractJSONSchema;
|
|
69
|
+
const refractLinkDescription = (value, options = {}) => refract(value, {
|
|
70
|
+
...options,
|
|
71
|
+
element: 'linkDescription'
|
|
52
72
|
});
|
|
53
|
-
exports.
|
|
73
|
+
exports.refractLinkDescription = refractLinkDescription;
|
|
54
74
|
var _default = exports.default = refract;
|
package/src/refractor/index.mjs
CHANGED
|
@@ -1,48 +1,65 @@
|
|
|
1
|
+
import { resolveSpecification, dispatchRefractorPlugins } from '@speclynx/apidom-core';
|
|
2
|
+
import { traverse } from '@speclynx/apidom-traverse';
|
|
3
|
+
import { refract as baseRefract } from '@speclynx/apidom-datamodel';
|
|
1
4
|
import { path } from 'ramda';
|
|
2
|
-
import { visit, dereference, refract as baseRefract, dispatchRefractorPlugins } from '@speclynx/apidom-core';
|
|
3
5
|
import specification from "./specification.mjs";
|
|
4
|
-
import { keyMap, getNodeType } from "../traversal/visitor.mjs";
|
|
5
6
|
import createToolbox from "./toolbox.mjs";
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
6
13
|
/**
|
|
7
14
|
* @public
|
|
8
15
|
*/
|
|
9
16
|
const refract = (value, {
|
|
10
|
-
|
|
17
|
+
element = 'jSONSchemaDraft7',
|
|
11
18
|
plugins = [],
|
|
12
19
|
specificationObj = specification
|
|
13
20
|
} = {}) => {
|
|
14
|
-
const
|
|
15
|
-
const resolvedSpec =
|
|
21
|
+
const genericElement = baseRefract(value);
|
|
22
|
+
const resolvedSpec = resolveSpecification(specificationObj);
|
|
23
|
+
const elementMap = resolvedSpec.elementMap;
|
|
24
|
+
const specPath = elementMap[element];
|
|
25
|
+
if (!specPath) {
|
|
26
|
+
throw new Error(`Unknown element type: "${element}"`);
|
|
27
|
+
}
|
|
16
28
|
|
|
17
29
|
/**
|
|
18
30
|
* This is where generic ApiDOM becomes semantic (namespace applied).
|
|
19
31
|
* We don't allow consumers to hook into this translation.
|
|
20
|
-
* Though we allow consumers to define their
|
|
32
|
+
* Though we allow consumers to define their own plugins on already transformed ApiDOM.
|
|
21
33
|
*/
|
|
22
34
|
const RootVisitorClass = path(specPath, resolvedSpec);
|
|
23
35
|
const rootVisitor = new RootVisitorClass({
|
|
24
36
|
specObj: resolvedSpec
|
|
25
37
|
});
|
|
26
|
-
|
|
38
|
+
traverse(genericElement, rootVisitor);
|
|
27
39
|
|
|
28
40
|
/**
|
|
29
|
-
* Run plugins only when necessary.
|
|
30
41
|
* Running plugins visitors means extra single traversal === performance hit.
|
|
31
42
|
*/
|
|
32
43
|
return dispatchRefractorPlugins(rootVisitor.element, plugins, {
|
|
33
|
-
toolboxCreator: createToolbox
|
|
34
|
-
visitorOptions: {
|
|
35
|
-
keyMap,
|
|
36
|
-
nodeTypeGetter: getNodeType
|
|
37
|
-
}
|
|
44
|
+
toolboxCreator: createToolbox
|
|
38
45
|
});
|
|
39
46
|
};
|
|
40
47
|
|
|
41
48
|
/**
|
|
49
|
+
* Refracts a value into a JSONSchemaElement.
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
export const refractJSONSchema = (value, options = {}) => refract(value, {
|
|
53
|
+
...options,
|
|
54
|
+
element: 'jSONSchemaDraft7'
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Refracts a value into a LinkDescriptionElement.
|
|
42
59
|
* @public
|
|
43
60
|
*/
|
|
44
|
-
export const
|
|
45
|
-
|
|
46
|
-
|
|
61
|
+
export const refractLinkDescription = (value, options = {}) => refract(value, {
|
|
62
|
+
...options,
|
|
63
|
+
element: 'linkDescription'
|
|
47
64
|
});
|
|
48
65
|
export default refract;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
var _apidomCore = require("@speclynx/apidom-core");
|
|
6
|
+
var _ramdaAdjunct = require("ramda-adjunct");
|
|
7
|
+
var _apidomNsJsonSchemaDraft = require("@speclynx/apidom-ns-json-schema-draft-6");
|
|
8
|
+
exports.JSONReferenceElement = _apidomNsJsonSchemaDraft.JSONReferenceElement;
|
|
9
|
+
var _JSONSchema = _interopRequireDefault(require("../elements/JSONSchema.cjs"));
|
|
10
|
+
exports.JSONSchemaElement = _JSONSchema.default;
|
|
11
|
+
var _LinkDescription = _interopRequireDefault(require("../elements/LinkDescription.cjs"));
|
|
12
|
+
exports.LinkDescriptionElement = _LinkDescription.default;
|
|
13
|
+
var _specification = _interopRequireDefault(require("./specification.cjs"));
|
|
14
|
+
/**
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// Resolve specification to dereference $ref pointers
|
|
19
|
+
const resolvedSpec = (0, _apidomCore.resolveSpecification)(_specification.default);
|
|
20
|
+
|
|
21
|
+
// Extract fixed fields as list of { name, alias?, $visitor }
|
|
22
|
+
const getFixedFields = fixedFieldsSpec => {
|
|
23
|
+
return Object.entries(fixedFieldsSpec).map(([name, fieldSpec]) => {
|
|
24
|
+
if ((0, _ramdaAdjunct.isPlainObject)(fieldSpec)) {
|
|
25
|
+
return {
|
|
26
|
+
name,
|
|
27
|
+
...fieldSpec
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
name,
|
|
32
|
+
$visitor: fieldSpec
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// Define lazy getters for fixedFields on element classes
|
|
38
|
+
// Note: JSONReferenceElement inherits fixedFields from draft-6/draft-4
|
|
39
|
+
Object.defineProperty(_JSONSchema.default, 'fixedFields', {
|
|
40
|
+
get: () => getFixedFields(resolvedSpec.visitors.document.objects.JSONSchema.fixedFields),
|
|
41
|
+
enumerable: true
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(_LinkDescription.default, 'fixedFields', {
|
|
44
|
+
get: () => getFixedFields(resolvedSpec.visitors.document.objects.LinkDescription.fixedFields),
|
|
45
|
+
enumerable: true
|
|
46
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { resolveSpecification } from '@speclynx/apidom-core';
|
|
2
|
+
import { isPlainObject } from 'ramda-adjunct';
|
|
3
|
+
import { JSONReferenceElement } from '@speclynx/apidom-ns-json-schema-draft-6';
|
|
4
|
+
import JSONSchemaElement from "../elements/JSONSchema.mjs";
|
|
5
|
+
import LinkDescriptionElement from "../elements/LinkDescription.mjs";
|
|
6
|
+
import specification from "./specification.mjs";
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
// Resolve specification to dereference $ref pointers
|
|
11
|
+
const resolvedSpec = resolveSpecification(specification);
|
|
12
|
+
|
|
13
|
+
// Extract fixed fields as list of { name, alias?, $visitor }
|
|
14
|
+
const getFixedFields = fixedFieldsSpec => {
|
|
15
|
+
return Object.entries(fixedFieldsSpec).map(([name, fieldSpec]) => {
|
|
16
|
+
if (isPlainObject(fieldSpec)) {
|
|
17
|
+
return {
|
|
18
|
+
name,
|
|
19
|
+
...fieldSpec
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
name,
|
|
24
|
+
$visitor: fieldSpec
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// Define lazy getters for fixedFields on element classes
|
|
30
|
+
// Note: JSONReferenceElement inherits fixedFields from draft-6/draft-4
|
|
31
|
+
Object.defineProperty(JSONSchemaElement, 'fixedFields', {
|
|
32
|
+
get: () => getFixedFields(resolvedSpec.visitors.document.objects.JSONSchema.fixedFields),
|
|
33
|
+
enumerable: true
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(LinkDescriptionElement, 'fixedFields', {
|
|
36
|
+
get: () => getFixedFields(resolvedSpec.visitors.document.objects.LinkDescription.fixedFields),
|
|
37
|
+
enumerable: true
|
|
38
|
+
});
|
|
39
|
+
export { JSONSchemaElement, JSONReferenceElement, LinkDescriptionElement };
|
|
@@ -3,14 +3,11 @@
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
4
|
exports.__esModule = true;
|
|
5
5
|
exports.default = void 0;
|
|
6
|
+
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
6
7
|
var _apidomCore = require("@speclynx/apidom-core");
|
|
8
|
+
var _apidomTraverse = require("@speclynx/apidom-traverse");
|
|
7
9
|
var _JSONSchema = _interopRequireDefault(require("../../elements/JSONSchema.cjs"));
|
|
8
10
|
var _LinkDescription = _interopRequireDefault(require("../../elements/LinkDescription.cjs"));
|
|
9
|
-
var _visitor = require("../../traversal/visitor.cjs");
|
|
10
|
-
/**
|
|
11
|
-
* JSON Schema Draft 7 specification elements.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
11
|
/**
|
|
15
12
|
* This plugin is specific to YAML 1.2 format, which allows defining key-value pairs
|
|
16
13
|
* with empty key, empty value, or both. If the value is not provided in YAML format,
|
|
@@ -45,7 +42,7 @@ var _visitor = require("../../traversal/visitor.cjs");
|
|
|
45
42
|
* (JSONSchemaElement))
|
|
46
43
|
*/
|
|
47
44
|
|
|
48
|
-
const isEmptyElement = element => (0,
|
|
45
|
+
const isEmptyElement = element => (0, _apidomDatamodel.isStringElement)(element) && (0, _apidomDatamodel.includesClasses)(element, ['yaml-e-node', 'yaml-e-scalar']);
|
|
49
46
|
const schema = {
|
|
50
47
|
JSONSchemaDraft7Element: {
|
|
51
48
|
additionalItems(...args) {
|
|
@@ -58,12 +55,12 @@ const schema = {
|
|
|
58
55
|
return new _JSONSchema.default(...args);
|
|
59
56
|
},
|
|
60
57
|
required(...args) {
|
|
61
|
-
const element = new
|
|
58
|
+
const element = new _apidomDatamodel.ArrayElement(...args);
|
|
62
59
|
element.classes.push('json-schema-required');
|
|
63
60
|
return element;
|
|
64
61
|
},
|
|
65
62
|
properties(...args) {
|
|
66
|
-
const element = new
|
|
63
|
+
const element = new _apidomDatamodel.ObjectElement(...args);
|
|
67
64
|
element.classes.push('json-schema-properties');
|
|
68
65
|
return element;
|
|
69
66
|
},
|
|
@@ -71,12 +68,12 @@ const schema = {
|
|
|
71
68
|
return new _JSONSchema.default(...args);
|
|
72
69
|
},
|
|
73
70
|
patternProperties(...args) {
|
|
74
|
-
const element = new
|
|
71
|
+
const element = new _apidomDatamodel.ObjectElement(...args);
|
|
75
72
|
element.classes.push('json-schema-patternProperties');
|
|
76
73
|
return element;
|
|
77
74
|
},
|
|
78
75
|
dependencies(...args) {
|
|
79
|
-
const element = new
|
|
76
|
+
const element = new _apidomDatamodel.ObjectElement(...args);
|
|
80
77
|
element.classes.push('json-schema-dependencies');
|
|
81
78
|
return element;
|
|
82
79
|
},
|
|
@@ -84,22 +81,22 @@ const schema = {
|
|
|
84
81
|
return new _JSONSchema.default(...args);
|
|
85
82
|
},
|
|
86
83
|
enum(...args) {
|
|
87
|
-
const element = new
|
|
84
|
+
const element = new _apidomDatamodel.ArrayElement(...args);
|
|
88
85
|
element.classes.push('json-schema-enum');
|
|
89
86
|
return element;
|
|
90
87
|
},
|
|
91
88
|
allOf(...args) {
|
|
92
|
-
const element = new
|
|
89
|
+
const element = new _apidomDatamodel.ArrayElement(...args);
|
|
93
90
|
element.classes.push('json-schema-allOf');
|
|
94
91
|
return element;
|
|
95
92
|
},
|
|
96
93
|
anyOf(...args) {
|
|
97
|
-
const element = new
|
|
94
|
+
const element = new _apidomDatamodel.ArrayElement(...args);
|
|
98
95
|
element.classes.push('json-schema-anyOf');
|
|
99
96
|
return element;
|
|
100
97
|
},
|
|
101
98
|
oneOf(...args) {
|
|
102
|
-
const element = new
|
|
99
|
+
const element = new _apidomDatamodel.ArrayElement(...args);
|
|
103
100
|
element.classes.push('json-schema-oneOf');
|
|
104
101
|
return element;
|
|
105
102
|
},
|
|
@@ -116,17 +113,17 @@ const schema = {
|
|
|
116
113
|
return new _JSONSchema.default(...args);
|
|
117
114
|
},
|
|
118
115
|
definitions(...args) {
|
|
119
|
-
const element = new
|
|
116
|
+
const element = new _apidomDatamodel.ObjectElement(...args);
|
|
120
117
|
element.classes.push('json-schema-definitions');
|
|
121
118
|
return element;
|
|
122
119
|
},
|
|
123
120
|
examples(...args) {
|
|
124
|
-
const element = new
|
|
121
|
+
const element = new _apidomDatamodel.ArrayElement(...args);
|
|
125
122
|
element.classes.push('json-schema-examples');
|
|
126
123
|
return element;
|
|
127
124
|
},
|
|
128
125
|
links(...args) {
|
|
129
|
-
const element = new
|
|
126
|
+
const element = new _apidomDatamodel.ArrayElement(...args);
|
|
130
127
|
element.classes.push('json-schema-links');
|
|
131
128
|
return element;
|
|
132
129
|
}
|
|
@@ -142,13 +139,13 @@ const schema = {
|
|
|
142
139
|
return new _JSONSchema.default(...args);
|
|
143
140
|
},
|
|
144
141
|
templatePointers(...args) {
|
|
145
|
-
return new
|
|
142
|
+
return new _apidomDatamodel.ObjectElement(...args);
|
|
146
143
|
},
|
|
147
144
|
templateRequired(...args) {
|
|
148
|
-
return new
|
|
145
|
+
return new _apidomDatamodel.ArrayElement(...args);
|
|
149
146
|
},
|
|
150
147
|
targetHints(...args) {
|
|
151
|
-
return new
|
|
148
|
+
return new _apidomDatamodel.ObjectElement(...args);
|
|
152
149
|
},
|
|
153
150
|
headerSchema(...args) {
|
|
154
151
|
return new _JSONSchema.default(...args);
|
|
@@ -196,7 +193,7 @@ const schema = {
|
|
|
196
193
|
}
|
|
197
194
|
};
|
|
198
195
|
const findElementFactory = (ancestor, keyName) => {
|
|
199
|
-
const elementType = (0,
|
|
196
|
+
const elementType = (0, _apidomTraverse.getNodeType)(ancestor); // @ts-ignore
|
|
200
197
|
const keyMapping = schema[elementType] || schema[(0, _apidomCore.toValue)(ancestor.classes.first)];
|
|
201
198
|
return typeof keyMapping === 'undefined' ? undefined : Object.hasOwn(keyMapping, '[key: *]') ? keyMapping['[key: *]'] : keyMapping[keyName];
|
|
202
199
|
};
|
|
@@ -204,30 +201,33 @@ const findElementFactory = (ancestor, keyName) => {
|
|
|
204
201
|
/**
|
|
205
202
|
* @public
|
|
206
203
|
*/
|
|
207
|
-
const plugin = () => () => {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const lineage = [...ancestors, parent].filter(_apidomCore.isElement);
|
|
213
|
-
const parentElement = lineage.at(-1);
|
|
214
|
-
let elementFactory;
|
|
215
|
-
let context;
|
|
216
|
-
if ((0, _apidomCore.isArrayElement)(parentElement)) {
|
|
217
|
-
context = element;
|
|
218
|
-
elementFactory = findElementFactory(parentElement, '<*>');
|
|
219
|
-
} else if ((0, _apidomCore.isMemberElement)(parentElement)) {
|
|
220
|
-
context = lineage.at(-2);
|
|
221
|
-
elementFactory = findElementFactory(context, (0, _apidomCore.toValue)(parentElement.key));
|
|
222
|
-
}
|
|
204
|
+
const plugin = () => () => ({
|
|
205
|
+
visitor: {
|
|
206
|
+
StringElement(path) {
|
|
207
|
+
const element = path.node;
|
|
208
|
+
if (!isEmptyElement(element)) return;
|
|
223
209
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
210
|
+
// getAncestorNodes() returns [parent, grandparent, ..., root], so reverse to get [root, ..., parent]
|
|
211
|
+
const lineage = path.getAncestorNodes().reverse().filter(_apidomDatamodel.isElement);
|
|
212
|
+
const parentElement = lineage.at(-1);
|
|
213
|
+
let elementFactory;
|
|
214
|
+
let context;
|
|
215
|
+
if ((0, _apidomDatamodel.isArrayElement)(parentElement)) {
|
|
216
|
+
context = element;
|
|
217
|
+
elementFactory = findElementFactory(parentElement, '<*>');
|
|
218
|
+
} else if ((0, _apidomDatamodel.isMemberElement)(parentElement)) {
|
|
219
|
+
context = lineage.at(-2);
|
|
220
|
+
elementFactory = findElementFactory(context, (0, _apidomCore.toValue)(parentElement.key));
|
|
229
221
|
}
|
|
222
|
+
|
|
223
|
+
// no element factory found
|
|
224
|
+
if (typeof elementFactory !== 'function') return;
|
|
225
|
+
const replacement = elementFactory.call({
|
|
226
|
+
context
|
|
227
|
+
}, undefined, (0, _apidomDatamodel.cloneDeep)(element.meta), (0, _apidomDatamodel.cloneDeep)(element.attributes));
|
|
228
|
+
_apidomDatamodel.SourceMapElement.transfer(element, replacement);
|
|
229
|
+
path.replaceWith(replacement);
|
|
230
230
|
}
|
|
231
|
-
}
|
|
232
|
-
};
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
233
|
var _default = exports.default = plugin;
|