@speclynx/apidom-ns-openapi-3-1 1.12.2 → 2.1.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 +25 -0
- package/NOTICE +16 -7
- package/README.md +16 -29
- package/dist/apidom-ns-openapi-3-1.browser.js +13422 -14424
- package/dist/apidom-ns-openapi-3-1.browser.min.js +1 -1
- package/package.json +11 -11
- package/src/elements/JsonSchemaDialect.cjs +2 -2
- package/src/elements/JsonSchemaDialect.mjs +1 -1
- package/src/elements/OpenApi3-1.cjs +2 -2
- package/src/elements/OpenApi3-1.mjs +1 -1
- package/src/elements/PathItem.cjs +24 -24
- package/src/elements/PathItem.mjs +24 -24
- package/src/elements/nces/ComponentsPathItems.cjs +2 -2
- package/src/elements/nces/ComponentsPathItems.mjs +1 -1
- package/src/elements/nces/Webhooks.cjs +2 -2
- package/src/elements/nces/Webhooks.mjs +1 -1
- package/src/index.cjs +73 -49
- package/src/index.mjs +6 -3
- package/src/namespace.cjs +0 -1
- package/src/predicates.cjs +56 -187
- package/src/predicates.mjs +29 -186
- package/src/refractor/index.cjs +338 -17
- package/src/refractor/index.mjs +305 -16
- package/src/refractor/inspect.cjs +207 -0
- package/src/refractor/inspect.mjs +171 -0
- package/src/refractor/plugins/normalize-header-examples/NormalizeStorage.cjs +5 -5
- package/src/refractor/plugins/normalize-header-examples/NormalizeStorage.mjs +1 -1
- package/src/refractor/plugins/normalize-header-examples/index.cjs +11 -7
- package/src/refractor/plugins/normalize-header-examples/index.mjs +8 -4
- package/src/refractor/plugins/normalize-operation-ids.cjs +13 -6
- package/src/refractor/plugins/normalize-operation-ids.mjs +13 -6
- package/src/refractor/plugins/normalize-parameter-examples.cjs +11 -7
- package/src/refractor/plugins/normalize-parameter-examples.mjs +8 -4
- package/src/refractor/plugins/normalize-parameters.cjs +11 -5
- package/src/refractor/plugins/normalize-parameters.mjs +11 -5
- package/src/refractor/plugins/normalize-security-requirements.cjs +8 -4
- package/src/refractor/plugins/normalize-security-requirements.mjs +8 -4
- package/src/refractor/plugins/normalize-servers.cjs +15 -9
- package/src/refractor/plugins/normalize-servers.mjs +15 -9
- package/src/refractor/plugins/replace-empty-element.cjs +32 -30
- package/src/refractor/plugins/replace-empty-element.mjs +16 -15
- package/src/refractor/predicates.cjs +36 -0
- package/src/refractor/predicates.mjs +31 -0
- package/src/refractor/specification.cjs +43 -4
- package/src/refractor/specification.mjs +43 -4
- package/src/refractor/toolbox.cjs +12 -21
- package/src/refractor/toolbox.mjs +9 -16
- package/src/refractor/visitors/open-api-3-1/JsonSchemaDialectVisitor.cjs +5 -5
- package/src/refractor/visitors/open-api-3-1/JsonSchemaDialectVisitor.mjs +6 -6
- package/src/refractor/visitors/open-api-3-1/OpenapiVisitor.cjs +25 -0
- package/src/refractor/visitors/open-api-3-1/OpenapiVisitor.mjs +19 -0
- package/src/refractor/visitors/open-api-3-1/WebhooksVisitor.cjs +4 -5
- package/src/refractor/visitors/open-api-3-1/WebhooksVisitor.mjs +5 -6
- package/src/refractor/visitors/open-api-3-1/bases.cjs +46 -0
- package/src/refractor/visitors/open-api-3-1/bases.mjs +43 -0
- package/src/refractor/visitors/open-api-3-1/callback/index.cjs +2 -3
- package/src/refractor/visitors/open-api-3-1/callback/index.mjs +2 -3
- package/src/refractor/visitors/open-api-3-1/components/PathItemsVisitor.cjs +4 -5
- package/src/refractor/visitors/open-api-3-1/components/PathItemsVisitor.mjs +5 -6
- package/src/refractor/visitors/open-api-3-1/components/SchemasVisitor.cjs +2 -2
- package/src/refractor/visitors/open-api-3-1/components/SchemasVisitor.mjs +3 -5
- package/src/refractor/visitors/open-api-3-1/index.cjs +5 -4
- package/src/refractor/visitors/open-api-3-1/index.mjs +6 -5
- package/src/refractor/visitors/open-api-3-1/schema/index.cjs +11 -10
- package/src/refractor/visitors/open-api-3-1/schema/index.mjs +12 -11
- package/types/apidom-ns-openapi-3-1.d.ts +435 -274
- package/src/refractor/registration.cjs +0 -102
- package/src/refractor/registration.mjs +0 -66
- package/src/traversal/visitor.cjs +0 -57
- package/src/traversal/visitor.mjs +0 -54
package/src/refractor/index.cjs
CHANGED
|
@@ -2,44 +2,365 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
4
|
exports.__esModule = true;
|
|
5
|
-
exports.
|
|
5
|
+
exports.refractXml = exports.refractTag = exports.refractServerVariable = exports.refractServer = exports.refractSecurityScheme = exports.refractSecurityRequirement = exports.refractSchema = exports.refractResponses = exports.refractResponse = exports.refractRequestBody = exports.refractReference = exports.refractPaths = exports.refractPathItem = exports.refractParameter = exports.refractOperation = exports.refractOpenApi3_1 = exports.refractOAuthFlows = exports.refractOAuthFlow = exports.refractMediaType = exports.refractLink = exports.refractLicense = exports.refractJsonSchemaDialect = exports.refractInfo = exports.refractHeader = exports.refractExternalDocumentation = exports.refractExample = exports.refractEncoding = exports.refractDiscriminator = exports.refractContact = exports.refractComponents = exports.refractCallback = exports.default = void 0;
|
|
6
6
|
var _apidomCore = require("@speclynx/apidom-core");
|
|
7
|
+
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
8
|
+
var _apidomTraverse = require("@speclynx/apidom-traverse");
|
|
7
9
|
var _ramda = require("ramda");
|
|
8
10
|
var _specification = _interopRequireDefault(require("./specification.cjs"));
|
|
9
|
-
var _visitor = require("../traversal/visitor.cjs");
|
|
10
11
|
var _toolbox = _interopRequireDefault(require("./toolbox.cjs"));
|
|
12
|
+
/**
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
11
23
|
const refract = (value, {
|
|
12
|
-
|
|
13
|
-
plugins = []
|
|
24
|
+
element = 'openApi3_1',
|
|
25
|
+
plugins = [],
|
|
26
|
+
specificationObj = _specification.default
|
|
14
27
|
} = {}) => {
|
|
15
|
-
const
|
|
16
|
-
const resolvedSpec = (0, _apidomCore.
|
|
28
|
+
const genericElement = (0, _apidomDatamodel.refract)(value);
|
|
29
|
+
const resolvedSpec = (0, _apidomCore.resolveSpecification)(specificationObj);
|
|
30
|
+
const elementMap = resolvedSpec.elementMap;
|
|
31
|
+
const specPath = elementMap[element];
|
|
32
|
+
if (!specPath) {
|
|
33
|
+
throw new Error(`Unknown element type: "${element}"`);
|
|
34
|
+
}
|
|
17
35
|
|
|
18
36
|
/**
|
|
19
37
|
* This is where generic ApiDOM becomes semantic (namespace applied).
|
|
20
38
|
* We don't allow consumers to hook into this translation.
|
|
21
|
-
* Though we allow consumers to define their
|
|
39
|
+
* Though we allow consumers to define their own plugins on already transformed ApiDOM.
|
|
22
40
|
*/
|
|
23
41
|
const RootVisitorClass = (0, _ramda.path)(specPath, resolvedSpec);
|
|
24
42
|
const rootVisitor = new RootVisitorClass({
|
|
25
43
|
specObj: resolvedSpec
|
|
26
44
|
});
|
|
27
|
-
(0,
|
|
45
|
+
(0, _apidomTraverse.traverse)(genericElement, rootVisitor, {
|
|
46
|
+
nodeTypeGetter: _apidomTraverse.getNodePrimitiveType
|
|
47
|
+
});
|
|
28
48
|
|
|
29
49
|
/**
|
|
30
50
|
* Running plugins visitors means extra single traversal === performance hit.
|
|
31
51
|
*/
|
|
32
52
|
return (0, _apidomCore.dispatchRefractorPlugins)(rootVisitor.element, plugins, {
|
|
33
|
-
toolboxCreator: _toolbox.default
|
|
34
|
-
visitorOptions: {
|
|
35
|
-
keyMap: _visitor.keyMap,
|
|
36
|
-
nodeTypeGetter: _visitor.getNodeType
|
|
37
|
-
}
|
|
53
|
+
toolboxCreator: _toolbox.default
|
|
38
54
|
});
|
|
39
55
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Refracts a value into an OpenApi3_1Element.
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
const refractOpenApi3_1 = (value, options = {}) => refract(value, {
|
|
62
|
+
...options,
|
|
63
|
+
element: 'openApi3_1'
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Refracts a value into an InfoElement.
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
exports.refractOpenApi3_1 = refractOpenApi3_1;
|
|
71
|
+
const refractInfo = (value, options = {}) => refract(value, {
|
|
72
|
+
...options,
|
|
73
|
+
element: 'info'
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Refracts a value into a ContactElement.
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
80
|
+
exports.refractInfo = refractInfo;
|
|
81
|
+
const refractContact = (value, options = {}) => refract(value, {
|
|
82
|
+
...options,
|
|
83
|
+
element: 'contact'
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Refracts a value into a LicenseElement.
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
exports.refractContact = refractContact;
|
|
91
|
+
const refractLicense = (value, options = {}) => refract(value, {
|
|
92
|
+
...options,
|
|
93
|
+
element: 'license'
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Refracts a value into a ServerElement.
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
exports.refractLicense = refractLicense;
|
|
101
|
+
const refractServer = (value, options = {}) => refract(value, {
|
|
102
|
+
...options,
|
|
103
|
+
element: 'server'
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Refracts a value into a ServerVariableElement.
|
|
108
|
+
* @public
|
|
109
|
+
*/
|
|
110
|
+
exports.refractServer = refractServer;
|
|
111
|
+
const refractServerVariable = (value, options = {}) => refract(value, {
|
|
112
|
+
...options,
|
|
113
|
+
element: 'serverVariable'
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Refracts a value into a ComponentsElement.
|
|
118
|
+
* @public
|
|
119
|
+
*/
|
|
120
|
+
exports.refractServerVariable = refractServerVariable;
|
|
121
|
+
const refractComponents = (value, options = {}) => refract(value, {
|
|
122
|
+
...options,
|
|
123
|
+
element: 'components'
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Refracts a value into a PathsElement.
|
|
128
|
+
* @public
|
|
129
|
+
*/
|
|
130
|
+
exports.refractComponents = refractComponents;
|
|
131
|
+
const refractPaths = (value, options = {}) => refract(value, {
|
|
132
|
+
...options,
|
|
133
|
+
element: 'paths'
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Refracts a value into a PathItemElement.
|
|
138
|
+
* @public
|
|
139
|
+
*/
|
|
140
|
+
exports.refractPaths = refractPaths;
|
|
141
|
+
const refractPathItem = (value, options = {}) => refract(value, {
|
|
142
|
+
...options,
|
|
143
|
+
element: 'pathItem'
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Refracts a value into an OperationElement.
|
|
148
|
+
* @public
|
|
149
|
+
*/
|
|
150
|
+
exports.refractPathItem = refractPathItem;
|
|
151
|
+
const refractOperation = (value, options = {}) => refract(value, {
|
|
152
|
+
...options,
|
|
153
|
+
element: 'operation'
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Refracts a value into an ExternalDocumentationElement.
|
|
158
|
+
* @public
|
|
159
|
+
*/
|
|
160
|
+
exports.refractOperation = refractOperation;
|
|
161
|
+
const refractExternalDocumentation = (value, options = {}) => refract(value, {
|
|
162
|
+
...options,
|
|
163
|
+
element: 'externalDocumentation'
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Refracts a value into a ParameterElement.
|
|
168
|
+
* @public
|
|
169
|
+
*/
|
|
170
|
+
exports.refractExternalDocumentation = refractExternalDocumentation;
|
|
171
|
+
const refractParameter = (value, options = {}) => refract(value, {
|
|
172
|
+
...options,
|
|
173
|
+
element: 'parameter'
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Refracts a value into a RequestBodyElement.
|
|
178
|
+
* @public
|
|
179
|
+
*/
|
|
180
|
+
exports.refractParameter = refractParameter;
|
|
181
|
+
const refractRequestBody = (value, options = {}) => refract(value, {
|
|
182
|
+
...options,
|
|
183
|
+
element: 'requestBody'
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Refracts a value into a MediaTypeElement.
|
|
188
|
+
* @public
|
|
189
|
+
*/
|
|
190
|
+
exports.refractRequestBody = refractRequestBody;
|
|
191
|
+
const refractMediaType = (value, options = {}) => refract(value, {
|
|
192
|
+
...options,
|
|
193
|
+
element: 'mediaType'
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Refracts a value into an EncodingElement.
|
|
198
|
+
* @public
|
|
199
|
+
*/
|
|
200
|
+
exports.refractMediaType = refractMediaType;
|
|
201
|
+
const refractEncoding = (value, options = {}) => refract(value, {
|
|
202
|
+
...options,
|
|
203
|
+
element: 'encoding'
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Refracts a value into a ResponsesElement.
|
|
208
|
+
* @public
|
|
209
|
+
*/
|
|
210
|
+
exports.refractEncoding = refractEncoding;
|
|
211
|
+
const refractResponses = (value, options = {}) => refract(value, {
|
|
212
|
+
...options,
|
|
213
|
+
element: 'responses'
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Refracts a value into a ResponseElement.
|
|
218
|
+
* @public
|
|
219
|
+
*/
|
|
220
|
+
exports.refractResponses = refractResponses;
|
|
221
|
+
const refractResponse = (value, options = {}) => refract(value, {
|
|
222
|
+
...options,
|
|
223
|
+
element: 'response'
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Refracts a value into a CallbackElement.
|
|
228
|
+
* @public
|
|
229
|
+
*/
|
|
230
|
+
exports.refractResponse = refractResponse;
|
|
231
|
+
const refractCallback = (value, options = {}) => refract(value, {
|
|
232
|
+
...options,
|
|
233
|
+
element: 'callback'
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Refracts a value into an ExampleElement.
|
|
238
|
+
* @public
|
|
239
|
+
*/
|
|
240
|
+
exports.refractCallback = refractCallback;
|
|
241
|
+
const refractExample = (value, options = {}) => refract(value, {
|
|
242
|
+
...options,
|
|
243
|
+
element: 'example'
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Refracts a value into a LinkElement.
|
|
248
|
+
* @public
|
|
249
|
+
*/
|
|
250
|
+
exports.refractExample = refractExample;
|
|
251
|
+
const refractLink = (value, options = {}) => refract(value, {
|
|
252
|
+
...options,
|
|
253
|
+
element: 'link'
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Refracts a value into a HeaderElement.
|
|
258
|
+
* @public
|
|
259
|
+
*/
|
|
260
|
+
exports.refractLink = refractLink;
|
|
261
|
+
const refractHeader = (value, options = {}) => refract(value, {
|
|
262
|
+
...options,
|
|
263
|
+
element: 'header'
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Refracts a value into a TagElement.
|
|
268
|
+
* @public
|
|
269
|
+
*/
|
|
270
|
+
exports.refractHeader = refractHeader;
|
|
271
|
+
const refractTag = (value, options = {}) => refract(value, {
|
|
272
|
+
...options,
|
|
273
|
+
element: 'tag'
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Refracts a value into a ReferenceElement.
|
|
278
|
+
* @public
|
|
279
|
+
*/
|
|
280
|
+
exports.refractTag = refractTag;
|
|
281
|
+
const refractReference = (value, options = {}) => refract(value, {
|
|
282
|
+
...options,
|
|
283
|
+
element: 'reference'
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Refracts a value into a SchemaElement.
|
|
288
|
+
* @public
|
|
289
|
+
*/
|
|
290
|
+
exports.refractReference = refractReference;
|
|
291
|
+
const refractSchema = (value, options = {}) => refract(value, {
|
|
292
|
+
...options,
|
|
293
|
+
element: 'schema'
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Refracts a value into a DiscriminatorElement.
|
|
298
|
+
* @public
|
|
299
|
+
*/
|
|
300
|
+
exports.refractSchema = refractSchema;
|
|
301
|
+
const refractDiscriminator = (value, options = {}) => refract(value, {
|
|
302
|
+
...options,
|
|
303
|
+
element: 'discriminator'
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Refracts a value into an XmlElement.
|
|
308
|
+
* @public
|
|
309
|
+
*/
|
|
310
|
+
exports.refractDiscriminator = refractDiscriminator;
|
|
311
|
+
const refractXml = (value, options = {}) => refract(value, {
|
|
312
|
+
...options,
|
|
313
|
+
element: 'xml'
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Refracts a value into a SecuritySchemeElement.
|
|
318
|
+
* @public
|
|
319
|
+
*/
|
|
320
|
+
exports.refractXml = refractXml;
|
|
321
|
+
const refractSecurityScheme = (value, options = {}) => refract(value, {
|
|
322
|
+
...options,
|
|
323
|
+
element: 'securityScheme'
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Refracts a value into an OAuthFlowsElement.
|
|
328
|
+
* @public
|
|
329
|
+
*/
|
|
330
|
+
exports.refractSecurityScheme = refractSecurityScheme;
|
|
331
|
+
const refractOAuthFlows = (value, options = {}) => refract(value, {
|
|
332
|
+
...options,
|
|
333
|
+
element: 'oAuthFlows'
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Refracts a value into an OAuthFlowElement.
|
|
338
|
+
* @public
|
|
339
|
+
*/
|
|
340
|
+
exports.refractOAuthFlows = refractOAuthFlows;
|
|
341
|
+
const refractOAuthFlow = (value, options = {}) => refract(value, {
|
|
342
|
+
...options,
|
|
343
|
+
element: 'oAuthFlow'
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Refracts a value into a SecurityRequirementElement.
|
|
348
|
+
* @public
|
|
349
|
+
*/
|
|
350
|
+
exports.refractOAuthFlow = refractOAuthFlow;
|
|
351
|
+
const refractSecurityRequirement = (value, options = {}) => refract(value, {
|
|
352
|
+
...options,
|
|
353
|
+
element: 'securityRequirement'
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Refracts a value into a JsonSchemaDialectElement.
|
|
358
|
+
* @public
|
|
359
|
+
*/
|
|
360
|
+
exports.refractSecurityRequirement = refractSecurityRequirement;
|
|
361
|
+
const refractJsonSchemaDialect = (value, options = {}) => refract(value, {
|
|
362
|
+
...options,
|
|
363
|
+
element: 'jsonSchemaDialect'
|
|
43
364
|
});
|
|
44
|
-
exports.
|
|
365
|
+
exports.refractJsonSchemaDialect = refractJsonSchemaDialect;
|
|
45
366
|
var _default = exports.default = refract;
|
package/src/refractor/index.mjs
CHANGED
|
@@ -1,39 +1,328 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolveSpecification, dispatchRefractorPlugins } from '@speclynx/apidom-core';
|
|
2
|
+
import { refract as baseRefract } from '@speclynx/apidom-datamodel';
|
|
3
|
+
import { traverse, getNodePrimitiveType } from '@speclynx/apidom-traverse';
|
|
2
4
|
import { path } from 'ramda';
|
|
3
5
|
import specification from "./specification.mjs";
|
|
4
|
-
import { keyMap, getNodeType } from "../traversal/visitor.mjs";
|
|
5
6
|
import createToolbox from "./toolbox.mjs";
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
6
16
|
const refract = (value, {
|
|
7
|
-
|
|
8
|
-
plugins = []
|
|
17
|
+
element = 'openApi3_1',
|
|
18
|
+
plugins = [],
|
|
19
|
+
specificationObj = specification
|
|
9
20
|
} = {}) => {
|
|
10
|
-
const
|
|
11
|
-
const resolvedSpec =
|
|
21
|
+
const genericElement = baseRefract(value);
|
|
22
|
+
const resolvedSpec = resolveSpecification(specificationObj);
|
|
23
|
+
const elementMap = resolvedSpec.elementMap;
|
|
24
|
+
const specPath = elementMap[element];
|
|
25
|
+
if (!specPath) {
|
|
26
|
+
throw new Error(`Unknown element type: "${element}"`);
|
|
27
|
+
}
|
|
12
28
|
|
|
13
29
|
/**
|
|
14
30
|
* This is where generic ApiDOM becomes semantic (namespace applied).
|
|
15
31
|
* We don't allow consumers to hook into this translation.
|
|
16
|
-
* Though we allow consumers to define their
|
|
32
|
+
* Though we allow consumers to define their own plugins on already transformed ApiDOM.
|
|
17
33
|
*/
|
|
18
34
|
const RootVisitorClass = path(specPath, resolvedSpec);
|
|
19
35
|
const rootVisitor = new RootVisitorClass({
|
|
20
36
|
specObj: resolvedSpec
|
|
21
37
|
});
|
|
22
|
-
|
|
38
|
+
traverse(genericElement, rootVisitor, {
|
|
39
|
+
nodeTypeGetter: getNodePrimitiveType
|
|
40
|
+
});
|
|
23
41
|
|
|
24
42
|
/**
|
|
25
43
|
* Running plugins visitors means extra single traversal === performance hit.
|
|
26
44
|
*/
|
|
27
45
|
return dispatchRefractorPlugins(rootVisitor.element, plugins, {
|
|
28
|
-
toolboxCreator: createToolbox
|
|
29
|
-
visitorOptions: {
|
|
30
|
-
keyMap,
|
|
31
|
-
nodeTypeGetter: getNodeType
|
|
32
|
-
}
|
|
46
|
+
toolboxCreator: createToolbox
|
|
33
47
|
});
|
|
34
48
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Refracts a value into an OpenApi3_1Element.
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
export const refractOpenApi3_1 = (value, options = {}) => refract(value, {
|
|
55
|
+
...options,
|
|
56
|
+
element: 'openApi3_1'
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Refracts a value into an InfoElement.
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
export const refractInfo = (value, options = {}) => refract(value, {
|
|
64
|
+
...options,
|
|
65
|
+
element: 'info'
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Refracts a value into a ContactElement.
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
export const refractContact = (value, options = {}) => refract(value, {
|
|
73
|
+
...options,
|
|
74
|
+
element: 'contact'
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Refracts a value into a LicenseElement.
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
export const refractLicense = (value, options = {}) => refract(value, {
|
|
82
|
+
...options,
|
|
83
|
+
element: 'license'
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Refracts a value into a ServerElement.
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
export const refractServer = (value, options = {}) => refract(value, {
|
|
91
|
+
...options,
|
|
92
|
+
element: 'server'
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Refracts a value into a ServerVariableElement.
|
|
97
|
+
* @public
|
|
98
|
+
*/
|
|
99
|
+
export const refractServerVariable = (value, options = {}) => refract(value, {
|
|
100
|
+
...options,
|
|
101
|
+
element: 'serverVariable'
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Refracts a value into a ComponentsElement.
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
108
|
+
export const refractComponents = (value, options = {}) => refract(value, {
|
|
109
|
+
...options,
|
|
110
|
+
element: 'components'
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Refracts a value into a PathsElement.
|
|
115
|
+
* @public
|
|
116
|
+
*/
|
|
117
|
+
export const refractPaths = (value, options = {}) => refract(value, {
|
|
118
|
+
...options,
|
|
119
|
+
element: 'paths'
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Refracts a value into a PathItemElement.
|
|
124
|
+
* @public
|
|
125
|
+
*/
|
|
126
|
+
export const refractPathItem = (value, options = {}) => refract(value, {
|
|
127
|
+
...options,
|
|
128
|
+
element: 'pathItem'
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Refracts a value into an OperationElement.
|
|
133
|
+
* @public
|
|
134
|
+
*/
|
|
135
|
+
export const refractOperation = (value, options = {}) => refract(value, {
|
|
136
|
+
...options,
|
|
137
|
+
element: 'operation'
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Refracts a value into an ExternalDocumentationElement.
|
|
142
|
+
* @public
|
|
143
|
+
*/
|
|
144
|
+
export const refractExternalDocumentation = (value, options = {}) => refract(value, {
|
|
145
|
+
...options,
|
|
146
|
+
element: 'externalDocumentation'
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Refracts a value into a ParameterElement.
|
|
151
|
+
* @public
|
|
152
|
+
*/
|
|
153
|
+
export const refractParameter = (value, options = {}) => refract(value, {
|
|
154
|
+
...options,
|
|
155
|
+
element: 'parameter'
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Refracts a value into a RequestBodyElement.
|
|
160
|
+
* @public
|
|
161
|
+
*/
|
|
162
|
+
export const refractRequestBody = (value, options = {}) => refract(value, {
|
|
163
|
+
...options,
|
|
164
|
+
element: 'requestBody'
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Refracts a value into a MediaTypeElement.
|
|
169
|
+
* @public
|
|
170
|
+
*/
|
|
171
|
+
export const refractMediaType = (value, options = {}) => refract(value, {
|
|
172
|
+
...options,
|
|
173
|
+
element: 'mediaType'
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Refracts a value into an EncodingElement.
|
|
178
|
+
* @public
|
|
179
|
+
*/
|
|
180
|
+
export const refractEncoding = (value, options = {}) => refract(value, {
|
|
181
|
+
...options,
|
|
182
|
+
element: 'encoding'
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Refracts a value into a ResponsesElement.
|
|
187
|
+
* @public
|
|
188
|
+
*/
|
|
189
|
+
export const refractResponses = (value, options = {}) => refract(value, {
|
|
190
|
+
...options,
|
|
191
|
+
element: 'responses'
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Refracts a value into a ResponseElement.
|
|
196
|
+
* @public
|
|
197
|
+
*/
|
|
198
|
+
export const refractResponse = (value, options = {}) => refract(value, {
|
|
199
|
+
...options,
|
|
200
|
+
element: 'response'
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Refracts a value into a CallbackElement.
|
|
205
|
+
* @public
|
|
206
|
+
*/
|
|
207
|
+
export const refractCallback = (value, options = {}) => refract(value, {
|
|
208
|
+
...options,
|
|
209
|
+
element: 'callback'
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Refracts a value into an ExampleElement.
|
|
214
|
+
* @public
|
|
215
|
+
*/
|
|
216
|
+
export const refractExample = (value, options = {}) => refract(value, {
|
|
217
|
+
...options,
|
|
218
|
+
element: 'example'
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Refracts a value into a LinkElement.
|
|
223
|
+
* @public
|
|
224
|
+
*/
|
|
225
|
+
export const refractLink = (value, options = {}) => refract(value, {
|
|
226
|
+
...options,
|
|
227
|
+
element: 'link'
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Refracts a value into a HeaderElement.
|
|
232
|
+
* @public
|
|
233
|
+
*/
|
|
234
|
+
export const refractHeader = (value, options = {}) => refract(value, {
|
|
235
|
+
...options,
|
|
236
|
+
element: 'header'
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Refracts a value into a TagElement.
|
|
241
|
+
* @public
|
|
242
|
+
*/
|
|
243
|
+
export const refractTag = (value, options = {}) => refract(value, {
|
|
244
|
+
...options,
|
|
245
|
+
element: 'tag'
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Refracts a value into a ReferenceElement.
|
|
250
|
+
* @public
|
|
251
|
+
*/
|
|
252
|
+
export const refractReference = (value, options = {}) => refract(value, {
|
|
253
|
+
...options,
|
|
254
|
+
element: 'reference'
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Refracts a value into a SchemaElement.
|
|
259
|
+
* @public
|
|
260
|
+
*/
|
|
261
|
+
export const refractSchema = (value, options = {}) => refract(value, {
|
|
262
|
+
...options,
|
|
263
|
+
element: 'schema'
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Refracts a value into a DiscriminatorElement.
|
|
268
|
+
* @public
|
|
269
|
+
*/
|
|
270
|
+
export const refractDiscriminator = (value, options = {}) => refract(value, {
|
|
271
|
+
...options,
|
|
272
|
+
element: 'discriminator'
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Refracts a value into an XmlElement.
|
|
277
|
+
* @public
|
|
278
|
+
*/
|
|
279
|
+
export const refractXml = (value, options = {}) => refract(value, {
|
|
280
|
+
...options,
|
|
281
|
+
element: 'xml'
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Refracts a value into a SecuritySchemeElement.
|
|
286
|
+
* @public
|
|
287
|
+
*/
|
|
288
|
+
export const refractSecurityScheme = (value, options = {}) => refract(value, {
|
|
289
|
+
...options,
|
|
290
|
+
element: 'securityScheme'
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Refracts a value into an OAuthFlowsElement.
|
|
295
|
+
* @public
|
|
296
|
+
*/
|
|
297
|
+
export const refractOAuthFlows = (value, options = {}) => refract(value, {
|
|
298
|
+
...options,
|
|
299
|
+
element: 'oAuthFlows'
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Refracts a value into an OAuthFlowElement.
|
|
304
|
+
* @public
|
|
305
|
+
*/
|
|
306
|
+
export const refractOAuthFlow = (value, options = {}) => refract(value, {
|
|
307
|
+
...options,
|
|
308
|
+
element: 'oAuthFlow'
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Refracts a value into a SecurityRequirementElement.
|
|
313
|
+
* @public
|
|
314
|
+
*/
|
|
315
|
+
export const refractSecurityRequirement = (value, options = {}) => refract(value, {
|
|
316
|
+
...options,
|
|
317
|
+
element: 'securityRequirement'
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Refracts a value into a JsonSchemaDialectElement.
|
|
322
|
+
* @public
|
|
323
|
+
*/
|
|
324
|
+
export const refractJsonSchemaDialect = (value, options = {}) => refract(value, {
|
|
325
|
+
...options,
|
|
326
|
+
element: 'jsonSchemaDialect'
|
|
38
327
|
});
|
|
39
328
|
export default refract;
|