@speclynx/apidom-ns-json-schema-draft-7 3.2.0 → 4.0.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 +16 -0
- package/dist/apidom-ns-json-schema-draft-7.browser.js +24 -20
- package/package.json +7 -7
- package/src/elements/JSONSchema.cjs +0 -122
- package/src/elements/JSONSchema.mjs +0 -119
- package/src/elements/LinkDescription.cjs +0 -138
- package/src/elements/LinkDescription.mjs +0 -134
- package/src/index.cjs +0 -42
- package/src/index.mjs +0 -13
- package/src/media-types.cjs +0 -34
- package/src/media-types.mjs +0 -30
- package/src/namespace.cjs +0 -23
- package/src/namespace.mjs +0 -18
- package/src/predicates.cjs +0 -22
- package/src/predicates.mjs +0 -13
- package/src/refractor/index.cjs +0 -76
- package/src/refractor/index.mjs +0 -67
- package/src/refractor/inspect.cjs +0 -46
- package/src/refractor/inspect.mjs +0 -39
- package/src/refractor/plugins/replace-empty-element.cjs +0 -235
- package/src/refractor/plugins/replace-empty-element.mjs +0 -229
- package/src/refractor/specification.cjs +0 -15
- package/src/refractor/specification.mjs +0 -10
- package/src/refractor/toolbox.cjs +0 -26
- package/src/refractor/toolbox.mjs +0 -19
- package/src/refractor/visitors/json-schema/index.cjs +0 -20
- package/src/refractor/visitors/json-schema/index.mjs +0 -15
- package/src/refractor/visitors/json-schema/link-description/index.cjs +0 -17
- package/src/refractor/visitors/json-schema/link-description/index.mjs +0 -12
|
@@ -1,235 +0,0 @@
|
|
|
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;
|
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import { ArrayElement, ObjectElement, isArrayElement, isElement, isMemberElement, isStringElement, includesClasses, cloneDeep, SourceMapElement, StyleElement } from '@speclynx/apidom-datamodel';
|
|
2
|
-
import { toValue } from '@speclynx/apidom-core';
|
|
3
|
-
import { getNodeType } from '@speclynx/apidom-traverse';
|
|
4
|
-
import JSONSchemaElement from "../../elements/JSONSchema.mjs";
|
|
5
|
-
import LinkDescriptionElement from "../../elements/LinkDescription.mjs";
|
|
6
|
-
/**
|
|
7
|
-
* This plugin is specific to YAML 1.2 format, which allows defining key-value pairs
|
|
8
|
-
* with empty key, empty value, or both. If the value is not provided in YAML format,
|
|
9
|
-
* this plugin compensates for this missing value with the most appropriate semantic element type.
|
|
10
|
-
*
|
|
11
|
-
* https://yaml.org/spec/1.2.2/#72-empty-nodes
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
*
|
|
15
|
-
* ```yaml
|
|
16
|
-
* $schema: http://json-schema.org/draft-07/schema#
|
|
17
|
-
* items:
|
|
18
|
-
* ```
|
|
19
|
-
* Refracting result without this plugin:
|
|
20
|
-
*
|
|
21
|
-
* (JSONSchemaElement
|
|
22
|
-
* (MemberElement
|
|
23
|
-
* (StringElement)
|
|
24
|
-
* (StringElement))
|
|
25
|
-
* (MemberElement
|
|
26
|
-
* (StringElement)
|
|
27
|
-
* (StringElement))
|
|
28
|
-
*
|
|
29
|
-
* Refracting result with this plugin:
|
|
30
|
-
*
|
|
31
|
-
* (JSONSchemaElement
|
|
32
|
-
* (MemberElement
|
|
33
|
-
* (StringElement)
|
|
34
|
-
* (StringElement))
|
|
35
|
-
* (MemberElement
|
|
36
|
-
* (StringElement)
|
|
37
|
-
* (JSONSchemaElement))
|
|
38
|
-
*/
|
|
39
|
-
const isEmptyElement = element => isStringElement(element) && includesClasses(element, ['yaml-e-node', 'yaml-e-scalar']);
|
|
40
|
-
const schema = {
|
|
41
|
-
JSONSchemaDraft7Element: {
|
|
42
|
-
additionalItems(...args) {
|
|
43
|
-
return new JSONSchemaElement(...args);
|
|
44
|
-
},
|
|
45
|
-
items(...args) {
|
|
46
|
-
return new JSONSchemaElement(...args);
|
|
47
|
-
},
|
|
48
|
-
contains(...args) {
|
|
49
|
-
return new JSONSchemaElement(...args);
|
|
50
|
-
},
|
|
51
|
-
required(...args) {
|
|
52
|
-
const element = new ArrayElement(...args);
|
|
53
|
-
element.classes.push('json-schema-required');
|
|
54
|
-
return element;
|
|
55
|
-
},
|
|
56
|
-
properties(...args) {
|
|
57
|
-
const element = new ObjectElement(...args);
|
|
58
|
-
element.classes.push('json-schema-properties');
|
|
59
|
-
return element;
|
|
60
|
-
},
|
|
61
|
-
additionalProperties(...args) {
|
|
62
|
-
return new JSONSchemaElement(...args);
|
|
63
|
-
},
|
|
64
|
-
patternProperties(...args) {
|
|
65
|
-
const element = new ObjectElement(...args);
|
|
66
|
-
element.classes.push('json-schema-patternProperties');
|
|
67
|
-
return element;
|
|
68
|
-
},
|
|
69
|
-
dependencies(...args) {
|
|
70
|
-
const element = new ObjectElement(...args);
|
|
71
|
-
element.classes.push('json-schema-dependencies');
|
|
72
|
-
return element;
|
|
73
|
-
},
|
|
74
|
-
propertyNames(...args) {
|
|
75
|
-
return new JSONSchemaElement(...args);
|
|
76
|
-
},
|
|
77
|
-
enum(...args) {
|
|
78
|
-
const element = new ArrayElement(...args);
|
|
79
|
-
element.classes.push('json-schema-enum');
|
|
80
|
-
return element;
|
|
81
|
-
},
|
|
82
|
-
allOf(...args) {
|
|
83
|
-
const element = new ArrayElement(...args);
|
|
84
|
-
element.classes.push('json-schema-allOf');
|
|
85
|
-
return element;
|
|
86
|
-
},
|
|
87
|
-
anyOf(...args) {
|
|
88
|
-
const element = new ArrayElement(...args);
|
|
89
|
-
element.classes.push('json-schema-anyOf');
|
|
90
|
-
return element;
|
|
91
|
-
},
|
|
92
|
-
oneOf(...args) {
|
|
93
|
-
const element = new ArrayElement(...args);
|
|
94
|
-
element.classes.push('json-schema-oneOf');
|
|
95
|
-
return element;
|
|
96
|
-
},
|
|
97
|
-
if(...args) {
|
|
98
|
-
return new JSONSchemaElement(...args);
|
|
99
|
-
},
|
|
100
|
-
then(...args) {
|
|
101
|
-
return new JSONSchemaElement(...args);
|
|
102
|
-
},
|
|
103
|
-
else(...args) {
|
|
104
|
-
return new JSONSchemaElement(...args);
|
|
105
|
-
},
|
|
106
|
-
not(...args) {
|
|
107
|
-
return new JSONSchemaElement(...args);
|
|
108
|
-
},
|
|
109
|
-
definitions(...args) {
|
|
110
|
-
const element = new ObjectElement(...args);
|
|
111
|
-
element.classes.push('json-schema-definitions');
|
|
112
|
-
return element;
|
|
113
|
-
},
|
|
114
|
-
examples(...args) {
|
|
115
|
-
const element = new ArrayElement(...args);
|
|
116
|
-
element.classes.push('json-schema-examples');
|
|
117
|
-
return element;
|
|
118
|
-
},
|
|
119
|
-
links(...args) {
|
|
120
|
-
const element = new ArrayElement(...args);
|
|
121
|
-
element.classes.push('json-schema-links');
|
|
122
|
-
return element;
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
LinkDescriptionElement: {
|
|
126
|
-
hrefSchema(...args) {
|
|
127
|
-
return new JSONSchemaElement(...args);
|
|
128
|
-
},
|
|
129
|
-
targetSchema(...args) {
|
|
130
|
-
return new JSONSchemaElement(...args);
|
|
131
|
-
},
|
|
132
|
-
submissionSchema(...args) {
|
|
133
|
-
return new JSONSchemaElement(...args);
|
|
134
|
-
},
|
|
135
|
-
templatePointers(...args) {
|
|
136
|
-
return new ObjectElement(...args);
|
|
137
|
-
},
|
|
138
|
-
templateRequired(...args) {
|
|
139
|
-
return new ArrayElement(...args);
|
|
140
|
-
},
|
|
141
|
-
targetHints(...args) {
|
|
142
|
-
return new ObjectElement(...args);
|
|
143
|
-
},
|
|
144
|
-
headerSchema(...args) {
|
|
145
|
-
return new JSONSchemaElement(...args);
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
'json-schema-properties': {
|
|
149
|
-
'[key: *]': function key(...args) {
|
|
150
|
-
return new JSONSchemaElement(...args);
|
|
151
|
-
}
|
|
152
|
-
},
|
|
153
|
-
'json-schema-patternProperties': {
|
|
154
|
-
'[key: *]': function key(...args) {
|
|
155
|
-
return new JSONSchemaElement(...args);
|
|
156
|
-
}
|
|
157
|
-
},
|
|
158
|
-
'json-schema-dependencies': {
|
|
159
|
-
'[key: *]': function key(...args) {
|
|
160
|
-
return new JSONSchemaElement(...args);
|
|
161
|
-
}
|
|
162
|
-
},
|
|
163
|
-
'json-schema-allOf': {
|
|
164
|
-
'<*>': function asterisk(...args) {
|
|
165
|
-
return new JSONSchemaElement(...args);
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
'json-schema-anyOf': {
|
|
169
|
-
'<*>': function asterisk(...args) {
|
|
170
|
-
return new JSONSchemaElement(...args);
|
|
171
|
-
}
|
|
172
|
-
},
|
|
173
|
-
'json-schema-oneOf': {
|
|
174
|
-
'<*>': function asterisk(...args) {
|
|
175
|
-
return new JSONSchemaElement(...args);
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
'json-schema-definitions': {
|
|
179
|
-
'[key: *]': function key(...args) {
|
|
180
|
-
return new JSONSchemaElement(...args);
|
|
181
|
-
}
|
|
182
|
-
},
|
|
183
|
-
'json-schema-links': {
|
|
184
|
-
'<*>': function asterisk(...args) {
|
|
185
|
-
return new LinkDescriptionElement(...args);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
const findElementFactory = (ancestor, keyName) => {
|
|
190
|
-
const elementType = getNodeType(ancestor);
|
|
191
|
-
const classType = ancestor.isMetaEmpty ? undefined : ancestor.classes.at(0); // @ts-ignore
|
|
192
|
-
const keyMapping = schema[elementType] || schema[classType];
|
|
193
|
-
return typeof keyMapping === 'undefined' ? undefined : Object.hasOwn(keyMapping, '[key: *]') ? keyMapping['[key: *]'] : keyMapping[keyName];
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* @public
|
|
198
|
-
*/
|
|
199
|
-
const plugin = () => () => ({
|
|
200
|
-
visitor: {
|
|
201
|
-
StringElement(path) {
|
|
202
|
-
const element = path.node;
|
|
203
|
-
if (!isEmptyElement(element)) return;
|
|
204
|
-
|
|
205
|
-
// getAncestorNodes() returns [parent, grandparent, ..., root], so reverse to get [root, ..., parent]
|
|
206
|
-
const lineage = path.getAncestorNodes().reverse().filter(isElement);
|
|
207
|
-
const parentElement = lineage.at(-1);
|
|
208
|
-
let elementFactory;
|
|
209
|
-
let context;
|
|
210
|
-
if (isArrayElement(parentElement)) {
|
|
211
|
-
context = element;
|
|
212
|
-
elementFactory = findElementFactory(parentElement, '<*>');
|
|
213
|
-
} else if (isMemberElement(parentElement)) {
|
|
214
|
-
context = lineage.at(-2);
|
|
215
|
-
elementFactory = findElementFactory(context, toValue(parentElement.key));
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// no element factory found
|
|
219
|
-
if (typeof elementFactory !== 'function') return;
|
|
220
|
-
const replacement = elementFactory.call({
|
|
221
|
-
context
|
|
222
|
-
}, undefined, element.isMetaEmpty ? undefined : element.meta.cloneDeep(), element.isAttributesEmpty ? undefined : cloneDeep(element.attributes));
|
|
223
|
-
SourceMapElement.transfer(element, replacement);
|
|
224
|
-
StyleElement.transfer(element, replacement);
|
|
225
|
-
path.replaceWith(replacement);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
export default plugin;
|
|
@@ -1,15 +0,0 @@
|
|
|
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-6");
|
|
8
|
-
var _index = _interopRequireDefault(require("./visitors/json-schema/index.cjs"));
|
|
9
|
-
var _index2 = _interopRequireDefault(require("./visitors/json-schema/link-description/index.cjs"));
|
|
10
|
-
const specification = (0, _ramda.pipe)(
|
|
11
|
-
// JSON Schema object modifications
|
|
12
|
-
(0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'element'], 'jSONSchemaDraft7'), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', '$visitor'], _index.default), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', '$comment'], _apidomNsJsonSchemaDraft.specificationObj.visitors.value), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'if'], _apidomNsJsonSchemaDraft.specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'then'], _apidomNsJsonSchemaDraft.specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'else'], _apidomNsJsonSchemaDraft.specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor), (0, _ramda.dissocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'media']), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'contentEncoding'], _apidomNsJsonSchemaDraft.specificationObj.visitors.value), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'contentMediaType'], _apidomNsJsonSchemaDraft.specificationObj.visitors.value), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'writeOnly'], _apidomNsJsonSchemaDraft.specificationObj.visitors.value),
|
|
13
|
-
// Link Description object modifications
|
|
14
|
-
(0, _ramda.assocPath)(['visitors', 'document', 'objects', 'LinkDescription', '$visitor'], _index2.default), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'anchor'], _apidomNsJsonSchemaDraft.specificationObj.visitors.value), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'anchorPointer'], _apidomNsJsonSchemaDraft.specificationObj.visitors.value), (0, _ramda.dissocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'mediaType']), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'targetMediaType'], _apidomNsJsonSchemaDraft.specificationObj.visitors.value), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'targetHints'], _apidomNsJsonSchemaDraft.specificationObj.visitors.value), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'description'], _apidomNsJsonSchemaDraft.specificationObj.visitors.value), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', '$comment'], _apidomNsJsonSchemaDraft.specificationObj.visitors.value), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'headerSchema'], _apidomNsJsonSchemaDraft.specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor), (0, _ramda.dissocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'submissionEncType']), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'submissionMediaType'], _apidomNsJsonSchemaDraft.specificationObj.visitors.value))(_apidomNsJsonSchemaDraft.specificationObj);
|
|
15
|
-
var _default = exports.default = specification;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { pipe, assocPath, dissocPath } from 'ramda';
|
|
2
|
-
import { specificationObj } from '@speclynx/apidom-ns-json-schema-draft-6';
|
|
3
|
-
import JSONSchemaVisitor from "./visitors/json-schema/index.mjs";
|
|
4
|
-
import LinkDescriptionVisitor from "./visitors/json-schema/link-description/index.mjs";
|
|
5
|
-
const specification = pipe(
|
|
6
|
-
// JSON Schema object modifications
|
|
7
|
-
assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'element'], 'jSONSchemaDraft7'), assocPath(['visitors', 'document', 'objects', 'JSONSchema', '$visitor'], JSONSchemaVisitor), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', '$comment'], specificationObj.visitors.value), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'if'], specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'then'], specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'else'], specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor), dissocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'media']), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'contentEncoding'], specificationObj.visitors.value), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'contentMediaType'], specificationObj.visitors.value), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'writeOnly'], specificationObj.visitors.value),
|
|
8
|
-
// Link Description object modifications
|
|
9
|
-
assocPath(['visitors', 'document', 'objects', 'LinkDescription', '$visitor'], LinkDescriptionVisitor), assocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'anchor'], specificationObj.visitors.value), assocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'anchorPointer'], specificationObj.visitors.value), dissocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'mediaType']), assocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'targetMediaType'], specificationObj.visitors.value), assocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'targetHints'], specificationObj.visitors.value), assocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'description'], specificationObj.visitors.value), assocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', '$comment'], specificationObj.visitors.value), assocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'headerSchema'], specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor), dissocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'submissionEncType']), assocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'submissionMediaType'], specificationObj.visitors.value))(specificationObj);
|
|
10
|
-
export default specification;
|
|
@@ -1,26 +0,0 @@
|
|
|
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 _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
8
|
-
var jsonSchemaDraft7Predicates = _interopRequireWildcard(require("../predicates.cjs"));
|
|
9
|
-
var _namespace = _interopRequireDefault(require("../namespace.cjs"));
|
|
10
|
-
/**
|
|
11
|
-
* @public
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
const createToolbox = () => {
|
|
15
|
-
const namespace = new _apidomDatamodel.Namespace();
|
|
16
|
-
const predicates = {
|
|
17
|
-
...jsonSchemaDraft7Predicates,
|
|
18
|
-
isStringElement: _apidomDatamodel.isStringElement
|
|
19
|
-
};
|
|
20
|
-
namespace.use(_namespace.default);
|
|
21
|
-
return {
|
|
22
|
-
predicates,
|
|
23
|
-
namespace
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
var _default = exports.default = createToolbox;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { isStringElement, Namespace } from '@speclynx/apidom-datamodel';
|
|
2
|
-
import * as jsonSchemaDraft7Predicates from "../predicates.mjs";
|
|
3
|
-
import jsonSchemaDraft7Namespace from "../namespace.mjs";
|
|
4
|
-
/**
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
7
|
-
const createToolbox = () => {
|
|
8
|
-
const namespace = new Namespace();
|
|
9
|
-
const predicates = {
|
|
10
|
-
...jsonSchemaDraft7Predicates,
|
|
11
|
-
isStringElement
|
|
12
|
-
};
|
|
13
|
-
namespace.use(jsonSchemaDraft7Namespace);
|
|
14
|
-
return {
|
|
15
|
-
predicates,
|
|
16
|
-
namespace
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
export default createToolbox;
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
/**
|
|
9
|
-
* @public
|
|
10
|
-
*/
|
|
11
|
-
class JSONSchemaVisitor extends _apidomNsJsonSchemaDraft.JSONSchemaVisitor {
|
|
12
|
-
constructor(options) {
|
|
13
|
-
super(options);
|
|
14
|
-
this.element = new _JSONSchema.default();
|
|
15
|
-
}
|
|
16
|
-
get defaultDialectIdentifier() {
|
|
17
|
-
return 'http://json-schema.org/draft-07/schema#';
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
var _default = exports.default = JSONSchemaVisitor;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { JSONSchemaVisitor as JSONSchemaDraft6Visitor } from '@speclynx/apidom-ns-json-schema-draft-6';
|
|
2
|
-
import JSONSchemaElement from "../../../elements/JSONSchema.mjs";
|
|
3
|
-
/**
|
|
4
|
-
* @public
|
|
5
|
-
*/
|
|
6
|
-
class JSONSchemaVisitor extends JSONSchemaDraft6Visitor {
|
|
7
|
-
constructor(options) {
|
|
8
|
-
super(options);
|
|
9
|
-
this.element = new JSONSchemaElement();
|
|
10
|
-
}
|
|
11
|
-
get defaultDialectIdentifier() {
|
|
12
|
-
return 'http://json-schema.org/draft-07/schema#';
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export default JSONSchemaVisitor;
|
|
@@ -1,17 +0,0 @@
|
|
|
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 _LinkDescription = _interopRequireDefault(require("../../../../elements/LinkDescription.cjs"));
|
|
8
|
-
/**
|
|
9
|
-
* @public
|
|
10
|
-
*/
|
|
11
|
-
class LinkDescriptionVisitor extends _apidomNsJsonSchemaDraft.LinkDescriptionVisitor {
|
|
12
|
-
constructor(options) {
|
|
13
|
-
super(options);
|
|
14
|
-
this.element = new _LinkDescription.default();
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
var _default = exports.default = LinkDescriptionVisitor;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { LinkDescriptionVisitor as JSONSchemaDraft6LinkDescriptionVisitor } from '@speclynx/apidom-ns-json-schema-draft-6';
|
|
2
|
-
import LinkDescriptionElement from "../../../../elements/LinkDescription.mjs";
|
|
3
|
-
/**
|
|
4
|
-
* @public
|
|
5
|
-
*/
|
|
6
|
-
class LinkDescriptionVisitor extends JSONSchemaDraft6LinkDescriptionVisitor {
|
|
7
|
-
constructor(options) {
|
|
8
|
-
super(options);
|
|
9
|
-
this.element = new LinkDescriptionElement();
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export default LinkDescriptionVisitor;
|