@speclynx/apidom-ns-json-schema-draft-7 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.
Files changed (39) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/LICENSE +202 -0
  3. package/LICENSES/AFL-3.0.txt +182 -0
  4. package/LICENSES/Apache-2.0.txt +202 -0
  5. package/LICENSES/BSD-3-Clause.txt +26 -0
  6. package/LICENSES/MIT.txt +9 -0
  7. package/NOTICE +65 -0
  8. package/README.md +188 -0
  9. package/dist/apidom-ns-json-schema-draft-7.browser.js +1 -0
  10. package/package.json +65 -0
  11. package/src/elements/JSONSchema.cjs +121 -0
  12. package/src/elements/JSONSchema.mjs +118 -0
  13. package/src/elements/LinkDescription.cjs +138 -0
  14. package/src/elements/LinkDescription.mjs +134 -0
  15. package/src/index.cjs +54 -0
  16. package/src/index.mjs +16 -0
  17. package/src/media-types.cjs +34 -0
  18. package/src/media-types.mjs +30 -0
  19. package/src/namespace.cjs +23 -0
  20. package/src/namespace.mjs +18 -0
  21. package/src/predicates.cjs +31 -0
  22. package/src/predicates.mjs +26 -0
  23. package/src/refractor/index.cjs +54 -0
  24. package/src/refractor/index.mjs +48 -0
  25. package/src/refractor/plugins/replace-empty-element.cjs +233 -0
  26. package/src/refractor/plugins/replace-empty-element.mjs +226 -0
  27. package/src/refractor/registration.cjs +13 -0
  28. package/src/refractor/registration.mjs +6 -0
  29. package/src/refractor/specification.cjs +15 -0
  30. package/src/refractor/specification.mjs +10 -0
  31. package/src/refractor/toolbox.cjs +21 -0
  32. package/src/refractor/toolbox.mjs +15 -0
  33. package/src/refractor/visitors/json-schema/index.cjs +20 -0
  34. package/src/refractor/visitors/json-schema/index.mjs +15 -0
  35. package/src/refractor/visitors/json-schema/link-description/index.cjs +17 -0
  36. package/src/refractor/visitors/json-schema/link-description/index.mjs +12 -0
  37. package/src/traversal/visitor.cjs +16 -0
  38. package/src/traversal/visitor.mjs +12 -0
  39. package/types/apidom-ns-json-schema-draft-7.d.ts +551 -0
@@ -0,0 +1,30 @@
1
+ import { last } from 'ramda';
2
+ import { MediaTypes } from '@speclynx/apidom-core';
3
+
4
+ /**
5
+ * @public
6
+ */
7
+
8
+ /**
9
+ * @public
10
+ */
11
+ export class JSONSchemaDraft7MediaTypes extends MediaTypes {
12
+ filterByFormat(format = 'generic') {
13
+ const effectiveFormat = format === 'generic' ? 'schema;version' : format;
14
+ return this.filter(mediaType => mediaType.includes(effectiveFormat));
15
+ }
16
+ findBy(version = 'draft-07', format = 'generic') {
17
+ const search = format === 'generic' ? `schema;version=${version}` : `schema+${format};version=${version}`;
18
+ const found = this.find(mediaType => mediaType.includes(search));
19
+ return found || this.unknownMediaType;
20
+ }
21
+ latest(format = 'generic') {
22
+ return last(this.filterByFormat(format));
23
+ }
24
+ }
25
+
26
+ /**
27
+ * @public
28
+ */
29
+ const mediaTypes = new JSONSchemaDraft7MediaTypes('application/schema;version=draft-07', 'application/schema+json;version=draft-07', 'application/schema+yaml;version=draft-07');
30
+ export default mediaTypes;
@@ -0,0 +1,23 @@
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 _apidomNsJsonSchemaDraft = require("@speclynx/apidom-ns-json-schema-draft-6");
7
+ var _JSONSchema = _interopRequireDefault(require("./elements/JSONSchema.cjs"));
8
+ var _LinkDescription = _interopRequireDefault(require("./elements/LinkDescription.cjs"));
9
+ /**
10
+ * @public
11
+ */
12
+ const jsonSchemaDraft7 = {
13
+ namespace: options => {
14
+ const {
15
+ base
16
+ } = options;
17
+ base.register('jSONSchemaDraft7', _JSONSchema.default);
18
+ base.register('jSONReference', _apidomNsJsonSchemaDraft.JSONReferenceElement);
19
+ base.register('linkDescription', _LinkDescription.default);
20
+ return base;
21
+ }
22
+ };
23
+ var _default = exports.default = jsonSchemaDraft7;
@@ -0,0 +1,18 @@
1
+ import { JSONReferenceElement } from '@speclynx/apidom-ns-json-schema-draft-6';
2
+ import JSONSchemaElement from "./elements/JSONSchema.mjs";
3
+ import LinkDescriptionElement from "./elements/LinkDescription.mjs";
4
+ /**
5
+ * @public
6
+ */
7
+ const jsonSchemaDraft7 = {
8
+ namespace: options => {
9
+ const {
10
+ base
11
+ } = options;
12
+ base.register('jSONSchemaDraft7', JSONSchemaElement);
13
+ base.register('jSONReference', JSONReferenceElement);
14
+ base.register('linkDescription', LinkDescriptionElement);
15
+ return base;
16
+ }
17
+ };
18
+ export default jsonSchemaDraft7;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
+ exports.__esModule = true;
5
+ exports.isLinkDescriptionElement = exports.isJSONSchemaElement = exports.isJSONReferenceElement = void 0;
6
+ var _apidomCore = require("@speclynx/apidom-core");
7
+ var _JSONSchema = _interopRequireDefault(require("./elements/JSONSchema.cjs"));
8
+ var _LinkDescription = _interopRequireDefault(require("./elements/LinkDescription.cjs"));
9
+ var _apidomNsJsonSchemaDraft = require("@speclynx/apidom-ns-json-schema-draft-6");
10
+ exports.isJSONReferenceElement = _apidomNsJsonSchemaDraft.isJSONReferenceElement;
11
+ /**
12
+ * @public
13
+ */
14
+ const isJSONSchemaElement = exports.isJSONSchemaElement = (0, _apidomCore.createPredicate)(({
15
+ hasBasicElementProps,
16
+ isElementType,
17
+ primitiveEq
18
+ }) => {
19
+ return element => element instanceof _JSONSchema.default || hasBasicElementProps(element) && isElementType('JSONSchemaDraft7', element) && primitiveEq('object', element);
20
+ });
21
+
22
+ /**
23
+ * @public
24
+ */
25
+ const isLinkDescriptionElement = exports.isLinkDescriptionElement = (0, _apidomCore.createPredicate)(({
26
+ hasBasicElementProps,
27
+ isElementType,
28
+ primitiveEq
29
+ }) => {
30
+ return element => element instanceof _LinkDescription.default || hasBasicElementProps(element) && isElementType('linkDescription', element) && primitiveEq('object', element);
31
+ });
@@ -0,0 +1,26 @@
1
+ import { createPredicate } from '@speclynx/apidom-core';
2
+ import JSONSchemaElement from "./elements/JSONSchema.mjs";
3
+ import LinkDescriptionElement from "./elements/LinkDescription.mjs";
4
+ export { isJSONReferenceElement } from '@speclynx/apidom-ns-json-schema-draft-6';
5
+
6
+ /**
7
+ * @public
8
+ */
9
+ export const isJSONSchemaElement = createPredicate(({
10
+ hasBasicElementProps,
11
+ isElementType,
12
+ primitiveEq
13
+ }) => {
14
+ return element => element instanceof JSONSchemaElement || hasBasicElementProps(element) && isElementType('JSONSchemaDraft7', element) && primitiveEq('object', element);
15
+ });
16
+
17
+ /**
18
+ * @public
19
+ */
20
+ export const isLinkDescriptionElement = createPredicate(({
21
+ hasBasicElementProps,
22
+ isElementType,
23
+ primitiveEq
24
+ }) => {
25
+ return element => element instanceof LinkDescriptionElement || hasBasicElementProps(element) && isElementType('linkDescription', element) && primitiveEq('object', element);
26
+ });
@@ -0,0 +1,54 @@
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
+ * Run plugins only when necessary.
35
+ * Running plugins visitors means extra single traversal === performance hit.
36
+ */
37
+ return (0, _apidomCore.dispatchRefractorPlugins)(rootVisitor.element, plugins, {
38
+ toolboxCreator: _toolbox.default,
39
+ visitorOptions: {
40
+ keyMap: _visitor.keyMap,
41
+ nodeTypeGetter: _visitor.getNodeType
42
+ }
43
+ });
44
+ };
45
+
46
+ /**
47
+ * @public
48
+ */
49
+ const createRefractor = specPath => (value, options = {}) => refract(value, {
50
+ specPath,
51
+ ...options
52
+ });
53
+ exports.createRefractor = createRefractor;
54
+ var _default = exports.default = refract;
@@ -0,0 +1,48 @@
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
+ * Run plugins only when necessary.
30
+ * Running plugins visitors means extra single traversal === performance hit.
31
+ */
32
+ return dispatchRefractorPlugins(rootVisitor.element, plugins, {
33
+ toolboxCreator: createToolbox,
34
+ visitorOptions: {
35
+ keyMap,
36
+ nodeTypeGetter: getNodeType
37
+ }
38
+ });
39
+ };
40
+
41
+ /**
42
+ * @public
43
+ */
44
+ export const createRefractor = specPath => (value, options = {}) => refract(value, {
45
+ specPath,
46
+ ...options
47
+ });
48
+ export default refract;
@@ -0,0 +1,233 @@
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 _JSONSchema = _interopRequireDefault(require("../../elements/JSONSchema.cjs"));
8
+ 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
+ /**
15
+ * This plugin is specific to YAML 1.2 format, which allows defining key-value pairs
16
+ * with empty key, empty value, or both. If the value is not provided in YAML format,
17
+ * this plugin compensates for this missing value with the most appropriate semantic element type.
18
+ *
19
+ * https://yaml.org/spec/1.2.2/#72-empty-nodes
20
+ *
21
+ * @example
22
+ *
23
+ * ```yaml
24
+ * $schema: http://json-schema.org/draft-07/schema#
25
+ * items:
26
+ * ```
27
+ * Refracting result without this plugin:
28
+ *
29
+ * (JSONSchemaElement
30
+ * (MemberElement
31
+ * (StringElement)
32
+ * (StringElement))
33
+ * (MemberElement
34
+ * (StringElement)
35
+ * (StringElement))
36
+ *
37
+ * Refracting result with this plugin:
38
+ *
39
+ * (JSONSchemaElement
40
+ * (MemberElement
41
+ * (StringElement)
42
+ * (StringElement))
43
+ * (MemberElement
44
+ * (StringElement)
45
+ * (JSONSchemaElement))
46
+ */
47
+
48
+ const isEmptyElement = element => (0, _apidomCore.isStringElement)(element) && (0, _apidomCore.includesClasses)(['yaml-e-node', 'yaml-e-scalar'], element);
49
+ const schema = {
50
+ JSONSchemaDraft7Element: {
51
+ additionalItems(...args) {
52
+ return new _JSONSchema.default(...args);
53
+ },
54
+ items(...args) {
55
+ return new _JSONSchema.default(...args);
56
+ },
57
+ contains(...args) {
58
+ return new _JSONSchema.default(...args);
59
+ },
60
+ required(...args) {
61
+ const element = new _apidomCore.ArrayElement(...args);
62
+ element.classes.push('json-schema-required');
63
+ return element;
64
+ },
65
+ properties(...args) {
66
+ const element = new _apidomCore.ObjectElement(...args);
67
+ element.classes.push('json-schema-properties');
68
+ return element;
69
+ },
70
+ additionalProperties(...args) {
71
+ return new _JSONSchema.default(...args);
72
+ },
73
+ patternProperties(...args) {
74
+ const element = new _apidomCore.ObjectElement(...args);
75
+ element.classes.push('json-schema-patternProperties');
76
+ return element;
77
+ },
78
+ dependencies(...args) {
79
+ const element = new _apidomCore.ObjectElement(...args);
80
+ element.classes.push('json-schema-dependencies');
81
+ return element;
82
+ },
83
+ propertyNames(...args) {
84
+ return new _JSONSchema.default(...args);
85
+ },
86
+ enum(...args) {
87
+ const element = new _apidomCore.ArrayElement(...args);
88
+ element.classes.push('json-schema-enum');
89
+ return element;
90
+ },
91
+ allOf(...args) {
92
+ const element = new _apidomCore.ArrayElement(...args);
93
+ element.classes.push('json-schema-allOf');
94
+ return element;
95
+ },
96
+ anyOf(...args) {
97
+ const element = new _apidomCore.ArrayElement(...args);
98
+ element.classes.push('json-schema-anyOf');
99
+ return element;
100
+ },
101
+ oneOf(...args) {
102
+ const element = new _apidomCore.ArrayElement(...args);
103
+ element.classes.push('json-schema-oneOf');
104
+ return element;
105
+ },
106
+ if(...args) {
107
+ return new _JSONSchema.default(...args);
108
+ },
109
+ then(...args) {
110
+ return new _JSONSchema.default(...args);
111
+ },
112
+ else(...args) {
113
+ return new _JSONSchema.default(...args);
114
+ },
115
+ not(...args) {
116
+ return new _JSONSchema.default(...args);
117
+ },
118
+ definitions(...args) {
119
+ const element = new _apidomCore.ObjectElement(...args);
120
+ element.classes.push('json-schema-definitions');
121
+ return element;
122
+ },
123
+ examples(...args) {
124
+ const element = new _apidomCore.ArrayElement(...args);
125
+ element.classes.push('json-schema-examples');
126
+ return element;
127
+ },
128
+ links(...args) {
129
+ const element = new _apidomCore.ArrayElement(...args);
130
+ element.classes.push('json-schema-links');
131
+ return element;
132
+ }
133
+ },
134
+ LinkDescriptionElement: {
135
+ hrefSchema(...args) {
136
+ return new _JSONSchema.default(...args);
137
+ },
138
+ targetSchema(...args) {
139
+ return new _JSONSchema.default(...args);
140
+ },
141
+ submissionSchema(...args) {
142
+ return new _JSONSchema.default(...args);
143
+ },
144
+ templatePointers(...args) {
145
+ return new _apidomCore.ObjectElement(...args);
146
+ },
147
+ templateRequired(...args) {
148
+ return new _apidomCore.ArrayElement(...args);
149
+ },
150
+ targetHints(...args) {
151
+ return new _apidomCore.ObjectElement(...args);
152
+ },
153
+ headerSchema(...args) {
154
+ return new _JSONSchema.default(...args);
155
+ }
156
+ },
157
+ 'json-schema-properties': {
158
+ '[key: *]': function key(...args) {
159
+ return new _JSONSchema.default(...args);
160
+ }
161
+ },
162
+ 'json-schema-patternProperties': {
163
+ '[key: *]': function key(...args) {
164
+ return new _JSONSchema.default(...args);
165
+ }
166
+ },
167
+ 'json-schema-dependencies': {
168
+ '[key: *]': function key(...args) {
169
+ return new _JSONSchema.default(...args);
170
+ }
171
+ },
172
+ 'json-schema-allOf': {
173
+ '<*>': function asterisk(...args) {
174
+ return new _JSONSchema.default(...args);
175
+ }
176
+ },
177
+ 'json-schema-anyOf': {
178
+ '<*>': function asterisk(...args) {
179
+ return new _JSONSchema.default(...args);
180
+ }
181
+ },
182
+ 'json-schema-oneOf': {
183
+ '<*>': function asterisk(...args) {
184
+ return new _JSONSchema.default(...args);
185
+ }
186
+ },
187
+ 'json-schema-definitions': {
188
+ '[key: *]': function key(...args) {
189
+ return new _JSONSchema.default(...args);
190
+ }
191
+ },
192
+ 'json-schema-links': {
193
+ '<*>': function asterisk(...args) {
194
+ return new _LinkDescription.default(...args);
195
+ }
196
+ }
197
+ };
198
+ const findElementFactory = (ancestor, keyName) => {
199
+ const elementType = (0, _visitor.getNodeType)(ancestor); // @ts-ignore
200
+ const keyMapping = schema[elementType] || schema[(0, _apidomCore.toValue)(ancestor.classes.first)];
201
+ return typeof keyMapping === 'undefined' ? undefined : Object.hasOwn(keyMapping, '[key: *]') ? keyMapping['[key: *]'] : keyMapping[keyName];
202
+ };
203
+
204
+ /**
205
+ * @public
206
+ */
207
+ const plugin = () => () => {
208
+ return {
209
+ visitor: {
210
+ StringElement(element, key, parent, path, ancestors) {
211
+ if (!isEmptyElement(element)) return undefined;
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
+ }
223
+
224
+ // no element factory found
225
+ if (typeof elementFactory !== 'function') return undefined;
226
+ return elementFactory.call({
227
+ context
228
+ }, undefined, (0, _apidomCore.cloneDeep)(element.meta), (0, _apidomCore.cloneDeep)(element.attributes));
229
+ }
230
+ }
231
+ };
232
+ };
233
+ var _default = exports.default = plugin;
@@ -0,0 +1,226 @@
1
+ import { ArrayElement, ObjectElement, isStringElement, isArrayElement, isElement, isMemberElement, includesClasses, cloneDeep, toValue } from '@speclynx/apidom-core';
2
+ /**
3
+ * JSON Schema Draft 7 specification elements.
4
+ */
5
+ import JSONSchemaElement from "../../elements/JSONSchema.mjs";
6
+ import LinkDescriptionElement from "../../elements/LinkDescription.mjs";
7
+ import { getNodeType } from "../../traversal/visitor.mjs";
8
+ /**
9
+ * This plugin is specific to YAML 1.2 format, which allows defining key-value pairs
10
+ * with empty key, empty value, or both. If the value is not provided in YAML format,
11
+ * this plugin compensates for this missing value with the most appropriate semantic element type.
12
+ *
13
+ * https://yaml.org/spec/1.2.2/#72-empty-nodes
14
+ *
15
+ * @example
16
+ *
17
+ * ```yaml
18
+ * $schema: http://json-schema.org/draft-07/schema#
19
+ * items:
20
+ * ```
21
+ * Refracting result without this plugin:
22
+ *
23
+ * (JSONSchemaElement
24
+ * (MemberElement
25
+ * (StringElement)
26
+ * (StringElement))
27
+ * (MemberElement
28
+ * (StringElement)
29
+ * (StringElement))
30
+ *
31
+ * Refracting result with this plugin:
32
+ *
33
+ * (JSONSchemaElement
34
+ * (MemberElement
35
+ * (StringElement)
36
+ * (StringElement))
37
+ * (MemberElement
38
+ * (StringElement)
39
+ * (JSONSchemaElement))
40
+ */
41
+ const isEmptyElement = element => isStringElement(element) && includesClasses(['yaml-e-node', 'yaml-e-scalar'], element);
42
+ const schema = {
43
+ JSONSchemaDraft7Element: {
44
+ additionalItems(...args) {
45
+ return new JSONSchemaElement(...args);
46
+ },
47
+ items(...args) {
48
+ return new JSONSchemaElement(...args);
49
+ },
50
+ contains(...args) {
51
+ return new JSONSchemaElement(...args);
52
+ },
53
+ required(...args) {
54
+ const element = new ArrayElement(...args);
55
+ element.classes.push('json-schema-required');
56
+ return element;
57
+ },
58
+ properties(...args) {
59
+ const element = new ObjectElement(...args);
60
+ element.classes.push('json-schema-properties');
61
+ return element;
62
+ },
63
+ additionalProperties(...args) {
64
+ return new JSONSchemaElement(...args);
65
+ },
66
+ patternProperties(...args) {
67
+ const element = new ObjectElement(...args);
68
+ element.classes.push('json-schema-patternProperties');
69
+ return element;
70
+ },
71
+ dependencies(...args) {
72
+ const element = new ObjectElement(...args);
73
+ element.classes.push('json-schema-dependencies');
74
+ return element;
75
+ },
76
+ propertyNames(...args) {
77
+ return new JSONSchemaElement(...args);
78
+ },
79
+ enum(...args) {
80
+ const element = new ArrayElement(...args);
81
+ element.classes.push('json-schema-enum');
82
+ return element;
83
+ },
84
+ allOf(...args) {
85
+ const element = new ArrayElement(...args);
86
+ element.classes.push('json-schema-allOf');
87
+ return element;
88
+ },
89
+ anyOf(...args) {
90
+ const element = new ArrayElement(...args);
91
+ element.classes.push('json-schema-anyOf');
92
+ return element;
93
+ },
94
+ oneOf(...args) {
95
+ const element = new ArrayElement(...args);
96
+ element.classes.push('json-schema-oneOf');
97
+ return element;
98
+ },
99
+ if(...args) {
100
+ return new JSONSchemaElement(...args);
101
+ },
102
+ then(...args) {
103
+ return new JSONSchemaElement(...args);
104
+ },
105
+ else(...args) {
106
+ return new JSONSchemaElement(...args);
107
+ },
108
+ not(...args) {
109
+ return new JSONSchemaElement(...args);
110
+ },
111
+ definitions(...args) {
112
+ const element = new ObjectElement(...args);
113
+ element.classes.push('json-schema-definitions');
114
+ return element;
115
+ },
116
+ examples(...args) {
117
+ const element = new ArrayElement(...args);
118
+ element.classes.push('json-schema-examples');
119
+ return element;
120
+ },
121
+ links(...args) {
122
+ const element = new ArrayElement(...args);
123
+ element.classes.push('json-schema-links');
124
+ return element;
125
+ }
126
+ },
127
+ LinkDescriptionElement: {
128
+ hrefSchema(...args) {
129
+ return new JSONSchemaElement(...args);
130
+ },
131
+ targetSchema(...args) {
132
+ return new JSONSchemaElement(...args);
133
+ },
134
+ submissionSchema(...args) {
135
+ return new JSONSchemaElement(...args);
136
+ },
137
+ templatePointers(...args) {
138
+ return new ObjectElement(...args);
139
+ },
140
+ templateRequired(...args) {
141
+ return new ArrayElement(...args);
142
+ },
143
+ targetHints(...args) {
144
+ return new ObjectElement(...args);
145
+ },
146
+ headerSchema(...args) {
147
+ return new JSONSchemaElement(...args);
148
+ }
149
+ },
150
+ 'json-schema-properties': {
151
+ '[key: *]': function key(...args) {
152
+ return new JSONSchemaElement(...args);
153
+ }
154
+ },
155
+ 'json-schema-patternProperties': {
156
+ '[key: *]': function key(...args) {
157
+ return new JSONSchemaElement(...args);
158
+ }
159
+ },
160
+ 'json-schema-dependencies': {
161
+ '[key: *]': function key(...args) {
162
+ return new JSONSchemaElement(...args);
163
+ }
164
+ },
165
+ 'json-schema-allOf': {
166
+ '<*>': function asterisk(...args) {
167
+ return new JSONSchemaElement(...args);
168
+ }
169
+ },
170
+ 'json-schema-anyOf': {
171
+ '<*>': function asterisk(...args) {
172
+ return new JSONSchemaElement(...args);
173
+ }
174
+ },
175
+ 'json-schema-oneOf': {
176
+ '<*>': function asterisk(...args) {
177
+ return new JSONSchemaElement(...args);
178
+ }
179
+ },
180
+ 'json-schema-definitions': {
181
+ '[key: *]': function key(...args) {
182
+ return new JSONSchemaElement(...args);
183
+ }
184
+ },
185
+ 'json-schema-links': {
186
+ '<*>': function asterisk(...args) {
187
+ return new LinkDescriptionElement(...args);
188
+ }
189
+ }
190
+ };
191
+ const findElementFactory = (ancestor, keyName) => {
192
+ const elementType = getNodeType(ancestor); // @ts-ignore
193
+ const keyMapping = schema[elementType] || schema[toValue(ancestor.classes.first)];
194
+ return typeof keyMapping === 'undefined' ? undefined : Object.hasOwn(keyMapping, '[key: *]') ? keyMapping['[key: *]'] : keyMapping[keyName];
195
+ };
196
+
197
+ /**
198
+ * @public
199
+ */
200
+ const plugin = () => () => {
201
+ return {
202
+ visitor: {
203
+ StringElement(element, key, parent, path, ancestors) {
204
+ if (!isEmptyElement(element)) return undefined;
205
+ const lineage = [...ancestors, parent].filter(isElement);
206
+ const parentElement = lineage.at(-1);
207
+ let elementFactory;
208
+ let context;
209
+ if (isArrayElement(parentElement)) {
210
+ context = element;
211
+ elementFactory = findElementFactory(parentElement, '<*>');
212
+ } else if (isMemberElement(parentElement)) {
213
+ context = lineage.at(-2);
214
+ elementFactory = findElementFactory(context, toValue(parentElement.key));
215
+ }
216
+
217
+ // no element factory found
218
+ if (typeof elementFactory !== 'function') return undefined;
219
+ return elementFactory.call({
220
+ context
221
+ }, undefined, cloneDeep(element.meta), cloneDeep(element.attributes));
222
+ }
223
+ }
224
+ };
225
+ };
226
+ export default plugin;