@speclynx/apidom-ns-json-schema-draft-7 4.0.2 → 4.0.3

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 (41) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/package.json +8 -9
  3. package/src/elements/JSONSchema.cjs +122 -0
  4. package/src/elements/JSONSchema.mjs +119 -0
  5. package/src/elements/JSONSchema.ts +166 -0
  6. package/src/elements/LinkDescription.cjs +138 -0
  7. package/src/elements/LinkDescription.mjs +134 -0
  8. package/src/elements/LinkDescription.ts +194 -0
  9. package/src/index.cjs +42 -0
  10. package/src/index.mjs +13 -0
  11. package/src/index.ts +79 -0
  12. package/src/media-types.cjs +34 -0
  13. package/src/media-types.mjs +30 -0
  14. package/src/media-types.ts +40 -0
  15. package/src/namespace.cjs +23 -0
  16. package/src/namespace.mjs +18 -0
  17. package/src/namespace.ts +22 -0
  18. package/src/predicates.cjs +22 -0
  19. package/src/predicates.mjs +13 -0
  20. package/src/predicates.ts +20 -0
  21. package/src/refractor/index.cjs +76 -0
  22. package/src/refractor/index.mjs +67 -0
  23. package/src/refractor/index.ts +90 -0
  24. package/src/refractor/inspect.cjs +46 -0
  25. package/src/refractor/inspect.mjs +39 -0
  26. package/src/refractor/inspect.ts +51 -0
  27. package/src/refractor/plugins/replace-empty-element.cjs +235 -0
  28. package/src/refractor/plugins/replace-empty-element.mjs +229 -0
  29. package/src/refractor/plugins/replace-empty-element.ts +260 -0
  30. package/src/refractor/specification.cjs +15 -0
  31. package/src/refractor/specification.mjs +10 -0
  32. package/src/refractor/specification.ts +88 -0
  33. package/src/refractor/toolbox.cjs +26 -0
  34. package/src/refractor/toolbox.mjs +19 -0
  35. package/src/refractor/toolbox.ts +23 -0
  36. package/src/refractor/visitors/json-schema/index.cjs +20 -0
  37. package/src/refractor/visitors/json-schema/index.mjs +15 -0
  38. package/src/refractor/visitors/json-schema/index.ts +27 -0
  39. package/src/refractor/visitors/json-schema/link-description/index.cjs +17 -0
  40. package/src/refractor/visitors/json-schema/link-description/index.mjs +12 -0
  41. package/src/refractor/visitors/json-schema/link-description/index.ts +22 -0
@@ -0,0 +1,20 @@
1
+ import JSONSchemaElement from './elements/JSONSchema.ts';
2
+ import LinkDescriptionElement from './elements/LinkDescription.ts';
3
+
4
+ export {
5
+ isJSONReferenceElement,
6
+ isMediaElement,
7
+ isBooleanJSONSchemaElement,
8
+ } from '@speclynx/apidom-ns-json-schema-draft-6';
9
+
10
+ /**
11
+ * @public
12
+ */
13
+ export const isJSONSchemaElement = (element: unknown): element is JSONSchemaElement =>
14
+ element instanceof JSONSchemaElement;
15
+
16
+ /**
17
+ * @public
18
+ */
19
+ export const isLinkDescriptionElement = (element: unknown): element is LinkDescriptionElement =>
20
+ element instanceof LinkDescriptionElement;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
+ exports.__esModule = true;
5
+ exports.refractLinkDescription = exports.refractJSONSchema = exports.default = void 0;
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");
10
+ var _specification = _interopRequireDefault(require("./specification.cjs"));
11
+ var _toolbox = _interopRequireDefault(require("./toolbox.cjs"));
12
+ /**
13
+ * @public
14
+ */
15
+
16
+ /**
17
+ * @public
18
+ */
19
+
20
+ /**
21
+ * @public
22
+ */
23
+ const refract = (value, {
24
+ element = 'jSONSchemaDraft7',
25
+ plugins = [],
26
+ specificationObj = _specification.default,
27
+ consume = false
28
+ } = {}) => {
29
+ const genericElement = (0, _apidomDatamodel.refract)(value);
30
+ const resolvedSpec = (0, _apidomCore.resolveSpecification)(specificationObj);
31
+ const elementMap = resolvedSpec.elementMap;
32
+ const specPath = elementMap[element];
33
+ if (!specPath) {
34
+ throw new Error(`Unknown element type: "${element}"`);
35
+ }
36
+
37
+ /**
38
+ * This is where generic ApiDOM becomes semantic (namespace applied).
39
+ * We don't allow consumers to hook into this translation.
40
+ * Though we allow consumers to define their own plugins on already transformed ApiDOM.
41
+ */
42
+ const RootVisitorClass = (0, _ramda.path)(specPath, resolvedSpec);
43
+ const rootVisitor = new RootVisitorClass({
44
+ specObj: resolvedSpec,
45
+ consume
46
+ });
47
+ (0, _apidomTraverse.traverse)(genericElement, rootVisitor);
48
+
49
+ /**
50
+ * Running plugins visitors means extra single traversal === performance hit.
51
+ */
52
+ return (0, _apidomCore.dispatchRefractorPlugins)(rootVisitor.element, plugins, {
53
+ toolboxCreator: _toolbox.default
54
+ });
55
+ };
56
+
57
+ /**
58
+ * Refracts a value into a JSONSchemaElement.
59
+ * @public
60
+ */
61
+ const refractJSONSchema = (value, options = {}) => refract(value, {
62
+ ...options,
63
+ element: 'jSONSchemaDraft7'
64
+ });
65
+
66
+ /**
67
+ * Refracts a value into a LinkDescriptionElement.
68
+ * @public
69
+ */
70
+ exports.refractJSONSchema = refractJSONSchema;
71
+ const refractLinkDescription = (value, options = {}) => refract(value, {
72
+ ...options,
73
+ element: 'linkDescription'
74
+ });
75
+ exports.refractLinkDescription = refractLinkDescription;
76
+ var _default = exports.default = refract;
@@ -0,0 +1,67 @@
1
+ import { resolveSpecification, dispatchRefractorPlugins } from '@speclynx/apidom-core';
2
+ import { traverse } from '@speclynx/apidom-traverse';
3
+ import { refract as baseRefract } from '@speclynx/apidom-datamodel';
4
+ import { path } from 'ramda';
5
+ import specification from "./specification.mjs";
6
+ import createToolbox from "./toolbox.mjs";
7
+ /**
8
+ * @public
9
+ */
10
+ /**
11
+ * @public
12
+ */
13
+ /**
14
+ * @public
15
+ */
16
+ const refract = (value, {
17
+ element = 'jSONSchemaDraft7',
18
+ plugins = [],
19
+ specificationObj = specification,
20
+ consume = false
21
+ } = {}) => {
22
+ const genericElement = baseRefract(value);
23
+ const resolvedSpec = resolveSpecification(specificationObj);
24
+ const elementMap = resolvedSpec.elementMap;
25
+ const specPath = elementMap[element];
26
+ if (!specPath) {
27
+ throw new Error(`Unknown element type: "${element}"`);
28
+ }
29
+
30
+ /**
31
+ * This is where generic ApiDOM becomes semantic (namespace applied).
32
+ * We don't allow consumers to hook into this translation.
33
+ * Though we allow consumers to define their own plugins on already transformed ApiDOM.
34
+ */
35
+ const RootVisitorClass = path(specPath, resolvedSpec);
36
+ const rootVisitor = new RootVisitorClass({
37
+ specObj: resolvedSpec,
38
+ consume
39
+ });
40
+ traverse(genericElement, rootVisitor);
41
+
42
+ /**
43
+ * Running plugins visitors means extra single traversal === performance hit.
44
+ */
45
+ return dispatchRefractorPlugins(rootVisitor.element, plugins, {
46
+ toolboxCreator: createToolbox
47
+ });
48
+ };
49
+
50
+ /**
51
+ * Refracts a value into a JSONSchemaElement.
52
+ * @public
53
+ */
54
+ export const refractJSONSchema = (value, options = {}) => refract(value, {
55
+ ...options,
56
+ element: 'jSONSchemaDraft7'
57
+ });
58
+
59
+ /**
60
+ * Refracts a value into a LinkDescriptionElement.
61
+ * @public
62
+ */
63
+ export const refractLinkDescription = (value, options = {}) => refract(value, {
64
+ ...options,
65
+ element: 'linkDescription'
66
+ });
67
+ export default refract;
@@ -0,0 +1,90 @@
1
+ import { resolveSpecification, dispatchRefractorPlugins } from '@speclynx/apidom-core';
2
+ import { traverse } from '@speclynx/apidom-traverse';
3
+ import { Element, refract as baseRefract } from '@speclynx/apidom-datamodel';
4
+ import { path } from 'ramda';
5
+ import { Visitor as VisitorClass } from '@speclynx/apidom-ns-json-schema-draft-6';
6
+
7
+ import specification from './specification.ts';
8
+ import createToolbox, { type Toolbox } from './toolbox.ts';
9
+ import type JSONSchemaElement from '../elements/JSONSchema.ts';
10
+ import type LinkDescriptionElement from '../elements/LinkDescription.ts';
11
+
12
+ /**
13
+ * @public
14
+ */
15
+ export type RefractorPlugin = (toolbox: Toolbox) => {
16
+ visitor?: object;
17
+ pre?: () => void;
18
+ post?: () => void;
19
+ };
20
+
21
+ /**
22
+ * @public
23
+ */
24
+ export interface RefractorOptions {
25
+ readonly element?: string;
26
+ readonly plugins?: RefractorPlugin[];
27
+ readonly specificationObj?: typeof specification;
28
+ readonly consume?: boolean;
29
+ }
30
+
31
+ /**
32
+ * @public
33
+ */
34
+ const refract = <T extends Element>(
35
+ value: unknown,
36
+ {
37
+ element = 'jSONSchemaDraft7',
38
+ plugins = [],
39
+ specificationObj = specification,
40
+ consume = false,
41
+ }: RefractorOptions = {},
42
+ ): T => {
43
+ const genericElement = baseRefract(value);
44
+ const resolvedSpec = resolveSpecification(specificationObj);
45
+ const elementMap = resolvedSpec.elementMap as Record<string, string[]>;
46
+ const specPath = elementMap[element];
47
+
48
+ if (!specPath) {
49
+ throw new Error(`Unknown element type: "${element}"`);
50
+ }
51
+
52
+ /**
53
+ * This is where generic ApiDOM becomes semantic (namespace applied).
54
+ * We don't allow consumers to hook into this translation.
55
+ * Though we allow consumers to define their own plugins on already transformed ApiDOM.
56
+ */
57
+ const RootVisitorClass = path(specPath, resolvedSpec) as new (
58
+ options: Record<string, unknown>,
59
+ ) => InstanceType<typeof VisitorClass>;
60
+ const rootVisitor = new RootVisitorClass({ specObj: resolvedSpec, consume });
61
+
62
+ traverse(genericElement, rootVisitor);
63
+
64
+ /**
65
+ * Running plugins visitors means extra single traversal === performance hit.
66
+ */
67
+ return dispatchRefractorPlugins(rootVisitor.element, plugins, {
68
+ toolboxCreator: createToolbox,
69
+ }) as T;
70
+ };
71
+
72
+ /**
73
+ * Refracts a value into a JSONSchemaElement.
74
+ * @public
75
+ */
76
+ export const refractJSONSchema = <T extends Element = JSONSchemaElement>(
77
+ value: unknown,
78
+ options: Omit<RefractorOptions, 'element'> = {},
79
+ ): T => refract(value, { ...options, element: 'jSONSchemaDraft7' });
80
+
81
+ /**
82
+ * Refracts a value into a LinkDescriptionElement.
83
+ * @public
84
+ */
85
+ export const refractLinkDescription = <T extends Element = LinkDescriptionElement>(
86
+ value: unknown,
87
+ options: Omit<RefractorOptions, 'element'> = {},
88
+ ): T => refract(value, { ...options, element: 'linkDescription' });
89
+
90
+ 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 };
@@ -0,0 +1,51 @@
1
+ import { resolveSpecification, type ResolvedSpecification } from '@speclynx/apidom-core';
2
+ import { isPlainObject } from 'ramda-adjunct';
3
+ import { JSONReferenceElement } from '@speclynx/apidom-ns-json-schema-draft-6';
4
+
5
+ import JSONSchemaElement from '../elements/JSONSchema.ts';
6
+ import LinkDescriptionElement from '../elements/LinkDescription.ts';
7
+ import specification from './specification.ts';
8
+
9
+ /**
10
+ * @public
11
+ */
12
+ export interface FixedField {
13
+ name: string;
14
+ alias?: string;
15
+ $visitor: unknown;
16
+ }
17
+
18
+ interface ResolvedSpec extends ResolvedSpecification {
19
+ visitors: {
20
+ document: {
21
+ objects: Record<string, { fixedFields: Record<string, unknown> }>;
22
+ };
23
+ };
24
+ }
25
+
26
+ // Resolve specification to dereference $ref pointers
27
+ const resolvedSpec = resolveSpecification<ResolvedSpec>(specification);
28
+
29
+ // Extract fixed fields as list of { name, alias?, $visitor }
30
+ const getFixedFields = (fixedFieldsSpec: Record<string, unknown>): FixedField[] => {
31
+ return Object.entries(fixedFieldsSpec).map(([name, fieldSpec]) => {
32
+ if (isPlainObject(fieldSpec)) {
33
+ return { name, ...fieldSpec } as FixedField;
34
+ }
35
+ return { name, $visitor: fieldSpec };
36
+ });
37
+ };
38
+
39
+ // Define lazy getters for fixedFields on element classes
40
+ // Note: JSONReferenceElement inherits fixedFields from draft-6/draft-4
41
+ Object.defineProperty(JSONSchemaElement, 'fixedFields', {
42
+ get: () => getFixedFields(resolvedSpec.visitors.document.objects.JSONSchema.fixedFields),
43
+ enumerable: true,
44
+ });
45
+
46
+ Object.defineProperty(LinkDescriptionElement, 'fixedFields', {
47
+ get: () => getFixedFields(resolvedSpec.visitors.document.objects.LinkDescription.fixedFields),
48
+ enumerable: true,
49
+ });
50
+
51
+ export { JSONSchemaElement, JSONReferenceElement, LinkDescriptionElement };
@@ -0,0 +1,235 @@
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 _apidomDatamodel = require("@speclynx/apidom-datamodel");
7
+ var _apidomCore = require("@speclynx/apidom-core");
8
+ var _apidomTraverse = require("@speclynx/apidom-traverse");
9
+ var _JSONSchema = _interopRequireDefault(require("../../elements/JSONSchema.cjs"));
10
+ var _LinkDescription = _interopRequireDefault(require("../../elements/LinkDescription.cjs"));
11
+ /**
12
+ * This plugin is specific to YAML 1.2 format, which allows defining key-value pairs
13
+ * with empty key, empty value, or both. If the value is not provided in YAML format,
14
+ * this plugin compensates for this missing value with the most appropriate semantic element type.
15
+ *
16
+ * https://yaml.org/spec/1.2.2/#72-empty-nodes
17
+ *
18
+ * @example
19
+ *
20
+ * ```yaml
21
+ * $schema: http://json-schema.org/draft-07/schema#
22
+ * items:
23
+ * ```
24
+ * Refracting result without this plugin:
25
+ *
26
+ * (JSONSchemaElement
27
+ * (MemberElement
28
+ * (StringElement)
29
+ * (StringElement))
30
+ * (MemberElement
31
+ * (StringElement)
32
+ * (StringElement))
33
+ *
34
+ * Refracting result with this plugin:
35
+ *
36
+ * (JSONSchemaElement
37
+ * (MemberElement
38
+ * (StringElement)
39
+ * (StringElement))
40
+ * (MemberElement
41
+ * (StringElement)
42
+ * (JSONSchemaElement))
43
+ */
44
+
45
+ const isEmptyElement = element => (0, _apidomDatamodel.isStringElement)(element) && (0, _apidomDatamodel.includesClasses)(element, ['yaml-e-node', 'yaml-e-scalar']);
46
+ const schema = {
47
+ JSONSchemaDraft7Element: {
48
+ additionalItems(...args) {
49
+ return new _JSONSchema.default(...args);
50
+ },
51
+ items(...args) {
52
+ return new _JSONSchema.default(...args);
53
+ },
54
+ contains(...args) {
55
+ return new _JSONSchema.default(...args);
56
+ },
57
+ required(...args) {
58
+ const element = new _apidomDatamodel.ArrayElement(...args);
59
+ element.classes.push('json-schema-required');
60
+ return element;
61
+ },
62
+ properties(...args) {
63
+ const element = new _apidomDatamodel.ObjectElement(...args);
64
+ element.classes.push('json-schema-properties');
65
+ return element;
66
+ },
67
+ additionalProperties(...args) {
68
+ return new _JSONSchema.default(...args);
69
+ },
70
+ patternProperties(...args) {
71
+ const element = new _apidomDatamodel.ObjectElement(...args);
72
+ element.classes.push('json-schema-patternProperties');
73
+ return element;
74
+ },
75
+ dependencies(...args) {
76
+ const element = new _apidomDatamodel.ObjectElement(...args);
77
+ element.classes.push('json-schema-dependencies');
78
+ return element;
79
+ },
80
+ propertyNames(...args) {
81
+ return new _JSONSchema.default(...args);
82
+ },
83
+ enum(...args) {
84
+ const element = new _apidomDatamodel.ArrayElement(...args);
85
+ element.classes.push('json-schema-enum');
86
+ return element;
87
+ },
88
+ allOf(...args) {
89
+ const element = new _apidomDatamodel.ArrayElement(...args);
90
+ element.classes.push('json-schema-allOf');
91
+ return element;
92
+ },
93
+ anyOf(...args) {
94
+ const element = new _apidomDatamodel.ArrayElement(...args);
95
+ element.classes.push('json-schema-anyOf');
96
+ return element;
97
+ },
98
+ oneOf(...args) {
99
+ const element = new _apidomDatamodel.ArrayElement(...args);
100
+ element.classes.push('json-schema-oneOf');
101
+ return element;
102
+ },
103
+ if(...args) {
104
+ return new _JSONSchema.default(...args);
105
+ },
106
+ then(...args) {
107
+ return new _JSONSchema.default(...args);
108
+ },
109
+ else(...args) {
110
+ return new _JSONSchema.default(...args);
111
+ },
112
+ not(...args) {
113
+ return new _JSONSchema.default(...args);
114
+ },
115
+ definitions(...args) {
116
+ const element = new _apidomDatamodel.ObjectElement(...args);
117
+ element.classes.push('json-schema-definitions');
118
+ return element;
119
+ },
120
+ examples(...args) {
121
+ const element = new _apidomDatamodel.ArrayElement(...args);
122
+ element.classes.push('json-schema-examples');
123
+ return element;
124
+ },
125
+ links(...args) {
126
+ const element = new _apidomDatamodel.ArrayElement(...args);
127
+ element.classes.push('json-schema-links');
128
+ return element;
129
+ }
130
+ },
131
+ LinkDescriptionElement: {
132
+ hrefSchema(...args) {
133
+ return new _JSONSchema.default(...args);
134
+ },
135
+ targetSchema(...args) {
136
+ return new _JSONSchema.default(...args);
137
+ },
138
+ submissionSchema(...args) {
139
+ return new _JSONSchema.default(...args);
140
+ },
141
+ templatePointers(...args) {
142
+ return new _apidomDatamodel.ObjectElement(...args);
143
+ },
144
+ templateRequired(...args) {
145
+ return new _apidomDatamodel.ArrayElement(...args);
146
+ },
147
+ targetHints(...args) {
148
+ return new _apidomDatamodel.ObjectElement(...args);
149
+ },
150
+ headerSchema(...args) {
151
+ return new _JSONSchema.default(...args);
152
+ }
153
+ },
154
+ 'json-schema-properties': {
155
+ '[key: *]': function key(...args) {
156
+ return new _JSONSchema.default(...args);
157
+ }
158
+ },
159
+ 'json-schema-patternProperties': {
160
+ '[key: *]': function key(...args) {
161
+ return new _JSONSchema.default(...args);
162
+ }
163
+ },
164
+ 'json-schema-dependencies': {
165
+ '[key: *]': function key(...args) {
166
+ return new _JSONSchema.default(...args);
167
+ }
168
+ },
169
+ 'json-schema-allOf': {
170
+ '<*>': function asterisk(...args) {
171
+ return new _JSONSchema.default(...args);
172
+ }
173
+ },
174
+ 'json-schema-anyOf': {
175
+ '<*>': function asterisk(...args) {
176
+ return new _JSONSchema.default(...args);
177
+ }
178
+ },
179
+ 'json-schema-oneOf': {
180
+ '<*>': function asterisk(...args) {
181
+ return new _JSONSchema.default(...args);
182
+ }
183
+ },
184
+ 'json-schema-definitions': {
185
+ '[key: *]': function key(...args) {
186
+ return new _JSONSchema.default(...args);
187
+ }
188
+ },
189
+ 'json-schema-links': {
190
+ '<*>': function asterisk(...args) {
191
+ return new _LinkDescription.default(...args);
192
+ }
193
+ }
194
+ };
195
+ const findElementFactory = (ancestor, keyName) => {
196
+ const elementType = (0, _apidomTraverse.getNodeType)(ancestor);
197
+ const classType = ancestor.isMetaEmpty ? undefined : ancestor.classes.at(0); // @ts-ignore
198
+ const keyMapping = schema[elementType] || schema[classType];
199
+ return typeof keyMapping === 'undefined' ? undefined : Object.hasOwn(keyMapping, '[key: *]') ? keyMapping['[key: *]'] : keyMapping[keyName];
200
+ };
201
+
202
+ /**
203
+ * @public
204
+ */
205
+ const plugin = () => () => ({
206
+ visitor: {
207
+ StringElement(path) {
208
+ const element = path.node;
209
+ if (!isEmptyElement(element)) return;
210
+
211
+ // getAncestorNodes() returns [parent, grandparent, ..., root], so reverse to get [root, ..., parent]
212
+ const lineage = path.getAncestorNodes().reverse().filter(_apidomDatamodel.isElement);
213
+ const parentElement = lineage.at(-1);
214
+ let elementFactory;
215
+ let context;
216
+ if ((0, _apidomDatamodel.isArrayElement)(parentElement)) {
217
+ context = element;
218
+ elementFactory = findElementFactory(parentElement, '<*>');
219
+ } else if ((0, _apidomDatamodel.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;
226
+ const replacement = elementFactory.call({
227
+ context
228
+ }, undefined, element.isMetaEmpty ? undefined : element.meta.cloneDeep(), element.isAttributesEmpty ? undefined : (0, _apidomDatamodel.cloneDeep)(element.attributes));
229
+ _apidomDatamodel.SourceMapElement.transfer(element, replacement);
230
+ _apidomDatamodel.StyleElement.transfer(element, replacement);
231
+ path.replaceWith(replacement);
232
+ }
233
+ }
234
+ });
235
+ var _default = exports.default = plugin;