@speclynx/apidom-ns-openapi-2 2.13.1 → 3.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 +21 -0
- package/dist/apidom-ns-openapi-2.browser.js +637 -303
- package/dist/apidom-ns-openapi-2.browser.min.js +1 -1
- package/package.json +7 -7
- package/src/index.cjs +3 -2
- package/src/index.mjs +1 -1
- package/src/refractor/index.cjs +4 -2
- package/src/refractor/index.mjs +4 -2
- package/src/refractor/plugins/replace-empty-element.cjs +4 -3
- package/src/refractor/plugins/replace-empty-element.mjs +4 -3
- package/src/refractor/visitors/FallbackVisitor.cjs +1 -1
- package/src/refractor/visitors/FallbackVisitor.mjs +1 -1
- package/src/refractor/visitors/SpecificationVisitor.cjs +2 -2
- package/src/refractor/visitors/SpecificationVisitor.mjs +2 -2
- package/src/refractor/visitors/Visitor.cjs +10 -8
- package/src/refractor/visitors/Visitor.mjs +11 -9
- package/src/refractor/visitors/generics/FixedFieldsVisitor.cjs +6 -3
- package/src/refractor/visitors/generics/FixedFieldsVisitor.mjs +6 -3
- package/src/refractor/visitors/generics/PatternedFieldsVisitor.cjs +4 -2
- package/src/refractor/visitors/generics/PatternedFieldsVisitor.mjs +4 -2
- package/src/refractor/visitors/open-api-2/index.cjs +1 -0
- package/src/refractor/visitors/open-api-2/index.mjs +1 -0
- package/src/refractor/visitors/open-api-2/path-item/index.cjs +1 -0
- package/src/refractor/visitors/open-api-2/path-item/index.mjs +1 -0
- package/src/refractor/visitors/open-api-2/paths/index.cjs +1 -0
- package/src/refractor/visitors/open-api-2/paths/index.mjs +1 -0
- package/types/apidom-ns-openapi-2.d.ts +9 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@speclynx/apidom-ns-openapi-2",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "OpenAPI 2.0 namespace for ApiDOM.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
"license": "Apache-2.0",
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@babel/runtime-corejs3": "^7.28.4",
|
|
46
|
-
"@speclynx/apidom-core": "
|
|
47
|
-
"@speclynx/apidom-datamodel": "
|
|
48
|
-
"@speclynx/apidom-error": "
|
|
49
|
-
"@speclynx/apidom-ns-json-schema-draft-4": "
|
|
50
|
-
"@speclynx/apidom-traverse": "
|
|
46
|
+
"@speclynx/apidom-core": "3.1.0",
|
|
47
|
+
"@speclynx/apidom-datamodel": "3.1.0",
|
|
48
|
+
"@speclynx/apidom-error": "3.1.0",
|
|
49
|
+
"@speclynx/apidom-ns-json-schema-draft-4": "3.1.0",
|
|
50
|
+
"@speclynx/apidom-traverse": "3.1.0",
|
|
51
51
|
"ramda": "~0.32.0",
|
|
52
52
|
"ramda-adjunct": "^6.0.0",
|
|
53
53
|
"ts-mixer": "^6.0.4"
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"README.md",
|
|
63
63
|
"CHANGELOG.md"
|
|
64
64
|
],
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "c0807dd0b7770eaaf594bd0013be65e2c28c504a"
|
|
66
66
|
}
|
package/src/index.cjs
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
4
|
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
|
|
5
5
|
exports.__esModule = true;
|
|
6
|
-
exports.
|
|
7
|
-
exports.specificationObj = exports.refractorPluginReplaceEmptyElement = exports.refractXml = exports.refractTag = exports.refractSwagger = exports.refractSecurityScheme = exports.refractSecurityRequirement = exports.refractSecurityDefinitions = exports.refractScopes = exports.refractSchema = exports.refractResponsesDefinitions = exports.refractResponses = exports.refractResponse = exports.refractReference = exports.refractPaths = exports.refractPathItem = exports.refractParametersDefinitions = exports.refractParameter = void 0;
|
|
6
|
+
exports.refractLicense = exports.refractJSONReference = exports.refractItems = exports.refractInfo = exports.refractHeaders = exports.refractHeader = exports.refractExternalDocumentation = exports.refractExample = exports.refractDefinitions = exports.refractContact = exports.refract = exports.mediaTypes = exports.isXmlElement = exports.isTagElement = exports.isSwaggerVersionElement = exports.isSwaggerExtension = exports.isSwaggerElement = exports.isSecuritySchemeElement = exports.isSecurityRequirementElement = exports.isSecurityDefinitionsElement = exports.isScopesElement = exports.isSchemaElement = exports.isResponsesElement = exports.isResponsesDefinitionsElement = exports.isResponseElement = exports.isReferenceLikeElement = exports.isReferenceElement = exports.isPathsElement = exports.isPathItemElement = exports.isParametersDefinitionsElement = exports.isParameterElement = exports.isOperationElement = exports.isLicenseElement = exports.isJSONReferenceLikeElement = exports.isJSONReferenceElement = exports.isItemsElement = exports.isInfoElement = exports.isHeadersElement = exports.isHeaderElement = exports.isExternalDocumentationElement = exports.isExampleElement = exports.isDefinitionsElement = exports.isContactElement = exports.default = exports.XmlElement = exports.Visitor = exports.TagElement = exports.SwaggerVersionElement = exports.SwaggerTagsElement = exports.SwaggerSecurityElement = exports.SwaggerSchemesElement = exports.SwaggerProducesElement = exports.SwaggerElement = exports.SwaggerConsumesElement = exports.SpecificationVisitor = exports.SecuritySchemeElement = exports.SecurityRequirementElement = exports.SecurityDefinitionsElement = exports.ScopesElement = exports.SchemaElement = exports.ResponsesElement = exports.ResponsesDefinitionsElement = exports.ResponseElement = exports.ReferenceElement = exports.PatternedFieldsVisitor = exports.PathsElement = exports.PathItemParametersElement = exports.PathItemElement = exports.ParametersDefinitionsElement = exports.ParameterElement = exports.OperationTagsElement = exports.OperationSecurityElement = exports.OperationSchemesElement = exports.OperationProducesElement = exports.OperationParametersElement = exports.OperationElement = exports.OperationConsumesElement = exports.OpenAPIMediaTypes = exports.MixedFieldsVisitorBase = exports.MixedFieldsVisitor = exports.MapVisitor = exports.LicenseElement = exports.JSONReferenceElement = exports.ItemsElement = exports.InfoElement = exports.HeadersElement = exports.HeaderElement = exports.FixedFieldsVisitor = exports.FallbackVisitor = exports.ExternalDocumentationElement = exports.ExampleElement = exports.DefinitionsElement = exports.ContactElement = exports.BaseSpecificationVisitor = exports.BasePatternedFieldsVisitor = exports.BaseMixedFieldsVisitor = exports.BaseMapVisitor = exports.BaseFixedFieldsVisitor = exports.BaseAlternatingVisitor = exports.AlternatingVisitor = void 0;
|
|
7
|
+
exports.specificationObj = exports.refractorPluginReplaceEmptyElement = exports.refractXml = exports.refractTag = exports.refractSwagger = exports.refractSecurityScheme = exports.refractSecurityRequirement = exports.refractSecurityDefinitions = exports.refractScopes = exports.refractSchema = exports.refractResponsesDefinitions = exports.refractResponses = exports.refractResponse = exports.refractReference = exports.refractPaths = exports.refractPathItem = exports.refractParametersDefinitions = exports.refractParameter = exports.refractOperation = void 0;
|
|
8
8
|
var _apidomNsJsonSchemaDraft = require("@speclynx/apidom-ns-json-schema-draft-4");
|
|
9
9
|
exports.isJSONReferenceElement = _apidomNsJsonSchemaDraft.isJSONReferenceElement;
|
|
10
10
|
exports.isJSONReferenceLikeElement = _apidomNsJsonSchemaDraft.isJSONReferenceLikeElement;
|
|
11
11
|
exports.JSONReferenceElement = _apidomNsJsonSchemaDraft.JSONReferenceElement;
|
|
12
|
+
exports.refractJSONReference = _apidomNsJsonSchemaDraft.refractJSONReference;
|
|
12
13
|
var _mediaTypes = _interopRequireWildcard(require("./media-types.cjs"));
|
|
13
14
|
exports.mediaTypes = _mediaTypes.default;
|
|
14
15
|
exports.OpenAPIMediaTypes = _mediaTypes.OpenAPIMediaTypes;
|
package/src/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { isJSONReferenceElement, isJSONReferenceLikeElement, JSONReferenceElement } from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
1
|
+
export { isJSONReferenceElement, isJSONReferenceLikeElement, JSONReferenceElement, refractJSONReference } from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
2
2
|
export { default as mediaTypes, OpenAPIMediaTypes } from "./media-types.mjs";
|
|
3
3
|
export { default } from "./namespace.mjs";
|
|
4
4
|
export { default as refractorPluginReplaceEmptyElement } from "./refractor/plugins/replace-empty-element.mjs";
|
package/src/refractor/index.cjs
CHANGED
|
@@ -23,7 +23,8 @@ var _toolbox = _interopRequireDefault(require("./toolbox.cjs"));
|
|
|
23
23
|
const refract = (value, {
|
|
24
24
|
element = 'swagger',
|
|
25
25
|
plugins = [],
|
|
26
|
-
specificationObj = _specification.default
|
|
26
|
+
specificationObj = _specification.default,
|
|
27
|
+
consume = false
|
|
27
28
|
} = {}) => {
|
|
28
29
|
const genericElement = (0, _apidomDatamodel.refract)(value);
|
|
29
30
|
const resolvedSpec = (0, _apidomCore.resolveSpecification)(specificationObj);
|
|
@@ -40,7 +41,8 @@ const refract = (value, {
|
|
|
40
41
|
*/
|
|
41
42
|
const RootVisitorClass = (0, _ramda.path)(specPath, resolvedSpec);
|
|
42
43
|
const rootVisitor = new RootVisitorClass({
|
|
43
|
-
specObj: resolvedSpec
|
|
44
|
+
specObj: resolvedSpec,
|
|
45
|
+
consume
|
|
44
46
|
});
|
|
45
47
|
(0, _apidomTraverse.traverse)(genericElement, rootVisitor);
|
|
46
48
|
|
package/src/refractor/index.mjs
CHANGED
|
@@ -16,7 +16,8 @@ import createToolbox from "./toolbox.mjs";
|
|
|
16
16
|
const refract = (value, {
|
|
17
17
|
element = 'swagger',
|
|
18
18
|
plugins = [],
|
|
19
|
-
specificationObj = specification
|
|
19
|
+
specificationObj = specification,
|
|
20
|
+
consume = false
|
|
20
21
|
} = {}) => {
|
|
21
22
|
const genericElement = baseRefract(value);
|
|
22
23
|
const resolvedSpec = resolveSpecification(specificationObj);
|
|
@@ -33,7 +34,8 @@ const refract = (value, {
|
|
|
33
34
|
*/
|
|
34
35
|
const RootVisitorClass = path(specPath, resolvedSpec);
|
|
35
36
|
const rootVisitor = new RootVisitorClass({
|
|
36
|
-
specObj: resolvedSpec
|
|
37
|
+
specObj: resolvedSpec,
|
|
38
|
+
consume
|
|
37
39
|
});
|
|
38
40
|
traverse(genericElement, rootVisitor);
|
|
39
41
|
|
|
@@ -324,8 +324,9 @@ const schema = {
|
|
|
324
324
|
}
|
|
325
325
|
};
|
|
326
326
|
const findElementFactory = (ancestor, keyName) => {
|
|
327
|
-
const elementType = (0, _apidomTraverse.getNodeType)(ancestor);
|
|
328
|
-
const
|
|
327
|
+
const elementType = (0, _apidomTraverse.getNodeType)(ancestor);
|
|
328
|
+
const classType = ancestor.isMetaEmpty ? undefined : ancestor.classes.at(0); // @ts-ignore
|
|
329
|
+
const keyMapping = schema[elementType] || schema[classType];
|
|
329
330
|
return typeof keyMapping === 'undefined' ? undefined : Object.hasOwn(keyMapping, '[key: *]') ? keyMapping['[key: *]'] : keyMapping[keyName];
|
|
330
331
|
};
|
|
331
332
|
|
|
@@ -355,7 +356,7 @@ const plugin = () => () => ({
|
|
|
355
356
|
if (typeof elementFactory !== 'function') return;
|
|
356
357
|
const replacement = elementFactory.call({
|
|
357
358
|
context
|
|
358
|
-
}, undefined,
|
|
359
|
+
}, undefined, element.isMetaEmpty ? undefined : element.meta.cloneDeep(), element.isAttributesEmpty ? undefined : (0, _apidomDatamodel.cloneDeep)(element.attributes));
|
|
359
360
|
_apidomDatamodel.SourceMapElement.transfer(element, replacement);
|
|
360
361
|
_apidomDatamodel.StyleElement.transfer(element, replacement);
|
|
361
362
|
path.replaceWith(replacement);
|
|
@@ -316,8 +316,9 @@ const schema = {
|
|
|
316
316
|
}
|
|
317
317
|
};
|
|
318
318
|
const findElementFactory = (ancestor, keyName) => {
|
|
319
|
-
const elementType = getNodeType(ancestor);
|
|
320
|
-
const
|
|
319
|
+
const elementType = getNodeType(ancestor);
|
|
320
|
+
const classType = ancestor.isMetaEmpty ? undefined : ancestor.classes.at(0); // @ts-ignore
|
|
321
|
+
const keyMapping = schema[elementType] || schema[classType];
|
|
321
322
|
return typeof keyMapping === 'undefined' ? undefined : Object.hasOwn(keyMapping, '[key: *]') ? keyMapping['[key: *]'] : keyMapping[keyName];
|
|
322
323
|
};
|
|
323
324
|
|
|
@@ -347,7 +348,7 @@ const plugin = () => () => ({
|
|
|
347
348
|
if (typeof elementFactory !== 'function') return;
|
|
348
349
|
const replacement = elementFactory.call({
|
|
349
350
|
context
|
|
350
|
-
}, undefined,
|
|
351
|
+
}, undefined, element.isMetaEmpty ? undefined : element.meta.cloneDeep(), element.isAttributesEmpty ? undefined : cloneDeep(element.attributes));
|
|
351
352
|
SourceMapElement.transfer(element, replacement);
|
|
352
353
|
StyleElement.transfer(element, replacement);
|
|
353
354
|
path.replaceWith(replacement);
|
|
@@ -17,7 +17,7 @@ var _Visitor = _interopRequireDefault(require("./Visitor.cjs"));
|
|
|
17
17
|
*/
|
|
18
18
|
class FallbackVisitor extends _Visitor.default {
|
|
19
19
|
enter(path) {
|
|
20
|
-
this.element = (0, _apidomDatamodel.cloneDeep)(path.node);
|
|
20
|
+
this.element = this.consume ? path.node : (0, _apidomDatamodel.cloneDeep)(path.node);
|
|
21
21
|
path.stop();
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -20,7 +20,7 @@ var _FallbackVisitor = _interopRequireDefault(require("./FallbackVisitor.cjs"));
|
|
|
20
20
|
*/
|
|
21
21
|
class SpecificationVisitor extends _Visitor.default {
|
|
22
22
|
specObj;
|
|
23
|
-
passingOptionsNames = ['specObj'];
|
|
23
|
+
passingOptionsNames = ['specObj', 'consume'];
|
|
24
24
|
constructor({
|
|
25
25
|
specObj,
|
|
26
26
|
...rest
|
|
@@ -66,7 +66,7 @@ class SpecificationVisitor extends _Visitor.default {
|
|
|
66
66
|
*/
|
|
67
67
|
const visitor = this.retrieveVisitorInstance(specPath, options);
|
|
68
68
|
if (visitor instanceof _FallbackVisitor.default && visitor?.constructor === _FallbackVisitor.default) {
|
|
69
|
-
return (0, _apidomDatamodel.cloneDeep)(element);
|
|
69
|
+
return this.consume ? element : (0, _apidomDatamodel.cloneDeep)(element);
|
|
70
70
|
}
|
|
71
71
|
(0, _apidomTraverse.traverse)(element, visitor);
|
|
72
72
|
return visitor.element;
|
|
@@ -14,7 +14,7 @@ import FallbackVisitor from "./FallbackVisitor.mjs";
|
|
|
14
14
|
*/
|
|
15
15
|
class SpecificationVisitor extends Visitor {
|
|
16
16
|
specObj;
|
|
17
|
-
passingOptionsNames = ['specObj'];
|
|
17
|
+
passingOptionsNames = ['specObj', 'consume'];
|
|
18
18
|
constructor({
|
|
19
19
|
specObj,
|
|
20
20
|
...rest
|
|
@@ -60,7 +60,7 @@ class SpecificationVisitor extends Visitor {
|
|
|
60
60
|
*/
|
|
61
61
|
const visitor = this.retrieveVisitorInstance(specPath, options);
|
|
62
62
|
if (visitor instanceof FallbackVisitor && visitor?.constructor === FallbackVisitor) {
|
|
63
|
-
return cloneDeep(element);
|
|
63
|
+
return this.consume ? element : cloneDeep(element);
|
|
64
64
|
}
|
|
65
65
|
traverse(element, visitor);
|
|
66
66
|
return visitor.element;
|
|
@@ -13,19 +13,21 @@ var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
|
13
13
|
*/
|
|
14
14
|
class Visitor {
|
|
15
15
|
element;
|
|
16
|
+
consume = false;
|
|
17
|
+
consumeSafe = false;
|
|
16
18
|
constructor(options = {}) {
|
|
17
19
|
Object.assign(this, options);
|
|
18
20
|
}
|
|
19
21
|
copyMetaAndAttributes(from, to) {
|
|
20
|
-
if (!from.isMetaEmpty
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
to.meta =
|
|
22
|
+
if (!from.isMetaEmpty && !to.isMetaEmpty) {
|
|
23
|
+
to.meta = to.meta.merge(from.meta);
|
|
24
|
+
} else if (!from.isMetaEmpty) {
|
|
25
|
+
to.meta = from.meta.cloneDeep();
|
|
24
26
|
}
|
|
25
|
-
if (!from.isAttributesEmpty
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
to.attributes = (0,
|
|
27
|
+
if (!from.isAttributesEmpty && !to.isAttributesEmpty) {
|
|
28
|
+
to.attributes = (0, _apidomCore.deepmerge)(to.attributes, from.attributes);
|
|
29
|
+
} else if (!from.isAttributesEmpty) {
|
|
30
|
+
to.attributes = (0, _apidomDatamodel.cloneDeep)(from.attributes);
|
|
29
31
|
}
|
|
30
32
|
_apidomDatamodel.SourceMapElement.transfer(from, to);
|
|
31
33
|
_apidomDatamodel.StyleElement.transfer(from, to);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { deepmerge } from '@speclynx/apidom-core';
|
|
2
|
-
import {
|
|
2
|
+
import { SourceMapElement, StyleElement, cloneDeep } from '@speclynx/apidom-datamodel';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @public
|
|
@@ -10,19 +10,21 @@ import { ObjectElement, SourceMapElement, StyleElement } from '@speclynx/apidom-
|
|
|
10
10
|
*/
|
|
11
11
|
class Visitor {
|
|
12
12
|
element;
|
|
13
|
+
consume = false;
|
|
14
|
+
consumeSafe = false;
|
|
13
15
|
constructor(options = {}) {
|
|
14
16
|
Object.assign(this, options);
|
|
15
17
|
}
|
|
16
18
|
copyMetaAndAttributes(from, to) {
|
|
17
|
-
if (!from.isMetaEmpty
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
to.meta =
|
|
19
|
+
if (!from.isMetaEmpty && !to.isMetaEmpty) {
|
|
20
|
+
to.meta = to.meta.merge(from.meta);
|
|
21
|
+
} else if (!from.isMetaEmpty) {
|
|
22
|
+
to.meta = from.meta.cloneDeep();
|
|
21
23
|
}
|
|
22
|
-
if (!from.isAttributesEmpty
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
to.attributes =
|
|
24
|
+
if (!from.isAttributesEmpty && !to.isAttributesEmpty) {
|
|
25
|
+
to.attributes = deepmerge(to.attributes, from.attributes);
|
|
26
|
+
} else if (!from.isAttributesEmpty) {
|
|
27
|
+
to.attributes = cloneDeep(from.attributes);
|
|
26
28
|
}
|
|
27
29
|
SourceMapElement.transfer(from, to);
|
|
28
30
|
StyleElement.transfer(from, to);
|
|
@@ -52,15 +52,18 @@ class FixedFieldsVisitor extends _SpecificationVisitor.default {
|
|
|
52
52
|
const keyValue = (0, _apidomCore.toValue)(key);
|
|
53
53
|
if ((0, _apidomDatamodel.isStringElement)(key) && fields.includes(keyValue) && !this.ignoredFields.includes(keyValue)) {
|
|
54
54
|
const fixedFieldElement = this.toRefractedElement([...specPath, 'fixedFields', keyValue], value);
|
|
55
|
-
const newMemberElement = new _apidomDatamodel.MemberElement((0, _apidomDatamodel.cloneDeep)(key), fixedFieldElement);
|
|
55
|
+
const newMemberElement = new _apidomDatamodel.MemberElement(this.consume ? key : (0, _apidomDatamodel.cloneDeep)(key), fixedFieldElement);
|
|
56
56
|
this.copyMetaAndAttributes(memberElement, newMemberElement);
|
|
57
|
-
newMemberElement.classes.push('fixed-field');
|
|
58
57
|
this.element.content.push(newMemberElement);
|
|
58
|
+
// consume: release processed generic subtree
|
|
59
|
+
if (this.consume && this.consumeSafe && !memberElement.isFrozen) memberElement.value = undefined;
|
|
59
60
|
} else if (this.canSupportSpecificationExtensions && this.specificationExtensionPredicate(memberElement)) {
|
|
60
61
|
const extensionElement = this.toRefractedElement(['document', 'extension'], memberElement);
|
|
61
62
|
this.element.content.push(extensionElement);
|
|
63
|
+
// consume: release processed generic subtree
|
|
64
|
+
if (this.consume && this.consumeSafe && !memberElement.isFrozen) memberElement.value = undefined;
|
|
62
65
|
} else if (!this.ignoredFields.includes(keyValue)) {
|
|
63
|
-
this.element.content.push((0, _apidomDatamodel.cloneDeep)(memberElement));
|
|
66
|
+
this.element.content.push(this.consume ? memberElement : (0, _apidomDatamodel.cloneDeep)(memberElement));
|
|
64
67
|
}
|
|
65
68
|
});
|
|
66
69
|
this.copyMetaAndAttributes(objectElement, this.element);
|
|
@@ -45,15 +45,18 @@ class FixedFieldsVisitor extends SpecificationVisitor {
|
|
|
45
45
|
const keyValue = toValue(key);
|
|
46
46
|
if (isStringElement(key) && fields.includes(keyValue) && !this.ignoredFields.includes(keyValue)) {
|
|
47
47
|
const fixedFieldElement = this.toRefractedElement([...specPath, 'fixedFields', keyValue], value);
|
|
48
|
-
const newMemberElement = new MemberElement(cloneDeep(key), fixedFieldElement);
|
|
48
|
+
const newMemberElement = new MemberElement(this.consume ? key : cloneDeep(key), fixedFieldElement);
|
|
49
49
|
this.copyMetaAndAttributes(memberElement, newMemberElement);
|
|
50
|
-
newMemberElement.classes.push('fixed-field');
|
|
51
50
|
this.element.content.push(newMemberElement);
|
|
51
|
+
// consume: release processed generic subtree
|
|
52
|
+
if (this.consume && this.consumeSafe && !memberElement.isFrozen) memberElement.value = undefined;
|
|
52
53
|
} else if (this.canSupportSpecificationExtensions && this.specificationExtensionPredicate(memberElement)) {
|
|
53
54
|
const extensionElement = this.toRefractedElement(['document', 'extension'], memberElement);
|
|
54
55
|
this.element.content.push(extensionElement);
|
|
56
|
+
// consume: release processed generic subtree
|
|
57
|
+
if (this.consume && this.consumeSafe && !memberElement.isFrozen) memberElement.value = undefined;
|
|
55
58
|
} else if (!this.ignoredFields.includes(keyValue)) {
|
|
56
|
-
this.element.content.push(cloneDeep(memberElement));
|
|
59
|
+
this.element.content.push(this.consume ? memberElement : cloneDeep(memberElement));
|
|
57
60
|
}
|
|
58
61
|
});
|
|
59
62
|
this.copyMetaAndAttributes(objectElement, this.element);
|
|
@@ -55,12 +55,14 @@ class PatternedFieldsVisitor extends _SpecificationVisitor.default {
|
|
|
55
55
|
} else if (!this.ignoredFields.includes(keyValue) && this.fieldPatternPredicate(keyValue)) {
|
|
56
56
|
const specPath = this.specPath(value);
|
|
57
57
|
const patternedFieldElement = this.toRefractedElement(specPath, value);
|
|
58
|
-
const newMemberElement = new _apidomDatamodel.MemberElement((0, _apidomDatamodel.cloneDeep)(key), patternedFieldElement);
|
|
58
|
+
const newMemberElement = new _apidomDatamodel.MemberElement(this.consume ? key : (0, _apidomDatamodel.cloneDeep)(key), patternedFieldElement);
|
|
59
59
|
this.copyMetaAndAttributes(memberElement, newMemberElement);
|
|
60
60
|
newMemberElement.classes.push('patterned-field');
|
|
61
61
|
this.element.content.push(newMemberElement);
|
|
62
|
+
// consume: release processed generic subtree
|
|
63
|
+
if (this.consume && this.consumeSafe && !memberElement.isFrozen) memberElement.value = undefined;
|
|
62
64
|
} else if (!this.ignoredFields.includes(keyValue)) {
|
|
63
|
-
this.element.content.push((0, _apidomDatamodel.cloneDeep)(memberElement));
|
|
65
|
+
this.element.content.push(this.consume ? memberElement : (0, _apidomDatamodel.cloneDeep)(memberElement));
|
|
64
66
|
}
|
|
65
67
|
});
|
|
66
68
|
this.copyMetaAndAttributes(objectElement, this.element);
|
|
@@ -49,12 +49,14 @@ class PatternedFieldsVisitor extends SpecificationVisitor {
|
|
|
49
49
|
} else if (!this.ignoredFields.includes(keyValue) && this.fieldPatternPredicate(keyValue)) {
|
|
50
50
|
const specPath = this.specPath(value);
|
|
51
51
|
const patternedFieldElement = this.toRefractedElement(specPath, value);
|
|
52
|
-
const newMemberElement = new MemberElement(cloneDeep(key), patternedFieldElement);
|
|
52
|
+
const newMemberElement = new MemberElement(this.consume ? key : cloneDeep(key), patternedFieldElement);
|
|
53
53
|
this.copyMetaAndAttributes(memberElement, newMemberElement);
|
|
54
54
|
newMemberElement.classes.push('patterned-field');
|
|
55
55
|
this.element.content.push(newMemberElement);
|
|
56
|
+
// consume: release processed generic subtree
|
|
57
|
+
if (this.consume && this.consumeSafe && !memberElement.isFrozen) memberElement.value = undefined;
|
|
56
58
|
} else if (!this.ignoredFields.includes(keyValue)) {
|
|
57
|
-
this.element.content.push(cloneDeep(memberElement));
|
|
59
|
+
this.element.content.push(this.consume ? memberElement : cloneDeep(memberElement));
|
|
58
60
|
}
|
|
59
61
|
});
|
|
60
62
|
this.copyMetaAndAttributes(objectElement, this.element);
|
|
@@ -13,6 +13,7 @@ class SwaggerVisitor extends _bases.BaseFixedFieldsVisitor {
|
|
|
13
13
|
constructor(options) {
|
|
14
14
|
super(options);
|
|
15
15
|
this.element = new _Swagger.default();
|
|
16
|
+
this.consumeSafe = true;
|
|
16
17
|
this.specPath = (0, _ramda.always)(['document', 'objects', 'Swagger']);
|
|
17
18
|
this.canSupportSpecificationExtensions = true;
|
|
18
19
|
}
|
|
@@ -8,6 +8,7 @@ class SwaggerVisitor extends BaseFixedFieldsVisitor {
|
|
|
8
8
|
constructor(options) {
|
|
9
9
|
super(options);
|
|
10
10
|
this.element = new SwaggerElement();
|
|
11
|
+
this.consumeSafe = true;
|
|
11
12
|
this.specPath = always(['document', 'objects', 'Swagger']);
|
|
12
13
|
this.canSupportSpecificationExtensions = true;
|
|
13
14
|
}
|
|
@@ -16,6 +16,7 @@ class PathItemVisitor extends _bases.BaseFixedFieldsVisitor {
|
|
|
16
16
|
constructor(options) {
|
|
17
17
|
super(options);
|
|
18
18
|
this.element = new _PathItem.default();
|
|
19
|
+
this.consumeSafe = true;
|
|
19
20
|
this.specPath = (0, _ramda.always)(['document', 'objects', 'PathItem']);
|
|
20
21
|
}
|
|
21
22
|
ObjectElement(path) {
|
|
@@ -11,6 +11,7 @@ class PathItemVisitor extends BaseFixedFieldsVisitor {
|
|
|
11
11
|
constructor(options) {
|
|
12
12
|
super(options);
|
|
13
13
|
this.element = new PathItemElement();
|
|
14
|
+
this.consumeSafe = true;
|
|
14
15
|
this.specPath = always(['document', 'objects', 'PathItem']);
|
|
15
16
|
}
|
|
16
17
|
ObjectElement(path) {
|
|
@@ -16,6 +16,7 @@ class PathsVisitor extends _bases.BasePatternedFieldsVisitor {
|
|
|
16
16
|
constructor(options) {
|
|
17
17
|
super(options);
|
|
18
18
|
this.element = new _Paths.default();
|
|
19
|
+
this.consumeSafe = true;
|
|
19
20
|
this.specPath = (0, _ramda.always)(['document', 'objects', 'PathItem']);
|
|
20
21
|
this.canSupportSpecificationExtensions = true;
|
|
21
22
|
this.fieldPatternPredicate = _ramda.T;
|
|
@@ -11,6 +11,7 @@ class PathsVisitor extends BasePatternedFieldsVisitor {
|
|
|
11
11
|
constructor(options) {
|
|
12
12
|
super(options);
|
|
13
13
|
this.element = new PathsElement();
|
|
14
|
+
this.consumeSafe = true;
|
|
14
15
|
this.specPath = always(['document', 'objects', 'PathItem']);
|
|
15
16
|
this.canSupportSpecificationExtensions = true;
|
|
16
17
|
this.fieldPatternPredicate = stubTrue;
|
|
@@ -23,6 +23,7 @@ import { NumberElement } from '@speclynx/apidom-datamodel';
|
|
|
23
23
|
import { ObjectElement } from '@speclynx/apidom-datamodel';
|
|
24
24
|
import { Path } from '@speclynx/apidom-traverse';
|
|
25
25
|
import { PropertiesVisitor } from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
26
|
+
import { refractJSONReference } from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
26
27
|
import { RequiredVisitor } from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
27
28
|
import { AllOfVisitorOptions as SchemaAllOfVisitorOptions } from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
28
29
|
import { ItemsVisitorOptions as SchemaItemsVisitorOptions } from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
@@ -1186,7 +1187,7 @@ export declare class ReferenceVisitor extends BaseFixedFieldsVisitor {
|
|
|
1186
1187
|
/**
|
|
1187
1188
|
* @public
|
|
1188
1189
|
*/
|
|
1189
|
-
export declare const refract: <T extends Element_2>(value: unknown, { element, plugins, specificationObj }?: RefractorOptions) => T;
|
|
1190
|
+
export declare const refract: <T extends Element_2>(value: unknown, { element, plugins, specificationObj, consume, }?: RefractorOptions) => T;
|
|
1190
1191
|
|
|
1191
1192
|
/**
|
|
1192
1193
|
* Refracts a value into a ContactElement.
|
|
@@ -1236,6 +1237,8 @@ export declare const refractInfo: <T extends Element_2 = InfoElement>(value: unk
|
|
|
1236
1237
|
*/
|
|
1237
1238
|
export declare const refractItems: <T extends Element_2 = ItemsElement>(value: unknown, options?: Omit<RefractorOptions, "element">) => T;
|
|
1238
1239
|
|
|
1240
|
+
export { refractJSONReference }
|
|
1241
|
+
|
|
1239
1242
|
/**
|
|
1240
1243
|
* Refracts a value into a LicenseElement.
|
|
1241
1244
|
* @public
|
|
@@ -1255,6 +1258,7 @@ export declare interface RefractorOptions {
|
|
|
1255
1258
|
readonly element?: string;
|
|
1256
1259
|
readonly plugins?: RefractorPlugin[];
|
|
1257
1260
|
readonly specificationObj?: typeof specificationObj;
|
|
1261
|
+
readonly consume?: boolean;
|
|
1258
1262
|
}
|
|
1259
1263
|
|
|
1260
1264
|
/**
|
|
@@ -2239,7 +2243,7 @@ export declare class SpecificationVisitor extends Visitor {
|
|
|
2239
2243
|
protected readonly specObj: typeof specificationObj;
|
|
2240
2244
|
protected readonly passingOptionsNames: string[];
|
|
2241
2245
|
constructor({ specObj, ...rest }: SpecificationVisitorOptions);
|
|
2242
|
-
retrievePassingOptions():
|
|
2246
|
+
retrievePassingOptions(): Record<string, unknown>;
|
|
2243
2247
|
retrieveFixedFields(specPath: string[]): string[];
|
|
2244
2248
|
retrieveVisitor(specPath: string[]): unknown;
|
|
2245
2249
|
retrieveVisitorInstance(specPath: string[], options?: {}): Visitor;
|
|
@@ -2407,6 +2411,8 @@ export declare interface Toolbox {
|
|
|
2407
2411
|
*/
|
|
2408
2412
|
export declare class Visitor {
|
|
2409
2413
|
element: Element_2;
|
|
2414
|
+
protected readonly consume: boolean;
|
|
2415
|
+
protected consumeSafe: boolean;
|
|
2410
2416
|
constructor(options?: VisitorOptions);
|
|
2411
2417
|
copyMetaAndAttributes(from: Element_2, to: Element_2): void;
|
|
2412
2418
|
}
|
|
@@ -2415,6 +2421,7 @@ export declare class Visitor {
|
|
|
2415
2421
|
* @public
|
|
2416
2422
|
*/
|
|
2417
2423
|
declare interface VisitorOptions {
|
|
2424
|
+
readonly consume?: boolean;
|
|
2418
2425
|
}
|
|
2419
2426
|
export { VisitorOptions as BasePathVisitorOptions }
|
|
2420
2427
|
export { VisitorOptions as ConsumesVisitorOptions }
|