@speclynx/apidom-ns-json-schema-draft-7 1.12.2 → 2.1.0
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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@speclynx/apidom-ns-json-schema-draft-7",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "JSON Schema Draft 7 namespace for ApiDOM.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
11
11
|
"sideEffects": [
|
|
12
|
-
"./src/refractor/
|
|
13
|
-
"./src/refractor/
|
|
12
|
+
"./src/refractor/inspect.mjs",
|
|
13
|
+
"./src/refractor/inspect.cjs"
|
|
14
14
|
],
|
|
15
15
|
"unpkg": "./dist/apidom-ns-json-schema-draft-7.browser.min.js",
|
|
16
16
|
"main": "./src/index.cjs",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"test": "npm run build:es && cross-env BABEL_ENV=es babel test --out-dir test --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward' && cross-env NODE_ENV=test mocha",
|
|
32
32
|
"test:update-snapshots": "cross-env UPDATE_SNAPSHOT=1 mocha",
|
|
33
33
|
"typescript:check-types": "tsc --noEmit && tsc -p ./test/tsconfig.json --noEmit",
|
|
34
|
-
"typescript:declaration": "tsc -p tsconfig.declaration.json && api-extractor run -l -c ./config/api-extractor/api-extractor.json
|
|
34
|
+
"typescript:declaration": "tsc -p tsconfig.declaration.json && api-extractor run -l -c ./config/api-extractor/api-extractor.json",
|
|
35
35
|
"prepack": "copyfiles -u 3 ../../LICENSES/* LICENSES && copyfiles -u 2 ../../NOTICE .",
|
|
36
36
|
"postpack": "rimraf NOTICE LICENSES"
|
|
37
37
|
},
|
|
@@ -43,10 +43,11 @@
|
|
|
43
43
|
"license": "Apache-2.0",
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@babel/runtime-corejs3": "^7.28.4",
|
|
46
|
-
"@speclynx/apidom-core": "^1.
|
|
47
|
-
"@speclynx/apidom-
|
|
48
|
-
"@speclynx/apidom-
|
|
49
|
-
"@
|
|
46
|
+
"@speclynx/apidom-core": "^2.1.0",
|
|
47
|
+
"@speclynx/apidom-datamodel": "^2.1.0",
|
|
48
|
+
"@speclynx/apidom-error": "^2.1.0",
|
|
49
|
+
"@speclynx/apidom-ns-json-schema-draft-6": "^2.1.0",
|
|
50
|
+
"@speclynx/apidom-traverse": "^2.1.0",
|
|
50
51
|
"ramda": "~0.32.0",
|
|
51
52
|
"ramda-adjunct": "^6.0.0",
|
|
52
53
|
"ts-mixer": "^6.0.4"
|
|
@@ -61,5 +62,5 @@
|
|
|
61
62
|
"README.md",
|
|
62
63
|
"CHANGELOG.md"
|
|
63
64
|
],
|
|
64
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "dd02cfbbe82b0a31c6e7c444cec140e740e1c6e9"
|
|
65
66
|
}
|
|
@@ -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 };
|