@swagger-api/apidom-ns-json-schema-2020-12 1.0.0-beta.10
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 +18 -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 +83 -0
- package/README.md +186 -0
- package/dist/apidom-ns-json-schema-2020-12.browser.js +1 -0
- package/package.json +64 -0
- package/src/elements/JSONSchema.cjs +148 -0
- package/src/elements/JSONSchema.mjs +145 -0
- package/src/elements/LinkDescription.cjs +50 -0
- package/src/elements/LinkDescription.mjs +46 -0
- package/src/index.cjs +48 -0
- package/src/index.mjs +15 -0
- package/src/media-types.cjs +34 -0
- package/src/media-types.mjs +30 -0
- package/src/namespace.cjs +21 -0
- package/src/namespace.mjs +16 -0
- package/src/predicates.cjs +29 -0
- package/src/predicates.mjs +24 -0
- package/src/refractor/index.cjs +54 -0
- package/src/refractor/index.mjs +48 -0
- package/src/refractor/plugins/replace-empty-element.cjs +264 -0
- package/src/refractor/plugins/replace-empty-element.mjs +257 -0
- package/src/refractor/registration.cjs +13 -0
- package/src/refractor/registration.mjs +6 -0
- package/src/refractor/specification.cjs +16 -0
- package/src/refractor/specification.mjs +11 -0
- package/src/refractor/toolbox.cjs +21 -0
- package/src/refractor/toolbox.mjs +15 -0
- package/src/refractor/visitors/json-schema/PrefixItemsVisitor.cjs +30 -0
- package/src/refractor/visitors/json-schema/PrefixItemsVisitor.mjs +27 -0
- package/src/refractor/visitors/json-schema/index.cjs +22 -0
- package/src/refractor/visitors/json-schema/index.mjs +17 -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 +15 -0
- package/src/traversal/visitor.mjs +10 -0
- package/types/apidom-ns-json-schema-2020-12.d.ts +443 -0
|
@@ -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("@swagger-api/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 '@swagger-api/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,264 @@
|
|
|
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("@swagger-api/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 2020-12 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: https://json-schema.org/draft/2020-12/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
|
+
JSONSchema202012Element: {
|
|
51
|
+
prefixItems(...args) {
|
|
52
|
+
const element = new _apidomCore.ArrayElement(...args);
|
|
53
|
+
element.classes.push('json-schema-prefixItems');
|
|
54
|
+
return element;
|
|
55
|
+
},
|
|
56
|
+
items(...args) {
|
|
57
|
+
return new _JSONSchema.default(...args);
|
|
58
|
+
},
|
|
59
|
+
contains(...args) {
|
|
60
|
+
return new _JSONSchema.default(...args);
|
|
61
|
+
},
|
|
62
|
+
required(...args) {
|
|
63
|
+
const element = new _apidomCore.ArrayElement(...args);
|
|
64
|
+
element.classes.push('json-schema-required');
|
|
65
|
+
return element;
|
|
66
|
+
},
|
|
67
|
+
properties(...args) {
|
|
68
|
+
const element = new _apidomCore.ObjectElement(...args);
|
|
69
|
+
element.classes.push('json-schema-properties');
|
|
70
|
+
return element;
|
|
71
|
+
},
|
|
72
|
+
additionalProperties(...args) {
|
|
73
|
+
return new _JSONSchema.default(...args);
|
|
74
|
+
},
|
|
75
|
+
patternProperties(...args) {
|
|
76
|
+
const element = new _apidomCore.ObjectElement(...args);
|
|
77
|
+
element.classes.push('json-schema-patternProperties');
|
|
78
|
+
return element;
|
|
79
|
+
},
|
|
80
|
+
dependentSchemas(...args) {
|
|
81
|
+
const element = new _apidomCore.ObjectElement(...args);
|
|
82
|
+
element.classes.push('json-schema-dependentSchemas');
|
|
83
|
+
return element;
|
|
84
|
+
},
|
|
85
|
+
propertyNames(...args) {
|
|
86
|
+
return new _JSONSchema.default(...args);
|
|
87
|
+
},
|
|
88
|
+
enum(...args) {
|
|
89
|
+
const element = new _apidomCore.ArrayElement(...args);
|
|
90
|
+
element.classes.push('json-schema-enum');
|
|
91
|
+
return element;
|
|
92
|
+
},
|
|
93
|
+
allOf(...args) {
|
|
94
|
+
const element = new _apidomCore.ArrayElement(...args);
|
|
95
|
+
element.classes.push('json-schema-allOf');
|
|
96
|
+
return element;
|
|
97
|
+
},
|
|
98
|
+
anyOf(...args) {
|
|
99
|
+
const element = new _apidomCore.ArrayElement(...args);
|
|
100
|
+
element.classes.push('json-schema-anyOf');
|
|
101
|
+
return element;
|
|
102
|
+
},
|
|
103
|
+
oneOf(...args) {
|
|
104
|
+
const element = new _apidomCore.ArrayElement(...args);
|
|
105
|
+
element.classes.push('json-schema-oneOf');
|
|
106
|
+
return element;
|
|
107
|
+
},
|
|
108
|
+
if(...args) {
|
|
109
|
+
return new _JSONSchema.default(...args);
|
|
110
|
+
},
|
|
111
|
+
then(...args) {
|
|
112
|
+
return new _JSONSchema.default(...args);
|
|
113
|
+
},
|
|
114
|
+
else(...args) {
|
|
115
|
+
return new _JSONSchema.default(...args);
|
|
116
|
+
},
|
|
117
|
+
not(...args) {
|
|
118
|
+
return new _JSONSchema.default(...args);
|
|
119
|
+
},
|
|
120
|
+
$defs(...args) {
|
|
121
|
+
const element = new _apidomCore.ObjectElement(...args);
|
|
122
|
+
element.classes.push('json-schema-$defs');
|
|
123
|
+
return element;
|
|
124
|
+
},
|
|
125
|
+
examples(...args) {
|
|
126
|
+
const element = new _apidomCore.ArrayElement(...args);
|
|
127
|
+
element.classes.push('json-schema-examples');
|
|
128
|
+
return element;
|
|
129
|
+
},
|
|
130
|
+
links(...args) {
|
|
131
|
+
const element = new _apidomCore.ArrayElement(...args);
|
|
132
|
+
element.classes.push('json-schema-links');
|
|
133
|
+
return element;
|
|
134
|
+
},
|
|
135
|
+
$vocabulary(...args) {
|
|
136
|
+
const element = new _apidomCore.ObjectElement(...args);
|
|
137
|
+
element.classes.push('json-schema-$vocabulary');
|
|
138
|
+
return element;
|
|
139
|
+
},
|
|
140
|
+
unevaluatedItems(...args) {
|
|
141
|
+
return new _JSONSchema.default(...args);
|
|
142
|
+
},
|
|
143
|
+
unevaluatedProperties(...args) {
|
|
144
|
+
return new _JSONSchema.default(...args);
|
|
145
|
+
},
|
|
146
|
+
$dependentRequired(...args) {
|
|
147
|
+
const element = new _apidomCore.ObjectElement(...args);
|
|
148
|
+
element.classes.push('json-schema-$dependentRequired');
|
|
149
|
+
return element;
|
|
150
|
+
},
|
|
151
|
+
contentSchema(...args) {
|
|
152
|
+
return new _JSONSchema.default(...args);
|
|
153
|
+
},
|
|
154
|
+
type(...args) {
|
|
155
|
+
const element = new _apidomCore.ArrayElement(...args);
|
|
156
|
+
element.classes.push('json-schema-type');
|
|
157
|
+
return element;
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
LinkDescriptionElement: {
|
|
161
|
+
hrefSchema(...args) {
|
|
162
|
+
return new _JSONSchema.default(...args);
|
|
163
|
+
},
|
|
164
|
+
targetSchema(...args) {
|
|
165
|
+
return new _JSONSchema.default(...args);
|
|
166
|
+
},
|
|
167
|
+
submissionSchema(...args) {
|
|
168
|
+
return new _JSONSchema.default(...args);
|
|
169
|
+
},
|
|
170
|
+
templatePointers(...args) {
|
|
171
|
+
return new _apidomCore.ObjectElement(...args);
|
|
172
|
+
},
|
|
173
|
+
templateRequired(...args) {
|
|
174
|
+
return new _apidomCore.ArrayElement(...args);
|
|
175
|
+
},
|
|
176
|
+
targetHints(...args) {
|
|
177
|
+
return new _apidomCore.ObjectElement(...args);
|
|
178
|
+
},
|
|
179
|
+
headerSchema(...args) {
|
|
180
|
+
return new _JSONSchema.default(...args);
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
'json-schema-prefixItems': {
|
|
184
|
+
'<*>': function asterisk(...args) {
|
|
185
|
+
return new _JSONSchema.default(...args);
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
'json-schema-properties': {
|
|
189
|
+
'[key: *]': function key(...args) {
|
|
190
|
+
return new _JSONSchema.default(...args);
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
'json-schema-patternProperties': {
|
|
194
|
+
'[key: *]': function key(...args) {
|
|
195
|
+
return new _JSONSchema.default(...args);
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
'json-schema-dependentSchemas': {
|
|
199
|
+
'[key: *]': function key(...args) {
|
|
200
|
+
return new _JSONSchema.default(...args);
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
'json-schema-allOf': {
|
|
204
|
+
'<*>': function asterisk(...args) {
|
|
205
|
+
return new _JSONSchema.default(...args);
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
'json-schema-anyOf': {
|
|
209
|
+
'<*>': function asterisk(...args) {
|
|
210
|
+
return new _JSONSchema.default(...args);
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
'json-schema-oneOf': {
|
|
214
|
+
'<*>': function asterisk(...args) {
|
|
215
|
+
return new _JSONSchema.default(...args);
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
'json-schema-$defs': {
|
|
219
|
+
'[key: *]': function key(...args) {
|
|
220
|
+
return new _JSONSchema.default(...args);
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
'json-schema-links': {
|
|
224
|
+
'<*>': function asterisk(...args) {
|
|
225
|
+
return new _LinkDescription.default(...args);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
const findElementFactory = (ancestor, keyName) => {
|
|
230
|
+
const elementType = (0, _visitor.getNodeType)(ancestor); // @ts-ignore
|
|
231
|
+
const keyMapping = schema[elementType] || schema[(0, _apidomCore.toValue)(ancestor.classes.first)];
|
|
232
|
+
return typeof keyMapping === 'undefined' ? undefined : Object.prototype.hasOwnProperty.call(keyMapping, '[key: *]') ? keyMapping['[key: *]'] : keyMapping[keyName];
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* @public
|
|
237
|
+
*/
|
|
238
|
+
const plugin = () => () => {
|
|
239
|
+
return {
|
|
240
|
+
visitor: {
|
|
241
|
+
StringElement(element, key, parent, path, ancestors) {
|
|
242
|
+
if (!isEmptyElement(element)) return undefined;
|
|
243
|
+
const lineage = [...ancestors, parent].filter(_apidomCore.isElement);
|
|
244
|
+
const parentElement = lineage[lineage.length - 1]; // @TODO(vladimir.gorej@gmail.com): can be replaced by Array.prototype.at in future
|
|
245
|
+
let elementFactory;
|
|
246
|
+
let context;
|
|
247
|
+
if ((0, _apidomCore.isArrayElement)(parentElement)) {
|
|
248
|
+
context = element;
|
|
249
|
+
elementFactory = findElementFactory(parentElement, '<*>');
|
|
250
|
+
} else if ((0, _apidomCore.isMemberElement)(parentElement)) {
|
|
251
|
+
context = lineage[lineage.length - 2]; // @TODO(vladimir.gorej@gmail.com): can be replaced by Array.prototype.at in future
|
|
252
|
+
elementFactory = findElementFactory(context, (0, _apidomCore.toValue)(parentElement.key));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// no element factory found
|
|
256
|
+
if (typeof elementFactory !== 'function') return undefined;
|
|
257
|
+
return elementFactory.call({
|
|
258
|
+
context
|
|
259
|
+
}, undefined, (0, _apidomCore.cloneDeep)(element.meta), (0, _apidomCore.cloneDeep)(element.attributes));
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
};
|
|
264
|
+
var _default = exports.default = plugin;
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { ArrayElement, ObjectElement, isStringElement, isArrayElement, isElement, isMemberElement, includesClasses, cloneDeep, toValue } from '@swagger-api/apidom-core';
|
|
2
|
+
/**
|
|
3
|
+
* JSON Schema 2020-12 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: https://json-schema.org/draft/2020-12/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
|
+
JSONSchema202012Element: {
|
|
44
|
+
prefixItems(...args) {
|
|
45
|
+
const element = new ArrayElement(...args);
|
|
46
|
+
element.classes.push('json-schema-prefixItems');
|
|
47
|
+
return element;
|
|
48
|
+
},
|
|
49
|
+
items(...args) {
|
|
50
|
+
return new JSONSchemaElement(...args);
|
|
51
|
+
},
|
|
52
|
+
contains(...args) {
|
|
53
|
+
return new JSONSchemaElement(...args);
|
|
54
|
+
},
|
|
55
|
+
required(...args) {
|
|
56
|
+
const element = new ArrayElement(...args);
|
|
57
|
+
element.classes.push('json-schema-required');
|
|
58
|
+
return element;
|
|
59
|
+
},
|
|
60
|
+
properties(...args) {
|
|
61
|
+
const element = new ObjectElement(...args);
|
|
62
|
+
element.classes.push('json-schema-properties');
|
|
63
|
+
return element;
|
|
64
|
+
},
|
|
65
|
+
additionalProperties(...args) {
|
|
66
|
+
return new JSONSchemaElement(...args);
|
|
67
|
+
},
|
|
68
|
+
patternProperties(...args) {
|
|
69
|
+
const element = new ObjectElement(...args);
|
|
70
|
+
element.classes.push('json-schema-patternProperties');
|
|
71
|
+
return element;
|
|
72
|
+
},
|
|
73
|
+
dependentSchemas(...args) {
|
|
74
|
+
const element = new ObjectElement(...args);
|
|
75
|
+
element.classes.push('json-schema-dependentSchemas');
|
|
76
|
+
return element;
|
|
77
|
+
},
|
|
78
|
+
propertyNames(...args) {
|
|
79
|
+
return new JSONSchemaElement(...args);
|
|
80
|
+
},
|
|
81
|
+
enum(...args) {
|
|
82
|
+
const element = new ArrayElement(...args);
|
|
83
|
+
element.classes.push('json-schema-enum');
|
|
84
|
+
return element;
|
|
85
|
+
},
|
|
86
|
+
allOf(...args) {
|
|
87
|
+
const element = new ArrayElement(...args);
|
|
88
|
+
element.classes.push('json-schema-allOf');
|
|
89
|
+
return element;
|
|
90
|
+
},
|
|
91
|
+
anyOf(...args) {
|
|
92
|
+
const element = new ArrayElement(...args);
|
|
93
|
+
element.classes.push('json-schema-anyOf');
|
|
94
|
+
return element;
|
|
95
|
+
},
|
|
96
|
+
oneOf(...args) {
|
|
97
|
+
const element = new ArrayElement(...args);
|
|
98
|
+
element.classes.push('json-schema-oneOf');
|
|
99
|
+
return element;
|
|
100
|
+
},
|
|
101
|
+
if(...args) {
|
|
102
|
+
return new JSONSchemaElement(...args);
|
|
103
|
+
},
|
|
104
|
+
then(...args) {
|
|
105
|
+
return new JSONSchemaElement(...args);
|
|
106
|
+
},
|
|
107
|
+
else(...args) {
|
|
108
|
+
return new JSONSchemaElement(...args);
|
|
109
|
+
},
|
|
110
|
+
not(...args) {
|
|
111
|
+
return new JSONSchemaElement(...args);
|
|
112
|
+
},
|
|
113
|
+
$defs(...args) {
|
|
114
|
+
const element = new ObjectElement(...args);
|
|
115
|
+
element.classes.push('json-schema-$defs');
|
|
116
|
+
return element;
|
|
117
|
+
},
|
|
118
|
+
examples(...args) {
|
|
119
|
+
const element = new ArrayElement(...args);
|
|
120
|
+
element.classes.push('json-schema-examples');
|
|
121
|
+
return element;
|
|
122
|
+
},
|
|
123
|
+
links(...args) {
|
|
124
|
+
const element = new ArrayElement(...args);
|
|
125
|
+
element.classes.push('json-schema-links');
|
|
126
|
+
return element;
|
|
127
|
+
},
|
|
128
|
+
$vocabulary(...args) {
|
|
129
|
+
const element = new ObjectElement(...args);
|
|
130
|
+
element.classes.push('json-schema-$vocabulary');
|
|
131
|
+
return element;
|
|
132
|
+
},
|
|
133
|
+
unevaluatedItems(...args) {
|
|
134
|
+
return new JSONSchemaElement(...args);
|
|
135
|
+
},
|
|
136
|
+
unevaluatedProperties(...args) {
|
|
137
|
+
return new JSONSchemaElement(...args);
|
|
138
|
+
},
|
|
139
|
+
$dependentRequired(...args) {
|
|
140
|
+
const element = new ObjectElement(...args);
|
|
141
|
+
element.classes.push('json-schema-$dependentRequired');
|
|
142
|
+
return element;
|
|
143
|
+
},
|
|
144
|
+
contentSchema(...args) {
|
|
145
|
+
return new JSONSchemaElement(...args);
|
|
146
|
+
},
|
|
147
|
+
type(...args) {
|
|
148
|
+
const element = new ArrayElement(...args);
|
|
149
|
+
element.classes.push('json-schema-type');
|
|
150
|
+
return element;
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
LinkDescriptionElement: {
|
|
154
|
+
hrefSchema(...args) {
|
|
155
|
+
return new JSONSchemaElement(...args);
|
|
156
|
+
},
|
|
157
|
+
targetSchema(...args) {
|
|
158
|
+
return new JSONSchemaElement(...args);
|
|
159
|
+
},
|
|
160
|
+
submissionSchema(...args) {
|
|
161
|
+
return new JSONSchemaElement(...args);
|
|
162
|
+
},
|
|
163
|
+
templatePointers(...args) {
|
|
164
|
+
return new ObjectElement(...args);
|
|
165
|
+
},
|
|
166
|
+
templateRequired(...args) {
|
|
167
|
+
return new ArrayElement(...args);
|
|
168
|
+
},
|
|
169
|
+
targetHints(...args) {
|
|
170
|
+
return new ObjectElement(...args);
|
|
171
|
+
},
|
|
172
|
+
headerSchema(...args) {
|
|
173
|
+
return new JSONSchemaElement(...args);
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
'json-schema-prefixItems': {
|
|
177
|
+
'<*>': function asterisk(...args) {
|
|
178
|
+
return new JSONSchemaElement(...args);
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
'json-schema-properties': {
|
|
182
|
+
'[key: *]': function key(...args) {
|
|
183
|
+
return new JSONSchemaElement(...args);
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
'json-schema-patternProperties': {
|
|
187
|
+
'[key: *]': function key(...args) {
|
|
188
|
+
return new JSONSchemaElement(...args);
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
'json-schema-dependentSchemas': {
|
|
192
|
+
'[key: *]': function key(...args) {
|
|
193
|
+
return new JSONSchemaElement(...args);
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
'json-schema-allOf': {
|
|
197
|
+
'<*>': function asterisk(...args) {
|
|
198
|
+
return new JSONSchemaElement(...args);
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
'json-schema-anyOf': {
|
|
202
|
+
'<*>': function asterisk(...args) {
|
|
203
|
+
return new JSONSchemaElement(...args);
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
'json-schema-oneOf': {
|
|
207
|
+
'<*>': function asterisk(...args) {
|
|
208
|
+
return new JSONSchemaElement(...args);
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
'json-schema-$defs': {
|
|
212
|
+
'[key: *]': function key(...args) {
|
|
213
|
+
return new JSONSchemaElement(...args);
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
'json-schema-links': {
|
|
217
|
+
'<*>': function asterisk(...args) {
|
|
218
|
+
return new LinkDescriptionElement(...args);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
const findElementFactory = (ancestor, keyName) => {
|
|
223
|
+
const elementType = getNodeType(ancestor); // @ts-ignore
|
|
224
|
+
const keyMapping = schema[elementType] || schema[toValue(ancestor.classes.first)];
|
|
225
|
+
return typeof keyMapping === 'undefined' ? undefined : Object.prototype.hasOwnProperty.call(keyMapping, '[key: *]') ? keyMapping['[key: *]'] : keyMapping[keyName];
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* @public
|
|
230
|
+
*/
|
|
231
|
+
const plugin = () => () => {
|
|
232
|
+
return {
|
|
233
|
+
visitor: {
|
|
234
|
+
StringElement(element, key, parent, path, ancestors) {
|
|
235
|
+
if (!isEmptyElement(element)) return undefined;
|
|
236
|
+
const lineage = [...ancestors, parent].filter(isElement);
|
|
237
|
+
const parentElement = lineage[lineage.length - 1]; // @TODO(vladimir.gorej@gmail.com): can be replaced by Array.prototype.at in future
|
|
238
|
+
let elementFactory;
|
|
239
|
+
let context;
|
|
240
|
+
if (isArrayElement(parentElement)) {
|
|
241
|
+
context = element;
|
|
242
|
+
elementFactory = findElementFactory(parentElement, '<*>');
|
|
243
|
+
} else if (isMemberElement(parentElement)) {
|
|
244
|
+
context = lineage[lineage.length - 2]; // @TODO(vladimir.gorej@gmail.com): can be replaced by Array.prototype.at in future
|
|
245
|
+
elementFactory = findElementFactory(context, toValue(parentElement.key));
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// no element factory found
|
|
249
|
+
if (typeof elementFactory !== 'function') return undefined;
|
|
250
|
+
return elementFactory.call({
|
|
251
|
+
context
|
|
252
|
+
}, undefined, cloneDeep(element.meta), cloneDeep(element.attributes));
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
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,16 @@
|
|
|
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 _apidomNsJsonSchema = require("@swagger-api/apidom-ns-json-schema-2019-09");
|
|
8
|
+
var _index = _interopRequireDefault(require("./visitors/json-schema/index.cjs"));
|
|
9
|
+
var _PrefixItemsVisitor = _interopRequireDefault(require("./visitors/json-schema/PrefixItemsVisitor.cjs"));
|
|
10
|
+
var _index2 = _interopRequireDefault(require("./visitors/json-schema/link-description/index.cjs"));
|
|
11
|
+
const specification = (0, _ramda.pipe)(
|
|
12
|
+
// JSON Schema object modifications
|
|
13
|
+
(0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', '$visitor'], _index.default), (0, _ramda.dissocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', '$recursiveAnchor']), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', '$dynamicAnchor'], _apidomNsJsonSchema.specificationObj.visitors.value), (0, _ramda.dissocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', '$recursiveRef']), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', '$dynamicRef'], _apidomNsJsonSchema.specificationObj.visitors.value), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'not'], _index.default), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'if'], _index.default), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'then'], _index.default), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'else'], _index.default), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'prefixItems'], _PrefixItemsVisitor.default), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'items'], _index.default), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'contains'], _index.default), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'additionalProperties'], _index.default), (0, _ramda.dissocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'additionalItems']), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'propertyNames'], _index.default), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'unevaluatedItems'], _index.default), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'unevaluatedProperties'], _index.default), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'contentSchema'], _index.default),
|
|
14
|
+
// Link Description object modifications
|
|
15
|
+
(0, _ramda.assocPath)(['visitors', 'document', 'objects', 'LinkDescription', '$visitor'], _index2.default), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'targetSchema'], _index.default), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'hrefSchema'], _index.default), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'headerSchema'], _index.default), (0, _ramda.assocPath)(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'submissionSchema'], _index.default))(_apidomNsJsonSchema.specificationObj);
|
|
16
|
+
var _default = exports.default = specification;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { pipe, assocPath, dissocPath } from 'ramda';
|
|
2
|
+
import { specificationObj } from '@swagger-api/apidom-ns-json-schema-2019-09';
|
|
3
|
+
import JSONSchemaVisitor from "./visitors/json-schema/index.mjs";
|
|
4
|
+
import JSONSchemaPrefixItemsVisitor from "./visitors/json-schema/PrefixItemsVisitor.mjs";
|
|
5
|
+
import JSONSchemaLinkDescriptionVisitor from "./visitors/json-schema/link-description/index.mjs";
|
|
6
|
+
const specification = pipe(
|
|
7
|
+
// JSON Schema object modifications
|
|
8
|
+
assocPath(['visitors', 'document', 'objects', 'JSONSchema', '$visitor'], JSONSchemaVisitor), dissocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', '$recursiveAnchor']), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', '$dynamicAnchor'], specificationObj.visitors.value), dissocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', '$recursiveRef']), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', '$dynamicRef'], specificationObj.visitors.value), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'not'], JSONSchemaVisitor), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'if'], JSONSchemaVisitor), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'then'], JSONSchemaVisitor), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'else'], JSONSchemaVisitor), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'prefixItems'], JSONSchemaPrefixItemsVisitor), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'items'], JSONSchemaVisitor), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'contains'], JSONSchemaVisitor), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'additionalProperties'], JSONSchemaVisitor), dissocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'additionalItems']), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'propertyNames'], JSONSchemaVisitor), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'unevaluatedItems'], JSONSchemaVisitor), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'unevaluatedProperties'], JSONSchemaVisitor), assocPath(['visitors', 'document', 'objects', 'JSONSchema', 'fixedFields', 'contentSchema'], JSONSchemaVisitor),
|
|
9
|
+
// Link Description object modifications
|
|
10
|
+
assocPath(['visitors', 'document', 'objects', 'LinkDescription', '$visitor'], JSONSchemaLinkDescriptionVisitor), assocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'targetSchema'], JSONSchemaVisitor), assocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'hrefSchema'], JSONSchemaVisitor), assocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'headerSchema'], JSONSchemaVisitor), assocPath(['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'submissionSchema'], JSONSchemaVisitor))(specificationObj);
|
|
11
|
+
export default specification;
|