@speclynx/apidom-ns-openapi-2 4.0.5 → 4.2.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 +10 -0
- package/README.md +122 -0
- package/dist/apidom-ns-openapi-2.browser.js +538 -166
- package/dist/apidom-ns-openapi-2.browser.min.js +1 -1
- package/package.json +8 -7
- package/src/index.cjs +8 -2
- package/src/index.mjs +3 -0
- package/src/refractor/plugins/normalize-parameters.cjs +108 -0
- package/src/refractor/plugins/normalize-parameters.mjs +102 -0
- package/src/refractor/plugins/normalize-security-requirements.cjs +87 -0
- package/src/refractor/plugins/normalize-security-requirements.mjs +81 -0
- package/src/refractor/plugins/normalize-storage/index.cjs +38 -0
- package/src/refractor/plugins/normalize-storage/index.mjs +34 -0
- package/src/refractor/toolbox.cjs +6 -1
- package/src/refractor/toolbox.mjs +7 -2
- package/types/apidom-ns-openapi-2.d.ts +73 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@speclynx/apidom-ns-openapi-2",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "OpenAPI 2.0 namespace for ApiDOM.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"apidom",
|
|
@@ -56,11 +56,12 @@
|
|
|
56
56
|
"license": "Apache-2.0",
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@babel/runtime-corejs3": "^7.28.4",
|
|
59
|
-
"@speclynx/apidom-core": "4.0
|
|
60
|
-
"@speclynx/apidom-datamodel": "4.0
|
|
61
|
-
"@speclynx/apidom-error": "4.0
|
|
62
|
-
"@speclynx/apidom-
|
|
63
|
-
"@speclynx/apidom-
|
|
59
|
+
"@speclynx/apidom-core": "4.2.0",
|
|
60
|
+
"@speclynx/apidom-datamodel": "4.2.0",
|
|
61
|
+
"@speclynx/apidom-error": "4.2.0",
|
|
62
|
+
"@speclynx/apidom-json-pointer": "4.2.0",
|
|
63
|
+
"@speclynx/apidom-ns-json-schema-draft-4": "4.2.0",
|
|
64
|
+
"@speclynx/apidom-traverse": "4.2.0",
|
|
64
65
|
"ramda": "~0.32.0",
|
|
65
66
|
"ramda-adjunct": "^6.0.0",
|
|
66
67
|
"ts-mixer": "^6.0.4"
|
|
@@ -75,5 +76,5 @@
|
|
|
75
76
|
"README.md",
|
|
76
77
|
"CHANGELOG.md"
|
|
77
78
|
],
|
|
78
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "3485d180340f2d4fad149bcf062a6f618030ca9b"
|
|
79
80
|
}
|
package/src/index.cjs
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
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 = exports.refractOperation = void 0;
|
|
6
|
+
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.createToolbox = 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.refractorPluginNormalizeSecurityRequirements = exports.refractorPluginNormalizeParameters = 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 = exports.refractLicense = 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;
|
|
@@ -17,6 +17,10 @@ var _namespace = _interopRequireDefault(require("./namespace.cjs"));
|
|
|
17
17
|
exports.default = _namespace.default;
|
|
18
18
|
var _replaceEmptyElement = _interopRequireDefault(require("./refractor/plugins/replace-empty-element.cjs"));
|
|
19
19
|
exports.refractorPluginReplaceEmptyElement = _replaceEmptyElement.default;
|
|
20
|
+
var _normalizeParameters = _interopRequireDefault(require("./refractor/plugins/normalize-parameters.cjs"));
|
|
21
|
+
exports.refractorPluginNormalizeParameters = _normalizeParameters.default;
|
|
22
|
+
var _normalizeSecurityRequirements = _interopRequireDefault(require("./refractor/plugins/normalize-security-requirements.cjs"));
|
|
23
|
+
exports.refractorPluginNormalizeSecurityRequirements = _normalizeSecurityRequirements.default;
|
|
20
24
|
var _index = _interopRequireWildcard(require("./refractor/index.cjs"));
|
|
21
25
|
exports.refract = _index.default;
|
|
22
26
|
exports.refractSwagger = _index.refractSwagger;
|
|
@@ -45,6 +49,8 @@ exports.refractSecurityDefinitions = _index.refractSecurityDefinitions;
|
|
|
45
49
|
exports.refractSecurityScheme = _index.refractSecurityScheme;
|
|
46
50
|
exports.refractScopes = _index.refractScopes;
|
|
47
51
|
exports.refractSecurityRequirement = _index.refractSecurityRequirement;
|
|
52
|
+
var _toolbox = _interopRequireDefault(require("./refractor/toolbox.cjs"));
|
|
53
|
+
exports.createToolbox = _toolbox.default;
|
|
48
54
|
var _specification = _interopRequireDefault(require("./refractor/specification.cjs"));
|
|
49
55
|
exports.specificationObj = _specification.default;
|
|
50
56
|
var _predicates = require("./predicates.cjs");
|
package/src/index.mjs
CHANGED
|
@@ -2,7 +2,10 @@ export { isJSONReferenceElement, isJSONReferenceLikeElement, JSONReferenceElemen
|
|
|
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";
|
|
5
|
+
export { default as refractorPluginNormalizeParameters } from "./refractor/plugins/normalize-parameters.mjs";
|
|
6
|
+
export { default as refractorPluginNormalizeSecurityRequirements } from "./refractor/plugins/normalize-security-requirements.mjs";
|
|
5
7
|
export { default as refract, refractSwagger, refractInfo, refractContact, refractLicense, refractPaths, refractPathItem, refractOperation, refractExternalDocumentation, refractParameter, refractItems, refractResponses, refractResponse, refractHeaders, refractExample, refractHeader, refractTag, refractReference, refractSchema, refractXml, refractDefinitions, refractParametersDefinitions, refractResponsesDefinitions, refractSecurityDefinitions, refractSecurityScheme, refractScopes, refractSecurityRequirement } from "./refractor/index.mjs";
|
|
8
|
+
export { default as createToolbox } from "./refractor/toolbox.mjs";
|
|
6
9
|
export { default as specificationObj } from "./refractor/specification.mjs";
|
|
7
10
|
export { isSwaggerElement, isSwaggerVersionElement, isInfoElement, isContactElement, isLicenseElement, isPathsElement, isPathItemElement, isOperationElement, isExternalDocumentationElement, isParameterElement, isItemsElement, isResponsesElement, isResponseElement, isHeadersElement, isExampleElement, isHeaderElement, isTagElement, isReferenceElement, isSchemaElement, isXmlElement, isDefinitionsElement, isParametersDefinitionsElement, isResponsesDefinitionsElement, isSecurityDefinitionsElement, isSecuritySchemeElement, isScopesElement, isSecurityRequirementElement } from "./predicates.mjs";
|
|
8
11
|
export { isReferenceLikeElement, isSwaggerExtension } from "./refractor/predicates.mjs";
|
|
@@ -0,0 +1,108 @@
|
|
|
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 _apidomCore = require("@speclynx/apidom-core");
|
|
8
|
+
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
9
|
+
var _OperationParameters = _interopRequireDefault(require("../../elements/nces/OperationParameters.cjs"));
|
|
10
|
+
var _index = _interopRequireDefault(require("./normalize-storage/index.cjs"));
|
|
11
|
+
var _predicates = require("../../predicates.cjs");
|
|
12
|
+
/**
|
|
13
|
+
* Inheritance of Parameter Objects.
|
|
14
|
+
*
|
|
15
|
+
* OpenAPI 2.0 specification excerpt that defines the inheritance behavior:
|
|
16
|
+
*
|
|
17
|
+
* A list of parameters that are applicable for all the operations described under this path.
|
|
18
|
+
* These parameters can be overridden at the operation level, but cannot be removed there.
|
|
19
|
+
* The list MUST NOT include duplicated parameters.
|
|
20
|
+
* A unique parameter is defined by a combination of a name and location.
|
|
21
|
+
*
|
|
22
|
+
* NOTE: this plugin is idempotent
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Establishes identity between two Parameter Objects.
|
|
28
|
+
* A unique parameter is defined by a combination of a name and location.
|
|
29
|
+
*
|
|
30
|
+
* {@link https://spec.openapis.org/oas/v2.0.html#path-item-object}
|
|
31
|
+
*/
|
|
32
|
+
const parameterEquals = (parameter1, parameter2) => {
|
|
33
|
+
if (!(0, _predicates.isParameterElement)(parameter1)) return false;
|
|
34
|
+
if (!(0, _predicates.isParameterElement)(parameter2)) return false;
|
|
35
|
+
if (!(0, _apidomDatamodel.isStringElement)(parameter1.name)) return false;
|
|
36
|
+
if (!(0, _apidomDatamodel.isStringElement)(parameter1.in)) return false;
|
|
37
|
+
if (!(0, _apidomDatamodel.isStringElement)(parameter2.name)) return false;
|
|
38
|
+
if (!(0, _apidomDatamodel.isStringElement)(parameter2.in)) return false;
|
|
39
|
+
return (0, _apidomCore.toValue)(parameter1.name) === (0, _apidomCore.toValue)(parameter2.name) && (0, _apidomCore.toValue)(parameter1.in) === (0, _apidomCore.toValue)(parameter2.in);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Inherits parameters from a PathItem into an Operation element.
|
|
44
|
+
* Operation parameters take precedence; PathItem parameters are merged in
|
|
45
|
+
* for any (name, in) combination not already defined at the Operation level.
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
const inheritParametersToOperation = (operationElement, pathItemElement) => {
|
|
49
|
+
const pathItemParams = (0, _apidomDatamodel.isArrayElement)(pathItemElement.parameters) ? [...pathItemElement.parameters] : [];
|
|
50
|
+
if (pathItemParams.length === 0) return;
|
|
51
|
+
const operationParams = (0, _apidomDatamodel.isArrayElement)(operationElement.parameters) ? [...operationElement.parameters] : [];
|
|
52
|
+
|
|
53
|
+
// prefers the first item if two items compare equal based on the predicate
|
|
54
|
+
const mergedParameters = (0, _ramda.uniqWith)(parameterEquals, [...operationParams, ...pathItemParams]);
|
|
55
|
+
operationElement.parameters = new _OperationParameters.default(mergedParameters);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
const plugin = ({
|
|
62
|
+
storageField = 'x-normalized'
|
|
63
|
+
} = {}) => toolbox => {
|
|
64
|
+
const {
|
|
65
|
+
predicates
|
|
66
|
+
} = toolbox;
|
|
67
|
+
let storage;
|
|
68
|
+
return {
|
|
69
|
+
visitor: {
|
|
70
|
+
SwaggerElement: {
|
|
71
|
+
enter(path) {
|
|
72
|
+
const element = path.node;
|
|
73
|
+
storage = new _index.default(element, storageField, 'parameters');
|
|
74
|
+
},
|
|
75
|
+
leave() {
|
|
76
|
+
storage = undefined;
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
OperationElement: {
|
|
80
|
+
leave(path) {
|
|
81
|
+
const operationElement = path.node;
|
|
82
|
+
const ancestors = path.getAncestorNodes(); // parent to root order
|
|
83
|
+
|
|
84
|
+
// skip visiting this Operation if inside parameters definitions
|
|
85
|
+
if (ancestors.some(predicates.isParametersDefinitionsElement)) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const parentPathItemElement = ancestors.find(predicates.isPathItemElement);
|
|
89
|
+
|
|
90
|
+
// no parent Path Item to inherit from
|
|
91
|
+
if (!predicates.isPathItemElement(parentPathItemElement)) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const operationJSONPointer = path.formatPath();
|
|
95
|
+
|
|
96
|
+
// skip visiting this Operation Object if it's already normalized
|
|
97
|
+
if (storage.includes(operationJSONPointer)) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
inheritParametersToOperation(operationElement, parentPathItemElement);
|
|
101
|
+
storage.append(operationJSONPointer);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
plugin.inheritParametersToOperation = inheritParametersToOperation;
|
|
108
|
+
var _default = exports.default = plugin;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { uniqWith } from 'ramda';
|
|
2
|
+
import { toValue } from '@speclynx/apidom-core';
|
|
3
|
+
import { isStringElement, isArrayElement } from '@speclynx/apidom-datamodel';
|
|
4
|
+
import OperationParametersElement from "../../elements/nces/OperationParameters.mjs";
|
|
5
|
+
import NormalizeStorage from "./normalize-storage/index.mjs";
|
|
6
|
+
import { isParameterElement } from "../../predicates.mjs";
|
|
7
|
+
/**
|
|
8
|
+
* Inheritance of Parameter Objects.
|
|
9
|
+
*
|
|
10
|
+
* OpenAPI 2.0 specification excerpt that defines the inheritance behavior:
|
|
11
|
+
*
|
|
12
|
+
* A list of parameters that are applicable for all the operations described under this path.
|
|
13
|
+
* These parameters can be overridden at the operation level, but cannot be removed there.
|
|
14
|
+
* The list MUST NOT include duplicated parameters.
|
|
15
|
+
* A unique parameter is defined by a combination of a name and location.
|
|
16
|
+
*
|
|
17
|
+
* NOTE: this plugin is idempotent
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Establishes identity between two Parameter Objects.
|
|
22
|
+
* A unique parameter is defined by a combination of a name and location.
|
|
23
|
+
*
|
|
24
|
+
* {@link https://spec.openapis.org/oas/v2.0.html#path-item-object}
|
|
25
|
+
*/
|
|
26
|
+
const parameterEquals = (parameter1, parameter2) => {
|
|
27
|
+
if (!isParameterElement(parameter1)) return false;
|
|
28
|
+
if (!isParameterElement(parameter2)) return false;
|
|
29
|
+
if (!isStringElement(parameter1.name)) return false;
|
|
30
|
+
if (!isStringElement(parameter1.in)) return false;
|
|
31
|
+
if (!isStringElement(parameter2.name)) return false;
|
|
32
|
+
if (!isStringElement(parameter2.in)) return false;
|
|
33
|
+
return toValue(parameter1.name) === toValue(parameter2.name) && toValue(parameter1.in) === toValue(parameter2.in);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Inherits parameters from a PathItem into an Operation element.
|
|
38
|
+
* Operation parameters take precedence; PathItem parameters are merged in
|
|
39
|
+
* for any (name, in) combination not already defined at the Operation level.
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
const inheritParametersToOperation = (operationElement, pathItemElement) => {
|
|
43
|
+
const pathItemParams = isArrayElement(pathItemElement.parameters) ? [...pathItemElement.parameters] : [];
|
|
44
|
+
if (pathItemParams.length === 0) return;
|
|
45
|
+
const operationParams = isArrayElement(operationElement.parameters) ? [...operationElement.parameters] : [];
|
|
46
|
+
|
|
47
|
+
// prefers the first item if two items compare equal based on the predicate
|
|
48
|
+
const mergedParameters = uniqWith(parameterEquals, [...operationParams, ...pathItemParams]);
|
|
49
|
+
operationElement.parameters = new OperationParametersElement(mergedParameters);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
55
|
+
const plugin = ({
|
|
56
|
+
storageField = 'x-normalized'
|
|
57
|
+
} = {}) => toolbox => {
|
|
58
|
+
const {
|
|
59
|
+
predicates
|
|
60
|
+
} = toolbox;
|
|
61
|
+
let storage;
|
|
62
|
+
return {
|
|
63
|
+
visitor: {
|
|
64
|
+
SwaggerElement: {
|
|
65
|
+
enter(path) {
|
|
66
|
+
const element = path.node;
|
|
67
|
+
storage = new NormalizeStorage(element, storageField, 'parameters');
|
|
68
|
+
},
|
|
69
|
+
leave() {
|
|
70
|
+
storage = undefined;
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
OperationElement: {
|
|
74
|
+
leave(path) {
|
|
75
|
+
const operationElement = path.node;
|
|
76
|
+
const ancestors = path.getAncestorNodes(); // parent to root order
|
|
77
|
+
|
|
78
|
+
// skip visiting this Operation if inside parameters definitions
|
|
79
|
+
if (ancestors.some(predicates.isParametersDefinitionsElement)) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const parentPathItemElement = ancestors.find(predicates.isPathItemElement);
|
|
83
|
+
|
|
84
|
+
// no parent Path Item to inherit from
|
|
85
|
+
if (!predicates.isPathItemElement(parentPathItemElement)) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const operationJSONPointer = path.formatPath();
|
|
89
|
+
|
|
90
|
+
// skip visiting this Operation Object if it's already normalized
|
|
91
|
+
if (storage.includes(operationJSONPointer)) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
inheritParametersToOperation(operationElement, parentPathItemElement);
|
|
95
|
+
storage.append(operationJSONPointer);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
plugin.inheritParametersToOperation = inheritParametersToOperation;
|
|
102
|
+
export default plugin;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
7
|
+
var _OperationSecurity = _interopRequireDefault(require("../../elements/nces/OperationSecurity.cjs"));
|
|
8
|
+
var _index = _interopRequireDefault(require("./normalize-storage/index.cjs"));
|
|
9
|
+
/**
|
|
10
|
+
* Override of Security Requirement Objects.
|
|
11
|
+
*
|
|
12
|
+
* OpenAPI 2.0 specification excerpt that defines the override behavior:
|
|
13
|
+
*
|
|
14
|
+
* Operation.security definition overrides any declared top-level security.
|
|
15
|
+
* To remove a top-level security declaration, an empty array can be used.
|
|
16
|
+
*
|
|
17
|
+
* NOTE: this plugin is idempotent
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Inherits top-level security requirements into an Operation element.
|
|
23
|
+
* If Operation.security is missing and Swagger.security is defined, copies it down.
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
const inheritSecurityToOperation = (operationElement, swaggerElement) => {
|
|
27
|
+
const missingOperationLevelSecurity = typeof operationElement.security === 'undefined';
|
|
28
|
+
const hasTopLevelSecurity = (0, _apidomDatamodel.isArrayElement)(swaggerElement.security);
|
|
29
|
+
if (missingOperationLevelSecurity && hasTopLevelSecurity) {
|
|
30
|
+
operationElement.security = new _OperationSecurity.default([...swaggerElement.security]);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
const plugin = ({
|
|
38
|
+
storageField = 'x-normalized'
|
|
39
|
+
} = {}) => toolbox => {
|
|
40
|
+
const {
|
|
41
|
+
predicates
|
|
42
|
+
} = toolbox;
|
|
43
|
+
let topLevelSecurity;
|
|
44
|
+
let storage;
|
|
45
|
+
return {
|
|
46
|
+
visitor: {
|
|
47
|
+
SwaggerElement: {
|
|
48
|
+
enter(path) {
|
|
49
|
+
const swaggerElement = path.node;
|
|
50
|
+
storage = new _index.default(swaggerElement, storageField, 'security-requirements');
|
|
51
|
+
if (predicates.isArrayElement(swaggerElement.security)) {
|
|
52
|
+
topLevelSecurity = swaggerElement.security;
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
leave() {
|
|
56
|
+
storage = undefined;
|
|
57
|
+
topLevelSecurity = undefined;
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
OperationElement: {
|
|
61
|
+
leave(path) {
|
|
62
|
+
const operationElement = path.node;
|
|
63
|
+
const ancestors = path.getAncestorNodes(); // parent to root order
|
|
64
|
+
|
|
65
|
+
// skip visiting this Operation if inside parameters definitions
|
|
66
|
+
if (ancestors.some(predicates.isParametersDefinitionsElement)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const operationJSONPointer = path.formatPath();
|
|
70
|
+
|
|
71
|
+
// skip visiting this Operation Object if it's already normalized
|
|
72
|
+
if (storage.includes(operationJSONPointer)) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const missingOperationLevelSecurity = typeof operationElement.security === 'undefined';
|
|
76
|
+
const hasTopLevelSecurity = typeof topLevelSecurity !== 'undefined';
|
|
77
|
+
if (missingOperationLevelSecurity && hasTopLevelSecurity) {
|
|
78
|
+
operationElement.security = new _OperationSecurity.default([...topLevelSecurity]);
|
|
79
|
+
storage.append(operationJSONPointer);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
plugin.inheritSecurityToOperation = inheritSecurityToOperation;
|
|
87
|
+
var _default = exports.default = plugin;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { isArrayElement } from '@speclynx/apidom-datamodel';
|
|
2
|
+
import OperationSecurityElement from "../../elements/nces/OperationSecurity.mjs";
|
|
3
|
+
import NormalizeStorage from "./normalize-storage/index.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* Override of Security Requirement Objects.
|
|
6
|
+
*
|
|
7
|
+
* OpenAPI 2.0 specification excerpt that defines the override behavior:
|
|
8
|
+
*
|
|
9
|
+
* Operation.security definition overrides any declared top-level security.
|
|
10
|
+
* To remove a top-level security declaration, an empty array can be used.
|
|
11
|
+
*
|
|
12
|
+
* NOTE: this plugin is idempotent
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Inherits top-level security requirements into an Operation element.
|
|
17
|
+
* If Operation.security is missing and Swagger.security is defined, copies it down.
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
const inheritSecurityToOperation = (operationElement, swaggerElement) => {
|
|
21
|
+
const missingOperationLevelSecurity = typeof operationElement.security === 'undefined';
|
|
22
|
+
const hasTopLevelSecurity = isArrayElement(swaggerElement.security);
|
|
23
|
+
if (missingOperationLevelSecurity && hasTopLevelSecurity) {
|
|
24
|
+
operationElement.security = new OperationSecurityElement([...swaggerElement.security]);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
const plugin = ({
|
|
32
|
+
storageField = 'x-normalized'
|
|
33
|
+
} = {}) => toolbox => {
|
|
34
|
+
const {
|
|
35
|
+
predicates
|
|
36
|
+
} = toolbox;
|
|
37
|
+
let topLevelSecurity;
|
|
38
|
+
let storage;
|
|
39
|
+
return {
|
|
40
|
+
visitor: {
|
|
41
|
+
SwaggerElement: {
|
|
42
|
+
enter(path) {
|
|
43
|
+
const swaggerElement = path.node;
|
|
44
|
+
storage = new NormalizeStorage(swaggerElement, storageField, 'security-requirements');
|
|
45
|
+
if (predicates.isArrayElement(swaggerElement.security)) {
|
|
46
|
+
topLevelSecurity = swaggerElement.security;
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
leave() {
|
|
50
|
+
storage = undefined;
|
|
51
|
+
topLevelSecurity = undefined;
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
OperationElement: {
|
|
55
|
+
leave(path) {
|
|
56
|
+
const operationElement = path.node;
|
|
57
|
+
const ancestors = path.getAncestorNodes(); // parent to root order
|
|
58
|
+
|
|
59
|
+
// skip visiting this Operation if inside parameters definitions
|
|
60
|
+
if (ancestors.some(predicates.isParametersDefinitionsElement)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const operationJSONPointer = path.formatPath();
|
|
64
|
+
|
|
65
|
+
// skip visiting this Operation Object if it's already normalized
|
|
66
|
+
if (storage.includes(operationJSONPointer)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const missingOperationLevelSecurity = typeof operationElement.security === 'undefined';
|
|
70
|
+
const hasTopLevelSecurity = typeof topLevelSecurity !== 'undefined';
|
|
71
|
+
if (missingOperationLevelSecurity && hasTopLevelSecurity) {
|
|
72
|
+
operationElement.security = new OperationSecurityElement([...topLevelSecurity]);
|
|
73
|
+
storage.append(operationJSONPointer);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
plugin.inheritSecurityToOperation = inheritSecurityToOperation;
|
|
81
|
+
export default plugin;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
6
|
+
class NormalizeStorage {
|
|
7
|
+
internalStore;
|
|
8
|
+
constructor(storageElement, storageField, storageSubField) {
|
|
9
|
+
this.storageElement = storageElement;
|
|
10
|
+
this.storageField = storageField;
|
|
11
|
+
this.storageSubField = storageSubField;
|
|
12
|
+
}
|
|
13
|
+
get store() {
|
|
14
|
+
if (this.internalStore === undefined) {
|
|
15
|
+
let rootStore = this.storageElement.get(this.storageField);
|
|
16
|
+
if (!(0, _apidomDatamodel.isObjectElement)(rootStore)) {
|
|
17
|
+
rootStore = new _apidomDatamodel.ObjectElement();
|
|
18
|
+
this.storageElement.set(this.storageField, rootStore);
|
|
19
|
+
}
|
|
20
|
+
let store = rootStore.get(this.storageSubField);
|
|
21
|
+
if (!(0, _apidomDatamodel.isArrayElement)(store)) {
|
|
22
|
+
store = new _apidomDatamodel.ArrayElement();
|
|
23
|
+
rootStore.set(this.storageSubField, store);
|
|
24
|
+
}
|
|
25
|
+
this.internalStore = store;
|
|
26
|
+
}
|
|
27
|
+
return this.internalStore;
|
|
28
|
+
}
|
|
29
|
+
append(pointer) {
|
|
30
|
+
if (!this.includes(pointer)) {
|
|
31
|
+
this.store.push(pointer);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
includes(pointer) {
|
|
35
|
+
return this.store.includes(pointer);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
var _default = exports.default = NormalizeStorage;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ArrayElement, ObjectElement, isObjectElement, isArrayElement } from '@speclynx/apidom-datamodel';
|
|
2
|
+
class NormalizeStorage {
|
|
3
|
+
internalStore;
|
|
4
|
+
constructor(storageElement, storageField, storageSubField) {
|
|
5
|
+
this.storageElement = storageElement;
|
|
6
|
+
this.storageField = storageField;
|
|
7
|
+
this.storageSubField = storageSubField;
|
|
8
|
+
}
|
|
9
|
+
get store() {
|
|
10
|
+
if (this.internalStore === undefined) {
|
|
11
|
+
let rootStore = this.storageElement.get(this.storageField);
|
|
12
|
+
if (!isObjectElement(rootStore)) {
|
|
13
|
+
rootStore = new ObjectElement();
|
|
14
|
+
this.storageElement.set(this.storageField, rootStore);
|
|
15
|
+
}
|
|
16
|
+
let store = rootStore.get(this.storageSubField);
|
|
17
|
+
if (!isArrayElement(store)) {
|
|
18
|
+
store = new ArrayElement();
|
|
19
|
+
rootStore.set(this.storageSubField, store);
|
|
20
|
+
}
|
|
21
|
+
this.internalStore = store;
|
|
22
|
+
}
|
|
23
|
+
return this.internalStore;
|
|
24
|
+
}
|
|
25
|
+
append(pointer) {
|
|
26
|
+
if (!this.includes(pointer)) {
|
|
27
|
+
this.store.push(pointer);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
includes(pointer) {
|
|
31
|
+
return this.store.includes(pointer);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export default NormalizeStorage;
|
|
@@ -12,12 +12,17 @@ var _namespace = _interopRequireDefault(require("../namespace.cjs"));
|
|
|
12
12
|
* @public
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
15
18
|
const createToolbox = () => {
|
|
16
19
|
const namespace = new _apidomDatamodel.Namespace();
|
|
17
20
|
const predicates = {
|
|
18
21
|
...refractorPredicates,
|
|
19
22
|
...openApi2Predicates,
|
|
20
|
-
isStringElement: _apidomDatamodel.isStringElement
|
|
23
|
+
isStringElement: _apidomDatamodel.isStringElement,
|
|
24
|
+
isArrayElement: _apidomDatamodel.isArrayElement,
|
|
25
|
+
isObjectElement: _apidomDatamodel.isObjectElement
|
|
21
26
|
};
|
|
22
27
|
namespace.use(_namespace.default);
|
|
23
28
|
return {
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { isStringElement, Namespace } from '@speclynx/apidom-datamodel';
|
|
1
|
+
import { isStringElement, isArrayElement, isObjectElement, Namespace } from '@speclynx/apidom-datamodel';
|
|
2
2
|
import * as openApi2Predicates from "../predicates.mjs";
|
|
3
3
|
import * as refractorPredicates from "./predicates.mjs";
|
|
4
4
|
import openApi2Namespace from "../namespace.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
5
8
|
/**
|
|
6
9
|
* @public
|
|
7
10
|
*/
|
|
@@ -10,7 +13,9 @@ const createToolbox = () => {
|
|
|
10
13
|
const predicates = {
|
|
11
14
|
...refractorPredicates,
|
|
12
15
|
...openApi2Predicates,
|
|
13
|
-
isStringElement
|
|
16
|
+
isStringElement,
|
|
17
|
+
isArrayElement,
|
|
18
|
+
isObjectElement
|
|
14
19
|
};
|
|
15
20
|
namespace.use(openApi2Namespace);
|
|
16
21
|
return {
|
|
@@ -208,6 +208,11 @@ export declare class ContactVisitor extends BaseFixedFieldsVisitor {
|
|
|
208
208
|
constructor(options: BaseFixedFieldsVisitorOptions);
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
+
/**
|
|
212
|
+
* @public
|
|
213
|
+
*/
|
|
214
|
+
export declare const createToolbox: () => Toolbox;
|
|
215
|
+
|
|
211
216
|
/**
|
|
212
217
|
* @public
|
|
213
218
|
*/
|
|
@@ -1270,6 +1275,74 @@ export declare type RefractorPlugin = (toolbox: Toolbox) => {
|
|
|
1270
1275
|
post?: () => void;
|
|
1271
1276
|
};
|
|
1272
1277
|
|
|
1278
|
+
/**
|
|
1279
|
+
* @public
|
|
1280
|
+
*/
|
|
1281
|
+
export declare const refractorPluginNormalizeParameters: {
|
|
1282
|
+
({ storageField }?: RefractorPluginNormalizeParametersOptions): (toolbox: Toolbox) => {
|
|
1283
|
+
visitor: {
|
|
1284
|
+
SwaggerElement: {
|
|
1285
|
+
enter(path: Path<SwaggerElement>): void;
|
|
1286
|
+
leave(): void;
|
|
1287
|
+
};
|
|
1288
|
+
OperationElement: {
|
|
1289
|
+
leave(path: Path<OperationElement>): void;
|
|
1290
|
+
};
|
|
1291
|
+
};
|
|
1292
|
+
};
|
|
1293
|
+
inheritParametersToOperation: (operationElement: OperationElement, pathItemElement: PathItemElement) => void;
|
|
1294
|
+
};
|
|
1295
|
+
|
|
1296
|
+
/**
|
|
1297
|
+
* Inheritance of Parameter Objects.
|
|
1298
|
+
*
|
|
1299
|
+
* OpenAPI 2.0 specification excerpt that defines the inheritance behavior:
|
|
1300
|
+
*
|
|
1301
|
+
* A list of parameters that are applicable for all the operations described under this path.
|
|
1302
|
+
* These parameters can be overridden at the operation level, but cannot be removed there.
|
|
1303
|
+
* The list MUST NOT include duplicated parameters.
|
|
1304
|
+
* A unique parameter is defined by a combination of a name and location.
|
|
1305
|
+
*
|
|
1306
|
+
* NOTE: this plugin is idempotent
|
|
1307
|
+
* @public
|
|
1308
|
+
*/
|
|
1309
|
+
export declare interface RefractorPluginNormalizeParametersOptions {
|
|
1310
|
+
storageField?: string;
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
/**
|
|
1314
|
+
* @public
|
|
1315
|
+
*/
|
|
1316
|
+
export declare const refractorPluginNormalizeSecurityRequirements: {
|
|
1317
|
+
({ storageField }?: RefractorPluginNormalizeSecurityRequirementsOptions): (toolbox: Toolbox) => {
|
|
1318
|
+
visitor: {
|
|
1319
|
+
SwaggerElement: {
|
|
1320
|
+
enter(path: Path<SwaggerElement>): void;
|
|
1321
|
+
leave(): void;
|
|
1322
|
+
};
|
|
1323
|
+
OperationElement: {
|
|
1324
|
+
leave(path: Path<OperationElement>): void;
|
|
1325
|
+
};
|
|
1326
|
+
};
|
|
1327
|
+
};
|
|
1328
|
+
inheritSecurityToOperation: (operationElement: OperationElement, swaggerElement: SwaggerElement) => void;
|
|
1329
|
+
};
|
|
1330
|
+
|
|
1331
|
+
/**
|
|
1332
|
+
* Override of Security Requirement Objects.
|
|
1333
|
+
*
|
|
1334
|
+
* OpenAPI 2.0 specification excerpt that defines the override behavior:
|
|
1335
|
+
*
|
|
1336
|
+
* Operation.security definition overrides any declared top-level security.
|
|
1337
|
+
* To remove a top-level security declaration, an empty array can be used.
|
|
1338
|
+
*
|
|
1339
|
+
* NOTE: this plugin is idempotent
|
|
1340
|
+
* @public
|
|
1341
|
+
*/
|
|
1342
|
+
export declare interface RefractorPluginNormalizeSecurityRequirementsOptions {
|
|
1343
|
+
storageField?: string;
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1273
1346
|
/**
|
|
1274
1347
|
* @public
|
|
1275
1348
|
*/
|