@speclynx/apidom-ns-json-schema-draft-6 1.12.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 +82 -0
- package/LICENSE +202 -0
- package/LICENSES/AFL-3.0.txt +182 -0
- package/LICENSES/Apache-2.0.txt +202 -0
- package/LICENSES/BSD-3-Clause.txt +26 -0
- package/LICENSES/MIT.txt +9 -0
- package/NOTICE +65 -0
- package/README.md +189 -0
- package/dist/apidom-ns-json-schema-draft-6.browser.js +1 -0
- package/package.json +65 -0
- package/src/elements/JSONSchema.cjs +116 -0
- package/src/elements/JSONSchema.mjs +113 -0
- package/src/elements/LinkDescription.cjs +56 -0
- package/src/elements/LinkDescription.mjs +52 -0
- package/src/index.cjs +58 -0
- package/src/index.mjs +17 -0
- package/src/media-types.cjs +34 -0
- package/src/media-types.mjs +30 -0
- package/src/namespace.cjs +24 -0
- package/src/namespace.mjs +19 -0
- package/src/predicates.cjs +32 -0
- package/src/predicates.mjs +26 -0
- package/src/refractor/index.cjs +53 -0
- package/src/refractor/index.mjs +47 -0
- package/src/refractor/plugins/replace-empty-element.cjs +214 -0
- package/src/refractor/plugins/replace-empty-element.mjs +207 -0
- package/src/refractor/registration.cjs +13 -0
- package/src/refractor/registration.mjs +6 -0
- package/src/refractor/specification.cjs +17 -0
- package/src/refractor/specification.mjs +12 -0
- package/src/refractor/toolbox.cjs +21 -0
- package/src/refractor/toolbox.mjs +15 -0
- package/src/refractor/visitors/json-schema/ExamplesVisitor.cjs +16 -0
- package/src/refractor/visitors/json-schema/ExamplesVisitor.mjs +12 -0
- package/src/refractor/visitors/json-schema/ItemsVisitor.cjs +16 -0
- package/src/refractor/visitors/json-schema/ItemsVisitor.mjs +12 -0
- package/src/refractor/visitors/json-schema/index.cjs +28 -0
- package/src/refractor/visitors/json-schema/index.mjs +23 -0
- package/src/refractor/visitors/json-schema/link-description/index.cjs +17 -0
- package/src/refractor/visitors/json-schema/link-description/index.mjs +12 -0
- package/src/traversal/visitor.cjs +17 -0
- package/src/traversal/visitor.mjs +13 -0
- package/types/apidom-ns-json-schema-draft-6.d.ts +517 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = exports.createRefractor = void 0;
|
|
6
|
+
var _ramda = require("ramda");
|
|
7
|
+
var _apidomCore = require("@speclynx/apidom-core");
|
|
8
|
+
var _specification = _interopRequireDefault(require("./specification.cjs"));
|
|
9
|
+
var _visitor = require("../traversal/visitor.cjs");
|
|
10
|
+
var _toolbox = _interopRequireDefault(require("./toolbox.cjs"));
|
|
11
|
+
/**
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
const refract = (value, {
|
|
15
|
+
specPath = ['visitors', 'document', 'objects', 'JSONSchema', '$visitor'],
|
|
16
|
+
plugins = [],
|
|
17
|
+
specificationObj = _specification.default
|
|
18
|
+
} = {}) => {
|
|
19
|
+
const element = (0, _apidomCore.refract)(value);
|
|
20
|
+
const resolvedSpec = (0, _apidomCore.dereference)(specificationObj);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* This is where generic ApiDOM becomes semantic (namespace applied).
|
|
24
|
+
* We don't allow consumers to hook into this translation.
|
|
25
|
+
* Though we allow consumers to define their onw plugins on already transformed ApiDOM.
|
|
26
|
+
*/
|
|
27
|
+
const RootVisitorClass = (0, _ramda.path)(specPath, resolvedSpec);
|
|
28
|
+
const rootVisitor = new RootVisitorClass({
|
|
29
|
+
specObj: resolvedSpec
|
|
30
|
+
});
|
|
31
|
+
(0, _apidomCore.visit)(element, rootVisitor);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Running plugins visitors means extra single traversal === performance hit.
|
|
35
|
+
*/
|
|
36
|
+
return (0, _apidomCore.dispatchRefractorPlugins)(rootVisitor.element, plugins, {
|
|
37
|
+
toolboxCreator: _toolbox.default,
|
|
38
|
+
visitorOptions: {
|
|
39
|
+
keyMap: _visitor.keyMap,
|
|
40
|
+
nodeTypeGetter: _visitor.getNodeType
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
const createRefractor = specPath => (value, options = {}) => refract(value, {
|
|
49
|
+
specPath,
|
|
50
|
+
...options
|
|
51
|
+
});
|
|
52
|
+
exports.createRefractor = createRefractor;
|
|
53
|
+
var _default = exports.default = refract;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { path } from 'ramda';
|
|
2
|
+
import { visit, dereference, refract as baseRefract, dispatchRefractorPlugins } from '@speclynx/apidom-core';
|
|
3
|
+
import specification from "./specification.mjs";
|
|
4
|
+
import { keyMap, getNodeType } from "../traversal/visitor.mjs";
|
|
5
|
+
import createToolbox from "./toolbox.mjs";
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
const refract = (value, {
|
|
10
|
+
specPath = ['visitors', 'document', 'objects', 'JSONSchema', '$visitor'],
|
|
11
|
+
plugins = [],
|
|
12
|
+
specificationObj = specification
|
|
13
|
+
} = {}) => {
|
|
14
|
+
const element = baseRefract(value);
|
|
15
|
+
const resolvedSpec = dereference(specificationObj);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* This is where generic ApiDOM becomes semantic (namespace applied).
|
|
19
|
+
* We don't allow consumers to hook into this translation.
|
|
20
|
+
* Though we allow consumers to define their onw plugins on already transformed ApiDOM.
|
|
21
|
+
*/
|
|
22
|
+
const RootVisitorClass = path(specPath, resolvedSpec);
|
|
23
|
+
const rootVisitor = new RootVisitorClass({
|
|
24
|
+
specObj: resolvedSpec
|
|
25
|
+
});
|
|
26
|
+
visit(element, rootVisitor);
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Running plugins visitors means extra single traversal === performance hit.
|
|
30
|
+
*/
|
|
31
|
+
return dispatchRefractorPlugins(rootVisitor.element, plugins, {
|
|
32
|
+
toolboxCreator: createToolbox,
|
|
33
|
+
visitorOptions: {
|
|
34
|
+
keyMap,
|
|
35
|
+
nodeTypeGetter: getNodeType
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
export const createRefractor = specPath => (value, options = {}) => refract(value, {
|
|
44
|
+
specPath,
|
|
45
|
+
...options
|
|
46
|
+
});
|
|
47
|
+
export default refract;
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _apidomCore = require("@speclynx/apidom-core");
|
|
7
|
+
var _apidomNsJsonSchemaDraft = require("@speclynx/apidom-ns-json-schema-draft-4");
|
|
8
|
+
var _JSONSchema = _interopRequireDefault(require("../../elements/JSONSchema.cjs"));
|
|
9
|
+
var _LinkDescription = _interopRequireDefault(require("../../elements/LinkDescription.cjs"));
|
|
10
|
+
var _visitor = require("../../traversal/visitor.cjs");
|
|
11
|
+
/**
|
|
12
|
+
* JSON Schema Draft 6 specification elements.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* This plugin is specific to YAML 1.2 format, which allows defining key-value pairs
|
|
17
|
+
* with empty key, empty value, or both. If the value is not provided in YAML format,
|
|
18
|
+
* this plugin compensates for this missing value with the most appropriate semantic element type.
|
|
19
|
+
*
|
|
20
|
+
* https://yaml.org/spec/1.2.2/#72-empty-nodes
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
*
|
|
24
|
+
* ```yaml
|
|
25
|
+
* $schema: http://json-schema.org/draft-06/schema#
|
|
26
|
+
* items:
|
|
27
|
+
* ```
|
|
28
|
+
* Refracting result without this plugin:
|
|
29
|
+
*
|
|
30
|
+
* (JSONSchemaElement
|
|
31
|
+
* (MemberElement
|
|
32
|
+
* (StringElement)
|
|
33
|
+
* (StringElement))
|
|
34
|
+
* (MemberElement
|
|
35
|
+
* (StringElement)
|
|
36
|
+
* (StringElement))
|
|
37
|
+
*
|
|
38
|
+
* Refracting result with this plugin:
|
|
39
|
+
*
|
|
40
|
+
* (JSONSchemaElement
|
|
41
|
+
* (MemberElement
|
|
42
|
+
* (StringElement)
|
|
43
|
+
* (StringElement))
|
|
44
|
+
* (MemberElement
|
|
45
|
+
* (StringElement)
|
|
46
|
+
* (JSONSchemaElement))
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
const isEmptyElement = element => (0, _apidomCore.isStringElement)(element) && (0, _apidomCore.includesClasses)(['yaml-e-node', 'yaml-e-scalar'], element);
|
|
50
|
+
const schema = {
|
|
51
|
+
JSONSchemaDraft6Element: {
|
|
52
|
+
additionalItems(...args) {
|
|
53
|
+
return new _JSONSchema.default(...args);
|
|
54
|
+
},
|
|
55
|
+
items(...args) {
|
|
56
|
+
return new _JSONSchema.default(...args);
|
|
57
|
+
},
|
|
58
|
+
contains(...args) {
|
|
59
|
+
return new _JSONSchema.default(...args);
|
|
60
|
+
},
|
|
61
|
+
required(...args) {
|
|
62
|
+
const element = new _apidomCore.ArrayElement(...args);
|
|
63
|
+
element.classes.push('json-schema-required');
|
|
64
|
+
return element;
|
|
65
|
+
},
|
|
66
|
+
properties(...args) {
|
|
67
|
+
const element = new _apidomCore.ObjectElement(...args);
|
|
68
|
+
element.classes.push('json-schema-properties');
|
|
69
|
+
return element;
|
|
70
|
+
},
|
|
71
|
+
additionalProperties(...args) {
|
|
72
|
+
return new _JSONSchema.default(...args);
|
|
73
|
+
},
|
|
74
|
+
patternProperties(...args) {
|
|
75
|
+
const element = new _apidomCore.ObjectElement(...args);
|
|
76
|
+
element.classes.push('json-schema-patternProperties');
|
|
77
|
+
return element;
|
|
78
|
+
},
|
|
79
|
+
dependencies(...args) {
|
|
80
|
+
const element = new _apidomCore.ObjectElement(...args);
|
|
81
|
+
element.classes.push('json-schema-dependencies');
|
|
82
|
+
return element;
|
|
83
|
+
},
|
|
84
|
+
propertyNames(...args) {
|
|
85
|
+
return new _JSONSchema.default(...args);
|
|
86
|
+
},
|
|
87
|
+
enum(...args) {
|
|
88
|
+
const element = new _apidomCore.ArrayElement(...args);
|
|
89
|
+
element.classes.push('json-schema-enum');
|
|
90
|
+
return element;
|
|
91
|
+
},
|
|
92
|
+
allOf(...args) {
|
|
93
|
+
const element = new _apidomCore.ArrayElement(...args);
|
|
94
|
+
element.classes.push('json-schema-allOf');
|
|
95
|
+
return element;
|
|
96
|
+
},
|
|
97
|
+
anyOf(...args) {
|
|
98
|
+
const element = new _apidomCore.ArrayElement(...args);
|
|
99
|
+
element.classes.push('json-schema-anyOf');
|
|
100
|
+
return element;
|
|
101
|
+
},
|
|
102
|
+
oneOf(...args) {
|
|
103
|
+
const element = new _apidomCore.ArrayElement(...args);
|
|
104
|
+
element.classes.push('json-schema-oneOf');
|
|
105
|
+
return element;
|
|
106
|
+
},
|
|
107
|
+
not(...args) {
|
|
108
|
+
return new _JSONSchema.default(...args);
|
|
109
|
+
},
|
|
110
|
+
definitions(...args) {
|
|
111
|
+
const element = new _apidomCore.ObjectElement(...args);
|
|
112
|
+
element.classes.push('json-schema-definitions');
|
|
113
|
+
return element;
|
|
114
|
+
},
|
|
115
|
+
examples(...args) {
|
|
116
|
+
const element = new _apidomCore.ArrayElement(...args);
|
|
117
|
+
element.classes.push('json-schema-examples');
|
|
118
|
+
return element;
|
|
119
|
+
},
|
|
120
|
+
links(...args) {
|
|
121
|
+
const element = new _apidomCore.ArrayElement(...args);
|
|
122
|
+
element.classes.push('json-schema-links');
|
|
123
|
+
return element;
|
|
124
|
+
},
|
|
125
|
+
media(...args) {
|
|
126
|
+
return new _apidomNsJsonSchemaDraft.MediaElement(...args);
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
LinkDescriptionElement: {
|
|
130
|
+
hrefSchema(...args) {
|
|
131
|
+
return new _JSONSchema.default(...args);
|
|
132
|
+
},
|
|
133
|
+
targetSchema(...args) {
|
|
134
|
+
return new _JSONSchema.default(...args);
|
|
135
|
+
},
|
|
136
|
+
submissionSchema(...args) {
|
|
137
|
+
return new _JSONSchema.default(...args);
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
'json-schema-properties': {
|
|
141
|
+
'[key: *]': function key(...args) {
|
|
142
|
+
return new _JSONSchema.default(...args);
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
'json-schema-patternProperties': {
|
|
146
|
+
'[key: *]': function key(...args) {
|
|
147
|
+
return new _JSONSchema.default(...args);
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
'json-schema-dependencies': {
|
|
151
|
+
'[key: *]': function key(...args) {
|
|
152
|
+
return new _JSONSchema.default(...args);
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
'json-schema-allOf': {
|
|
156
|
+
'<*>': function asterisk(...args) {
|
|
157
|
+
return new _JSONSchema.default(...args);
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
'json-schema-anyOf': {
|
|
161
|
+
'<*>': function asterisk(...args) {
|
|
162
|
+
return new _JSONSchema.default(...args);
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
'json-schema-oneOf': {
|
|
166
|
+
'<*>': function asterisk(...args) {
|
|
167
|
+
return new _JSONSchema.default(...args);
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
'json-schema-definitions': {
|
|
171
|
+
'[key: *]': function key(...args) {
|
|
172
|
+
return new _JSONSchema.default(...args);
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
'json-schema-links': {
|
|
176
|
+
'<*>': function asterisk(...args) {
|
|
177
|
+
return new _LinkDescription.default(...args);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
const findElementFactory = (ancestor, keyName) => {
|
|
182
|
+
const elementType = (0, _visitor.getNodeType)(ancestor); // @ts-ignore
|
|
183
|
+
const keyMapping = schema[elementType] || schema[(0, _apidomCore.toValue)(ancestor.classes.first)];
|
|
184
|
+
return typeof keyMapping === 'undefined' ? undefined : Object.hasOwn(keyMapping, '[key: *]') ? keyMapping['[key: *]'] : keyMapping[keyName];
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* @public
|
|
189
|
+
*/
|
|
190
|
+
const plugin = () => () => ({
|
|
191
|
+
visitor: {
|
|
192
|
+
StringElement(element, key, parent, path, ancestors) {
|
|
193
|
+
if (!isEmptyElement(element)) return undefined;
|
|
194
|
+
const lineage = [...ancestors, parent].filter(_apidomCore.isElement);
|
|
195
|
+
const parentElement = lineage.at(-1);
|
|
196
|
+
let elementFactory;
|
|
197
|
+
let context;
|
|
198
|
+
if ((0, _apidomCore.isArrayElement)(parentElement)) {
|
|
199
|
+
context = element;
|
|
200
|
+
elementFactory = findElementFactory(parentElement, '<*>');
|
|
201
|
+
} else if ((0, _apidomCore.isMemberElement)(parentElement)) {
|
|
202
|
+
context = lineage.at(-2);
|
|
203
|
+
elementFactory = findElementFactory(context, (0, _apidomCore.toValue)(parentElement.key));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// no element factory found
|
|
207
|
+
if (typeof elementFactory !== 'function') return undefined;
|
|
208
|
+
return elementFactory.call({
|
|
209
|
+
context
|
|
210
|
+
}, undefined, (0, _apidomCore.cloneDeep)(element.meta), (0, _apidomCore.cloneDeep)(element.attributes));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
var _default = exports.default = plugin;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { ArrayElement, ObjectElement, isStringElement, isArrayElement, isElement, isMemberElement, includesClasses, cloneDeep, toValue } from '@speclynx/apidom-core';
|
|
2
|
+
/**
|
|
3
|
+
* JSON Schema Draft 6 specification elements.
|
|
4
|
+
*/
|
|
5
|
+
import { MediaElement } from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
6
|
+
import JSONSchemaElement from "../../elements/JSONSchema.mjs";
|
|
7
|
+
import LinkDescriptionElement from "../../elements/LinkDescription.mjs";
|
|
8
|
+
import { getNodeType } from "../../traversal/visitor.mjs";
|
|
9
|
+
/**
|
|
10
|
+
* This plugin is specific to YAML 1.2 format, which allows defining key-value pairs
|
|
11
|
+
* with empty key, empty value, or both. If the value is not provided in YAML format,
|
|
12
|
+
* this plugin compensates for this missing value with the most appropriate semantic element type.
|
|
13
|
+
*
|
|
14
|
+
* https://yaml.org/spec/1.2.2/#72-empty-nodes
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
*
|
|
18
|
+
* ```yaml
|
|
19
|
+
* $schema: http://json-schema.org/draft-06/schema#
|
|
20
|
+
* items:
|
|
21
|
+
* ```
|
|
22
|
+
* Refracting result without this plugin:
|
|
23
|
+
*
|
|
24
|
+
* (JSONSchemaElement
|
|
25
|
+
* (MemberElement
|
|
26
|
+
* (StringElement)
|
|
27
|
+
* (StringElement))
|
|
28
|
+
* (MemberElement
|
|
29
|
+
* (StringElement)
|
|
30
|
+
* (StringElement))
|
|
31
|
+
*
|
|
32
|
+
* Refracting result with this plugin:
|
|
33
|
+
*
|
|
34
|
+
* (JSONSchemaElement
|
|
35
|
+
* (MemberElement
|
|
36
|
+
* (StringElement)
|
|
37
|
+
* (StringElement))
|
|
38
|
+
* (MemberElement
|
|
39
|
+
* (StringElement)
|
|
40
|
+
* (JSONSchemaElement))
|
|
41
|
+
*/
|
|
42
|
+
const isEmptyElement = element => isStringElement(element) && includesClasses(['yaml-e-node', 'yaml-e-scalar'], element);
|
|
43
|
+
const schema = {
|
|
44
|
+
JSONSchemaDraft6Element: {
|
|
45
|
+
additionalItems(...args) {
|
|
46
|
+
return new JSONSchemaElement(...args);
|
|
47
|
+
},
|
|
48
|
+
items(...args) {
|
|
49
|
+
return new JSONSchemaElement(...args);
|
|
50
|
+
},
|
|
51
|
+
contains(...args) {
|
|
52
|
+
return new JSONSchemaElement(...args);
|
|
53
|
+
},
|
|
54
|
+
required(...args) {
|
|
55
|
+
const element = new ArrayElement(...args);
|
|
56
|
+
element.classes.push('json-schema-required');
|
|
57
|
+
return element;
|
|
58
|
+
},
|
|
59
|
+
properties(...args) {
|
|
60
|
+
const element = new ObjectElement(...args);
|
|
61
|
+
element.classes.push('json-schema-properties');
|
|
62
|
+
return element;
|
|
63
|
+
},
|
|
64
|
+
additionalProperties(...args) {
|
|
65
|
+
return new JSONSchemaElement(...args);
|
|
66
|
+
},
|
|
67
|
+
patternProperties(...args) {
|
|
68
|
+
const element = new ObjectElement(...args);
|
|
69
|
+
element.classes.push('json-schema-patternProperties');
|
|
70
|
+
return element;
|
|
71
|
+
},
|
|
72
|
+
dependencies(...args) {
|
|
73
|
+
const element = new ObjectElement(...args);
|
|
74
|
+
element.classes.push('json-schema-dependencies');
|
|
75
|
+
return element;
|
|
76
|
+
},
|
|
77
|
+
propertyNames(...args) {
|
|
78
|
+
return new JSONSchemaElement(...args);
|
|
79
|
+
},
|
|
80
|
+
enum(...args) {
|
|
81
|
+
const element = new ArrayElement(...args);
|
|
82
|
+
element.classes.push('json-schema-enum');
|
|
83
|
+
return element;
|
|
84
|
+
},
|
|
85
|
+
allOf(...args) {
|
|
86
|
+
const element = new ArrayElement(...args);
|
|
87
|
+
element.classes.push('json-schema-allOf');
|
|
88
|
+
return element;
|
|
89
|
+
},
|
|
90
|
+
anyOf(...args) {
|
|
91
|
+
const element = new ArrayElement(...args);
|
|
92
|
+
element.classes.push('json-schema-anyOf');
|
|
93
|
+
return element;
|
|
94
|
+
},
|
|
95
|
+
oneOf(...args) {
|
|
96
|
+
const element = new ArrayElement(...args);
|
|
97
|
+
element.classes.push('json-schema-oneOf');
|
|
98
|
+
return element;
|
|
99
|
+
},
|
|
100
|
+
not(...args) {
|
|
101
|
+
return new JSONSchemaElement(...args);
|
|
102
|
+
},
|
|
103
|
+
definitions(...args) {
|
|
104
|
+
const element = new ObjectElement(...args);
|
|
105
|
+
element.classes.push('json-schema-definitions');
|
|
106
|
+
return element;
|
|
107
|
+
},
|
|
108
|
+
examples(...args) {
|
|
109
|
+
const element = new ArrayElement(...args);
|
|
110
|
+
element.classes.push('json-schema-examples');
|
|
111
|
+
return element;
|
|
112
|
+
},
|
|
113
|
+
links(...args) {
|
|
114
|
+
const element = new ArrayElement(...args);
|
|
115
|
+
element.classes.push('json-schema-links');
|
|
116
|
+
return element;
|
|
117
|
+
},
|
|
118
|
+
media(...args) {
|
|
119
|
+
return new MediaElement(...args);
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
LinkDescriptionElement: {
|
|
123
|
+
hrefSchema(...args) {
|
|
124
|
+
return new JSONSchemaElement(...args);
|
|
125
|
+
},
|
|
126
|
+
targetSchema(...args) {
|
|
127
|
+
return new JSONSchemaElement(...args);
|
|
128
|
+
},
|
|
129
|
+
submissionSchema(...args) {
|
|
130
|
+
return new JSONSchemaElement(...args);
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
'json-schema-properties': {
|
|
134
|
+
'[key: *]': function key(...args) {
|
|
135
|
+
return new JSONSchemaElement(...args);
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
'json-schema-patternProperties': {
|
|
139
|
+
'[key: *]': function key(...args) {
|
|
140
|
+
return new JSONSchemaElement(...args);
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
'json-schema-dependencies': {
|
|
144
|
+
'[key: *]': function key(...args) {
|
|
145
|
+
return new JSONSchemaElement(...args);
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
'json-schema-allOf': {
|
|
149
|
+
'<*>': function asterisk(...args) {
|
|
150
|
+
return new JSONSchemaElement(...args);
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
'json-schema-anyOf': {
|
|
154
|
+
'<*>': function asterisk(...args) {
|
|
155
|
+
return new JSONSchemaElement(...args);
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
'json-schema-oneOf': {
|
|
159
|
+
'<*>': function asterisk(...args) {
|
|
160
|
+
return new JSONSchemaElement(...args);
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
'json-schema-definitions': {
|
|
164
|
+
'[key: *]': function key(...args) {
|
|
165
|
+
return new JSONSchemaElement(...args);
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
'json-schema-links': {
|
|
169
|
+
'<*>': function asterisk(...args) {
|
|
170
|
+
return new LinkDescriptionElement(...args);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
const findElementFactory = (ancestor, keyName) => {
|
|
175
|
+
const elementType = getNodeType(ancestor); // @ts-ignore
|
|
176
|
+
const keyMapping = schema[elementType] || schema[toValue(ancestor.classes.first)];
|
|
177
|
+
return typeof keyMapping === 'undefined' ? undefined : Object.hasOwn(keyMapping, '[key: *]') ? keyMapping['[key: *]'] : keyMapping[keyName];
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* @public
|
|
182
|
+
*/
|
|
183
|
+
const plugin = () => () => ({
|
|
184
|
+
visitor: {
|
|
185
|
+
StringElement(element, key, parent, path, ancestors) {
|
|
186
|
+
if (!isEmptyElement(element)) return undefined;
|
|
187
|
+
const lineage = [...ancestors, parent].filter(isElement);
|
|
188
|
+
const parentElement = lineage.at(-1);
|
|
189
|
+
let elementFactory;
|
|
190
|
+
let context;
|
|
191
|
+
if (isArrayElement(parentElement)) {
|
|
192
|
+
context = element;
|
|
193
|
+
elementFactory = findElementFactory(parentElement, '<*>');
|
|
194
|
+
} else if (isMemberElement(parentElement)) {
|
|
195
|
+
context = lineage.at(-2);
|
|
196
|
+
elementFactory = findElementFactory(context, toValue(parentElement.key));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// no element factory found
|
|
200
|
+
if (typeof elementFactory !== 'function') return undefined;
|
|
201
|
+
return elementFactory.call({
|
|
202
|
+
context
|
|
203
|
+
}, undefined, cloneDeep(element.meta), cloneDeep(element.attributes));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
export default plugin;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
var _JSONSchema = _interopRequireDefault(require("../elements/JSONSchema.cjs"));
|
|
6
|
+
exports.JSONSchemaElement = _JSONSchema.default;
|
|
7
|
+
var _LinkDescription = _interopRequireDefault(require("../elements/LinkDescription.cjs"));
|
|
8
|
+
exports.LinkDescriptionElement = _LinkDescription.default;
|
|
9
|
+
var _index = require("./index.cjs");
|
|
10
|
+
// register refractors specific to element types
|
|
11
|
+
|
|
12
|
+
_JSONSchema.default.refract = (0, _index.createRefractor)(['visitors', 'document', 'objects', 'JSONSchema', '$visitor']);
|
|
13
|
+
_LinkDescription.default.refract = (0, _index.createRefractor)(['visitors', 'document', 'objects', 'LinkDescription', '$visitor']);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import JSONSchemaElement from "../elements/JSONSchema.mjs";
|
|
2
|
+
import LinkDescriptionElement from "../elements/LinkDescription.mjs";
|
|
3
|
+
import { createRefractor } from "./index.mjs"; // register refractors specific to element types
|
|
4
|
+
JSONSchemaElement.refract = createRefractor(['visitors', 'document', 'objects', 'JSONSchema', '$visitor']);
|
|
5
|
+
LinkDescriptionElement.refract = createRefractor(['visitors', 'document', 'objects', 'LinkDescription', '$visitor']);
|
|
6
|
+
export { JSONSchemaElement, LinkDescriptionElement };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _ramda = require("ramda");
|
|
7
|
+
var _apidomNsJsonSchemaDraft = require("@speclynx/apidom-ns-json-schema-draft-4");
|
|
8
|
+
var _index = _interopRequireDefault(require("./visitors/json-schema/index.cjs"));
|
|
9
|
+
var _ItemsVisitor = _interopRequireDefault(require("./visitors/json-schema/ItemsVisitor.cjs"));
|
|
10
|
+
var _ExamplesVisitor = _interopRequireDefault(require("./visitors/json-schema/ExamplesVisitor.cjs"));
|
|
11
|
+
var _index2 = _interopRequireDefault(require("./visitors/json-schema/link-description/index.cjs"));
|
|
12
|
+
const specification = (0, _ramda.pipe)(
|
|
13
|
+
// JSON Schema object modifications
|
|
14
|
+
(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'], _apidomNsJsonSchemaDraft.specificationObj.visitors.value), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'contains'], _apidomNsJsonSchemaDraft.specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'items'], _ItemsVisitor.default), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'propertyNames'], _apidomNsJsonSchemaDraft.specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'const'], _apidomNsJsonSchemaDraft.specificationObj.visitors.value), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'examples'], _ExamplesVisitor.default),
|
|
15
|
+
// 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'], _apidomNsJsonSchemaDraft.specificationObj.visitors.value))(_apidomNsJsonSchemaDraft.specificationObj);
|
|
17
|
+
var _default = exports.default = specification;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { pipe, assocPath, dissocPath } from 'ramda';
|
|
2
|
+
import { specificationObj } from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
3
|
+
import JSONSchemaVisitor from "./visitors/json-schema/index.mjs";
|
|
4
|
+
import JSONSchemaItemsVisitor from "./visitors/json-schema/ItemsVisitor.mjs";
|
|
5
|
+
import JSONSchemaExamplesVisitor from "./visitors/json-schema/ExamplesVisitor.mjs";
|
|
6
|
+
import LinkDescriptionVisitor from "./visitors/json-schema/link-description/index.mjs";
|
|
7
|
+
const specification = pipe(
|
|
8
|
+
// JSON Schema object modifications
|
|
9
|
+
assocPath(['visitors', 'document', 'objects', 'JSONSchema', '$visitor'], JSONSchemaVisitor), dissocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'id']), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', '$id'], specificationObj.visitors.value), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'contains'], specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'items'], JSONSchemaItemsVisitor), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'propertyNames'], specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'const'], specificationObj.visitors.value), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'examples'], JSONSchemaExamplesVisitor),
|
|
10
|
+
// 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'], specificationObj.visitors.value))(specificationObj);
|
|
12
|
+
export default specification;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _apidomCore = require("@speclynx/apidom-core");
|
|
8
|
+
var jsonSchemaDraft6Predicates = _interopRequireWildcard(require("../predicates.cjs"));
|
|
9
|
+
var _namespace = _interopRequireDefault(require("../namespace.cjs"));
|
|
10
|
+
const createToolbox = () => {
|
|
11
|
+
const namespace = (0, _apidomCore.createNamespace)(_namespace.default);
|
|
12
|
+
const predicates = {
|
|
13
|
+
...jsonSchemaDraft6Predicates,
|
|
14
|
+
isStringElement: _apidomCore.isStringElement
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
predicates,
|
|
18
|
+
namespace
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
var _default = exports.default = createToolbox;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createNamespace, isStringElement } from '@speclynx/apidom-core';
|
|
2
|
+
import * as jsonSchemaDraft6Predicates from "../predicates.mjs";
|
|
3
|
+
import jsonSchemaDraft6Namespace from "../namespace.mjs";
|
|
4
|
+
const createToolbox = () => {
|
|
5
|
+
const namespace = createNamespace(jsonSchemaDraft6Namespace);
|
|
6
|
+
const predicates = {
|
|
7
|
+
...jsonSchemaDraft6Predicates,
|
|
8
|
+
isStringElement
|
|
9
|
+
};
|
|
10
|
+
return {
|
|
11
|
+
predicates,
|
|
12
|
+
namespace
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export default createToolbox;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
var _apidomNsJsonSchemaDraft = require("@speclynx/apidom-ns-json-schema-draft-4");
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
class ExamplesVisitor extends _apidomNsJsonSchemaDraft.FallbackVisitor {
|
|
10
|
+
ArrayElement(arrayElement) {
|
|
11
|
+
const result = this.enter(arrayElement);
|
|
12
|
+
this.element.classes.push('json-schema-examples');
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
var _default = exports.default = ExamplesVisitor;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FallbackVisitor } from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
2
|
+
/**
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
class ExamplesVisitor extends FallbackVisitor {
|
|
6
|
+
ArrayElement(arrayElement) {
|
|
7
|
+
const result = this.enter(arrayElement);
|
|
8
|
+
this.element.classes.push('json-schema-examples');
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export default ExamplesVisitor;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
var _apidomCore = require("@speclynx/apidom-core");
|
|
6
|
+
var _apidomNsJsonSchemaDraft = require("@speclynx/apidom-ns-json-schema-draft-4");
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
class ItemsVisitor extends _apidomNsJsonSchemaDraft.ItemsVisitor {
|
|
11
|
+
BooleanElement(booleanElement) {
|
|
12
|
+
this.element = this.toRefractedElement(['document', 'objects', 'JSONSchema'], booleanElement);
|
|
13
|
+
return _apidomCore.BREAK;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
var _default = exports.default = ItemsVisitor;
|