@speclynx/apidom-ns-openapi-3-1 1.12.1
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 +87 -0
- package/LICENSE +202 -0
- package/LICENSES/AFL-3.0.txt +182 -0
- package/LICENSES/Apache-2.0.txt +202 -0
- package/LICENSES/BSD-3-Clause.txt +26 -0
- package/LICENSES/MIT.txt +9 -0
- package/NOTICE +65 -0
- package/README.md +472 -0
- package/dist/apidom-ns-openapi-3-1.browser.js +36144 -0
- package/dist/apidom-ns-openapi-3-1.browser.min.js +1 -0
- package/package.json +70 -0
- package/src/elements/Callback.cjs +10 -0
- package/src/elements/Callback.mjs +7 -0
- package/src/elements/Components.cjs +17 -0
- package/src/elements/Components.mjs +14 -0
- package/src/elements/Contact.cjs +10 -0
- package/src/elements/Contact.mjs +7 -0
- package/src/elements/Discriminator.cjs +10 -0
- package/src/elements/Discriminator.mjs +7 -0
- package/src/elements/Encoding.cjs +10 -0
- package/src/elements/Encoding.mjs +7 -0
- package/src/elements/Example.cjs +10 -0
- package/src/elements/Example.mjs +7 -0
- package/src/elements/ExternalDocumentation.cjs +10 -0
- package/src/elements/ExternalDocumentation.mjs +7 -0
- package/src/elements/Header.cjs +17 -0
- package/src/elements/Header.mjs +13 -0
- package/src/elements/Info.cjs +23 -0
- package/src/elements/Info.mjs +19 -0
- package/src/elements/JsonSchemaDialect.cjs +16 -0
- package/src/elements/JsonSchemaDialect.mjs +13 -0
- package/src/elements/License.cjs +17 -0
- package/src/elements/License.mjs +14 -0
- package/src/elements/Link.cjs +10 -0
- package/src/elements/Link.mjs +7 -0
- package/src/elements/MediaType.cjs +17 -0
- package/src/elements/MediaType.mjs +13 -0
- package/src/elements/OAuthFlow.cjs +10 -0
- package/src/elements/OAuthFlow.mjs +7 -0
- package/src/elements/OAuthFlows.cjs +10 -0
- package/src/elements/OAuthFlows.mjs +7 -0
- package/src/elements/OpenApi3-1.cjs +77 -0
- package/src/elements/OpenApi3-1.mjs +73 -0
- package/src/elements/Openapi.cjs +10 -0
- package/src/elements/Openapi.mjs +7 -0
- package/src/elements/Operation.cjs +17 -0
- package/src/elements/Operation.mjs +13 -0
- package/src/elements/Parameter.cjs +17 -0
- package/src/elements/Parameter.mjs +13 -0
- package/src/elements/PathItem.cjs +59 -0
- package/src/elements/PathItem.mjs +55 -0
- package/src/elements/Paths.cjs +10 -0
- package/src/elements/Paths.mjs +7 -0
- package/src/elements/Reference.cjs +28 -0
- package/src/elements/Reference.mjs +25 -0
- package/src/elements/RequestBody.cjs +10 -0
- package/src/elements/RequestBody.mjs +7 -0
- package/src/elements/Response.cjs +10 -0
- package/src/elements/Response.mjs +7 -0
- package/src/elements/Responses.cjs +10 -0
- package/src/elements/Responses.mjs +7 -0
- package/src/elements/Schema.cjs +50 -0
- package/src/elements/Schema.mjs +46 -0
- package/src/elements/SecurityRequirement.cjs +10 -0
- package/src/elements/SecurityRequirement.mjs +7 -0
- package/src/elements/SecurityScheme.cjs +10 -0
- package/src/elements/SecurityScheme.mjs +7 -0
- package/src/elements/Server.cjs +10 -0
- package/src/elements/Server.mjs +7 -0
- package/src/elements/ServerVariable.cjs +10 -0
- package/src/elements/ServerVariable.mjs +7 -0
- package/src/elements/Tag.cjs +10 -0
- package/src/elements/Tag.mjs +7 -0
- package/src/elements/Xml.cjs +10 -0
- package/src/elements/Xml.mjs +7 -0
- package/src/elements/nces/ComponentsPathItems.cjs +16 -0
- package/src/elements/nces/ComponentsPathItems.mjs +13 -0
- package/src/elements/nces/Webhooks.cjs +16 -0
- package/src/elements/nces/Webhooks.mjs +13 -0
- package/src/index.cjs +158 -0
- package/src/index.mjs +28 -0
- package/src/media-types.cjs +34 -0
- package/src/media-types.mjs +30 -0
- package/src/namespace.cjs +82 -0
- package/src/namespace.mjs +76 -0
- package/src/predicates.cjs +365 -0
- package/src/predicates.mjs +357 -0
- package/src/refractor/index.cjs +45 -0
- package/src/refractor/index.mjs +39 -0
- package/src/refractor/plugins/normalize-header-examples/NormalizeStorage.cjs +38 -0
- package/src/refractor/plugins/normalize-header-examples/NormalizeStorage.mjs +34 -0
- package/src/refractor/plugins/normalize-header-examples/index.cjs +105 -0
- package/src/refractor/plugins/normalize-header-examples/index.mjs +99 -0
- package/src/refractor/plugins/normalize-operation-ids.cjs +159 -0
- package/src/refractor/plugins/normalize-operation-ids.mjs +154 -0
- package/src/refractor/plugins/normalize-parameter-examples.cjs +105 -0
- package/src/refractor/plugins/normalize-parameter-examples.mjs +99 -0
- package/src/refractor/plugins/normalize-parameters.cjs +103 -0
- package/src/refractor/plugins/normalize-parameters.mjs +97 -0
- package/src/refractor/plugins/normalize-security-requirements.cjs +71 -0
- package/src/refractor/plugins/normalize-security-requirements.mjs +65 -0
- package/src/refractor/plugins/normalize-servers.cjs +118 -0
- package/src/refractor/plugins/normalize-servers.mjs +112 -0
- package/src/refractor/plugins/replace-empty-element.cjs +665 -0
- package/src/refractor/plugins/replace-empty-element.mjs +658 -0
- package/src/refractor/registration.cjs +102 -0
- package/src/refractor/registration.mjs +66 -0
- package/src/refractor/specification.cjs +492 -0
- package/src/refractor/specification.mjs +487 -0
- package/src/refractor/toolbox.cjs +70 -0
- package/src/refractor/toolbox.mjs +60 -0
- package/src/refractor/visitors/open-api-3-1/JsonSchemaDialectVisitor.cjs +25 -0
- package/src/refractor/visitors/open-api-3-1/JsonSchemaDialectVisitor.mjs +19 -0
- package/src/refractor/visitors/open-api-3-1/WebhooksVisitor.cjs +44 -0
- package/src/refractor/visitors/open-api-3-1/WebhooksVisitor.mjs +38 -0
- package/src/refractor/visitors/open-api-3-1/callback/index.cjs +37 -0
- package/src/refractor/visitors/open-api-3-1/callback/index.mjs +32 -0
- package/src/refractor/visitors/open-api-3-1/components/PathItemsVisitor.cjs +34 -0
- package/src/refractor/visitors/open-api-3-1/components/PathItemsVisitor.mjs +28 -0
- package/src/refractor/visitors/open-api-3-1/components/SchemasVisitor.cjs +22 -0
- package/src/refractor/visitors/open-api-3-1/components/SchemasVisitor.mjs +19 -0
- package/src/refractor/visitors/open-api-3-1/components/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/components/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/contact/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/contact/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/distriminator/index.cjs +22 -0
- package/src/refractor/visitors/open-api-3-1/distriminator/index.mjs +17 -0
- package/src/refractor/visitors/open-api-3-1/encoding/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/encoding/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/example/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/example/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/external-documentation/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/external-documentation/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/header/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/header/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/index.cjs +31 -0
- package/src/refractor/visitors/open-api-3-1/index.mjs +25 -0
- package/src/refractor/visitors/open-api-3-1/info/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/info/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/license/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/license/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/link/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/link/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/media-type/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/media-type/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/oauth-flow/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/oauth-flow/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/oauth-flows/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/oauth-flows/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/operation/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/operation/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/parameter/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/parameter/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/path-item/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/path-item/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/paths/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/paths/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/reference/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/reference/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/request-body/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/request-body/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/response/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/response/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/responses/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/responses/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/schema/$defsVisitor.cjs +19 -0
- package/src/refractor/visitors/open-api-3-1/schema/$defsVisitor.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/schema/AllOfVisitor.cjs +15 -0
- package/src/refractor/visitors/open-api-3-1/schema/AllOfVisitor.mjs +11 -0
- package/src/refractor/visitors/open-api-3-1/schema/AnyOfVisitor.cjs +15 -0
- package/src/refractor/visitors/open-api-3-1/schema/AnyOfVisitor.mjs +11 -0
- package/src/refractor/visitors/open-api-3-1/schema/DependentSchemasVisitor.cjs +15 -0
- package/src/refractor/visitors/open-api-3-1/schema/DependentSchemasVisitor.mjs +11 -0
- package/src/refractor/visitors/open-api-3-1/schema/OneOfVisitor.cjs +15 -0
- package/src/refractor/visitors/open-api-3-1/schema/OneOfVisitor.mjs +11 -0
- package/src/refractor/visitors/open-api-3-1/schema/PatternPropertiesVisitor.cjs +15 -0
- package/src/refractor/visitors/open-api-3-1/schema/PatternPropertiesVisitor.mjs +11 -0
- package/src/refractor/visitors/open-api-3-1/schema/PrefixItemsVisitor.cjs +15 -0
- package/src/refractor/visitors/open-api-3-1/schema/PrefixItemsVisitor.mjs +11 -0
- package/src/refractor/visitors/open-api-3-1/schema/PropertiesVisitor.cjs +15 -0
- package/src/refractor/visitors/open-api-3-1/schema/PropertiesVisitor.mjs +11 -0
- package/src/refractor/visitors/open-api-3-1/schema/index.cjs +75 -0
- package/src/refractor/visitors/open-api-3-1/schema/index.mjs +69 -0
- package/src/refractor/visitors/open-api-3-1/security-requirement/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/security-requirement/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/security-scheme/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/security-scheme/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/server/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/server/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/server-variable/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/server-variable/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/tag/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/tag/index.mjs +16 -0
- package/src/refractor/visitors/open-api-3-1/xml/index.cjs +21 -0
- package/src/refractor/visitors/open-api-3-1/xml/index.mjs +16 -0
- package/src/traversal/visitor.cjs +57 -0
- package/src/traversal/visitor.mjs +54 -0
- package/types/apidom-ns-openapi-3-1.d.ts +2745 -0
|
@@ -0,0 +1,103 @@
|
|
|
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 _apidomNsOpenapi = require("@speclynx/apidom-ns-openapi-3-0");
|
|
9
|
+
var _NormalizeStorage = _interopRequireDefault(require("./normalize-header-examples/NormalizeStorage.cjs"));
|
|
10
|
+
/**
|
|
11
|
+
* Inheritance of Parameter Objects.
|
|
12
|
+
*
|
|
13
|
+
* OpenAPI 3.1 specification excerpt that defines the inheritance behavior:
|
|
14
|
+
*
|
|
15
|
+
* A list of parameters that are applicable for this operation. If a parameter is already defined at the Path Item,
|
|
16
|
+
* the new definition will override it but can never remove it. The list MUST NOT include duplicated parameters.
|
|
17
|
+
* A unique parameter is defined by a combination of a name and location.
|
|
18
|
+
*
|
|
19
|
+
* NOTE: this plugin is idempotent
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
const plugin = ({
|
|
27
|
+
storageField = 'x-normalized'
|
|
28
|
+
} = {}) => toolbox => {
|
|
29
|
+
const {
|
|
30
|
+
predicates,
|
|
31
|
+
ancestorLineageToJSONPointer
|
|
32
|
+
} = toolbox;
|
|
33
|
+
/**
|
|
34
|
+
* Establishes identity between two Parameter Objects.
|
|
35
|
+
*
|
|
36
|
+
* {@link https://spec.openapis.org/oas/v3.1.2.html#operation-parameters}
|
|
37
|
+
*/
|
|
38
|
+
const parameterEquals = (parameter1, parameter2) => {
|
|
39
|
+
if (!predicates.isParameterElement(parameter1)) return false;
|
|
40
|
+
if (!predicates.isParameterElement(parameter2)) return false;
|
|
41
|
+
if (!predicates.isStringElement(parameter1.name)) return false;
|
|
42
|
+
if (!predicates.isStringElement(parameter1.in)) return false;
|
|
43
|
+
if (!predicates.isStringElement(parameter2.name)) return false;
|
|
44
|
+
if (!predicates.isStringElement(parameter2.in)) return false;
|
|
45
|
+
return (0, _apidomCore.toValue)(parameter1.name) === (0, _apidomCore.toValue)(parameter2.name) && (0, _apidomCore.toValue)(parameter1.in) === (0, _apidomCore.toValue)(parameter2.in);
|
|
46
|
+
};
|
|
47
|
+
const pathItemParameters = [];
|
|
48
|
+
let storage;
|
|
49
|
+
return {
|
|
50
|
+
visitor: {
|
|
51
|
+
OpenApi3_1Element: {
|
|
52
|
+
enter(element) {
|
|
53
|
+
storage = new _NormalizeStorage.default(element, storageField, 'parameters');
|
|
54
|
+
},
|
|
55
|
+
leave() {
|
|
56
|
+
storage = undefined;
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
PathItemElement: {
|
|
60
|
+
enter(pathItemElement, key, parent, path, ancestors) {
|
|
61
|
+
// skip visiting this Path Item
|
|
62
|
+
if (ancestors.some(predicates.isComponentsElement)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const {
|
|
66
|
+
parameters
|
|
67
|
+
} = pathItemElement;
|
|
68
|
+
if (predicates.isArrayElement(parameters)) {
|
|
69
|
+
pathItemParameters.push([...parameters.content]);
|
|
70
|
+
} else {
|
|
71
|
+
pathItemParameters.push([]);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
leave() {
|
|
75
|
+
pathItemParameters.pop();
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
OperationElement: {
|
|
79
|
+
leave(operationElement, key, parent, path, ancestors) {
|
|
80
|
+
const parentPathItemParameters = (0, _ramda.last)(pathItemParameters);
|
|
81
|
+
|
|
82
|
+
// no Path Item Object parameters to inherit from
|
|
83
|
+
if (!Array.isArray(parentPathItemParameters) || parentPathItemParameters.length === 0) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors, parent, operationElement]);
|
|
87
|
+
|
|
88
|
+
// skip visiting this Operation Object if it's already normalized
|
|
89
|
+
if (storage.includes(operationJSONPointer)) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const operationParameters = (0, _ramda.pathOr)([], ['parameters', 'content'], operationElement);
|
|
93
|
+
|
|
94
|
+
// prefers the first item if two items compare equal based on the predicate
|
|
95
|
+
const mergedParameters = (0, _ramda.uniqWith)(parameterEquals, [...operationParameters, ...parentPathItemParameters]);
|
|
96
|
+
operationElement.parameters = new _apidomNsOpenapi.OperationParametersElement(mergedParameters);
|
|
97
|
+
storage.append(operationJSONPointer);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
var _default = exports.default = plugin;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { uniqWith, pathOr, last } from 'ramda';
|
|
2
|
+
import { toValue } from '@speclynx/apidom-core';
|
|
3
|
+
import { OperationParametersElement } from '@speclynx/apidom-ns-openapi-3-0';
|
|
4
|
+
import NormalizeStorage from "./normalize-header-examples/NormalizeStorage.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* Inheritance of Parameter Objects.
|
|
7
|
+
*
|
|
8
|
+
* OpenAPI 3.1 specification excerpt that defines the inheritance behavior:
|
|
9
|
+
*
|
|
10
|
+
* A list of parameters that are applicable for this operation. If a parameter is already defined at the Path Item,
|
|
11
|
+
* the new definition will override it but can never remove it. The list MUST NOT include duplicated parameters.
|
|
12
|
+
* A unique parameter is defined by a combination of a name and location.
|
|
13
|
+
*
|
|
14
|
+
* NOTE: this plugin is idempotent
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
const plugin = ({
|
|
21
|
+
storageField = 'x-normalized'
|
|
22
|
+
} = {}) => toolbox => {
|
|
23
|
+
const {
|
|
24
|
+
predicates,
|
|
25
|
+
ancestorLineageToJSONPointer
|
|
26
|
+
} = toolbox;
|
|
27
|
+
/**
|
|
28
|
+
* Establishes identity between two Parameter Objects.
|
|
29
|
+
*
|
|
30
|
+
* {@link https://spec.openapis.org/oas/v3.1.2.html#operation-parameters}
|
|
31
|
+
*/
|
|
32
|
+
const parameterEquals = (parameter1, parameter2) => {
|
|
33
|
+
if (!predicates.isParameterElement(parameter1)) return false;
|
|
34
|
+
if (!predicates.isParameterElement(parameter2)) return false;
|
|
35
|
+
if (!predicates.isStringElement(parameter1.name)) return false;
|
|
36
|
+
if (!predicates.isStringElement(parameter1.in)) return false;
|
|
37
|
+
if (!predicates.isStringElement(parameter2.name)) return false;
|
|
38
|
+
if (!predicates.isStringElement(parameter2.in)) return false;
|
|
39
|
+
return toValue(parameter1.name) === toValue(parameter2.name) && toValue(parameter1.in) === toValue(parameter2.in);
|
|
40
|
+
};
|
|
41
|
+
const pathItemParameters = [];
|
|
42
|
+
let storage;
|
|
43
|
+
return {
|
|
44
|
+
visitor: {
|
|
45
|
+
OpenApi3_1Element: {
|
|
46
|
+
enter(element) {
|
|
47
|
+
storage = new NormalizeStorage(element, storageField, 'parameters');
|
|
48
|
+
},
|
|
49
|
+
leave() {
|
|
50
|
+
storage = undefined;
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
PathItemElement: {
|
|
54
|
+
enter(pathItemElement, key, parent, path, ancestors) {
|
|
55
|
+
// skip visiting this Path Item
|
|
56
|
+
if (ancestors.some(predicates.isComponentsElement)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const {
|
|
60
|
+
parameters
|
|
61
|
+
} = pathItemElement;
|
|
62
|
+
if (predicates.isArrayElement(parameters)) {
|
|
63
|
+
pathItemParameters.push([...parameters.content]);
|
|
64
|
+
} else {
|
|
65
|
+
pathItemParameters.push([]);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
leave() {
|
|
69
|
+
pathItemParameters.pop();
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
OperationElement: {
|
|
73
|
+
leave(operationElement, key, parent, path, ancestors) {
|
|
74
|
+
const parentPathItemParameters = last(pathItemParameters);
|
|
75
|
+
|
|
76
|
+
// no Path Item Object parameters to inherit from
|
|
77
|
+
if (!Array.isArray(parentPathItemParameters) || parentPathItemParameters.length === 0) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors, parent, operationElement]);
|
|
81
|
+
|
|
82
|
+
// skip visiting this Operation Object if it's already normalized
|
|
83
|
+
if (storage.includes(operationJSONPointer)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const operationParameters = pathOr([], ['parameters', 'content'], operationElement);
|
|
87
|
+
|
|
88
|
+
// prefers the first item if two items compare equal based on the predicate
|
|
89
|
+
const mergedParameters = uniqWith(parameterEquals, [...operationParameters, ...parentPathItemParameters]);
|
|
90
|
+
operationElement.parameters = new OperationParametersElement(mergedParameters);
|
|
91
|
+
storage.append(operationJSONPointer);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
export default plugin;
|
|
@@ -0,0 +1,71 @@
|
|
|
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 _apidomNsOpenapi = require("@speclynx/apidom-ns-openapi-3-0");
|
|
7
|
+
var _NormalizeStorage = _interopRequireDefault(require("./normalize-header-examples/NormalizeStorage.cjs"));
|
|
8
|
+
/**
|
|
9
|
+
* Override of Security Requirement Objects.
|
|
10
|
+
*
|
|
11
|
+
* OpenAPI 3.1 specification excerpt that defines the override behavior:
|
|
12
|
+
*
|
|
13
|
+
* Operation.security definition overrides any declared top-level security.
|
|
14
|
+
* To remove a top-level security declaration, an empty array can be used.
|
|
15
|
+
* When a list of Security Requirement Objects is defined on the OpenAPI Object or Operation Object,
|
|
16
|
+
* only one of the Security Requirement Objects in the list needs to be satisfied to authorize the request.
|
|
17
|
+
*
|
|
18
|
+
* NOTE: this plugin is idempotent
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
const plugin = ({
|
|
26
|
+
storageField = 'x-normalized'
|
|
27
|
+
} = {}) => toolbox => {
|
|
28
|
+
const {
|
|
29
|
+
predicates,
|
|
30
|
+
ancestorLineageToJSONPointer
|
|
31
|
+
} = toolbox;
|
|
32
|
+
let topLevelSecurity;
|
|
33
|
+
let storage;
|
|
34
|
+
return {
|
|
35
|
+
visitor: {
|
|
36
|
+
OpenApi3_1Element: {
|
|
37
|
+
enter(openapiElement) {
|
|
38
|
+
storage = new _NormalizeStorage.default(openapiElement, storageField, 'security-requirements');
|
|
39
|
+
if (predicates.isArrayElement(openapiElement.security)) {
|
|
40
|
+
topLevelSecurity = openapiElement.security;
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
leave() {
|
|
44
|
+
storage = undefined;
|
|
45
|
+
topLevelSecurity = undefined;
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
OperationElement: {
|
|
49
|
+
leave(operationElement, key, parent, path, ancestors) {
|
|
50
|
+
// skip visiting this Operation
|
|
51
|
+
if (ancestors.some(predicates.isComponentsElement)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors, parent, operationElement]);
|
|
55
|
+
|
|
56
|
+
// skip visiting this Operation Object if it's already normalized
|
|
57
|
+
if (storage.includes(operationJSONPointer)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const missingOperationLevelSecurity = typeof operationElement.security === 'undefined';
|
|
61
|
+
const hasTopLevelSecurity = typeof topLevelSecurity !== 'undefined';
|
|
62
|
+
if (missingOperationLevelSecurity && hasTopLevelSecurity) {
|
|
63
|
+
operationElement.security = new _apidomNsOpenapi.OperationSecurityElement(topLevelSecurity?.content);
|
|
64
|
+
storage.append(operationJSONPointer);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
var _default = exports.default = plugin;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { OperationSecurityElement } from '@speclynx/apidom-ns-openapi-3-0';
|
|
2
|
+
import NormalizeStorage from "./normalize-header-examples/NormalizeStorage.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Override of Security Requirement Objects.
|
|
5
|
+
*
|
|
6
|
+
* OpenAPI 3.1 specification excerpt that defines the override behavior:
|
|
7
|
+
*
|
|
8
|
+
* Operation.security definition overrides any declared top-level security.
|
|
9
|
+
* To remove a top-level security declaration, an empty array can be used.
|
|
10
|
+
* When a list of Security Requirement Objects is defined on the OpenAPI Object or Operation Object,
|
|
11
|
+
* only one of the Security Requirement Objects in the list needs to be satisfied to authorize the request.
|
|
12
|
+
*
|
|
13
|
+
* NOTE: this plugin is idempotent
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
const plugin = ({
|
|
20
|
+
storageField = 'x-normalized'
|
|
21
|
+
} = {}) => toolbox => {
|
|
22
|
+
const {
|
|
23
|
+
predicates,
|
|
24
|
+
ancestorLineageToJSONPointer
|
|
25
|
+
} = toolbox;
|
|
26
|
+
let topLevelSecurity;
|
|
27
|
+
let storage;
|
|
28
|
+
return {
|
|
29
|
+
visitor: {
|
|
30
|
+
OpenApi3_1Element: {
|
|
31
|
+
enter(openapiElement) {
|
|
32
|
+
storage = new NormalizeStorage(openapiElement, storageField, 'security-requirements');
|
|
33
|
+
if (predicates.isArrayElement(openapiElement.security)) {
|
|
34
|
+
topLevelSecurity = openapiElement.security;
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
leave() {
|
|
38
|
+
storage = undefined;
|
|
39
|
+
topLevelSecurity = undefined;
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
OperationElement: {
|
|
43
|
+
leave(operationElement, key, parent, path, ancestors) {
|
|
44
|
+
// skip visiting this Operation
|
|
45
|
+
if (ancestors.some(predicates.isComponentsElement)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors, parent, operationElement]);
|
|
49
|
+
|
|
50
|
+
// skip visiting this Operation Object if it's already normalized
|
|
51
|
+
if (storage.includes(operationJSONPointer)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const missingOperationLevelSecurity = typeof operationElement.security === 'undefined';
|
|
55
|
+
const hasTopLevelSecurity = typeof topLevelSecurity !== 'undefined';
|
|
56
|
+
if (missingOperationLevelSecurity && hasTopLevelSecurity) {
|
|
57
|
+
operationElement.security = new OperationSecurityElement(topLevelSecurity?.content);
|
|
58
|
+
storage.append(operationJSONPointer);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
export default plugin;
|
|
@@ -0,0 +1,118 @@
|
|
|
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 _apidomNsOpenapi = require("@speclynx/apidom-ns-openapi-3-0");
|
|
7
|
+
var _NormalizeStorage = _interopRequireDefault(require("./normalize-header-examples/NormalizeStorage.cjs"));
|
|
8
|
+
/**
|
|
9
|
+
* Override of Server Objects.
|
|
10
|
+
*
|
|
11
|
+
* List of Server Objects can be defined in OpenAPI 3.1 on multiple levels:
|
|
12
|
+
*
|
|
13
|
+
* - OpenAPI.servers
|
|
14
|
+
* - PathItem.servers
|
|
15
|
+
* - Operation.servers
|
|
16
|
+
*
|
|
17
|
+
* If a servers array is specified at the OpenAPI Object level, it will be overridden by `PathItem`.servers.
|
|
18
|
+
* If a servers array is specified at the Path Item Object or OpenAPI Object level, it will be overridden by Operation.servers.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
const plugin = ({
|
|
26
|
+
storageField = 'x-normalized'
|
|
27
|
+
} = {}) => toolbox => {
|
|
28
|
+
const {
|
|
29
|
+
namespace,
|
|
30
|
+
ancestorLineageToJSONPointer,
|
|
31
|
+
predicates
|
|
32
|
+
} = toolbox;
|
|
33
|
+
let storage;
|
|
34
|
+
return {
|
|
35
|
+
visitor: {
|
|
36
|
+
OpenApi3_1Element: {
|
|
37
|
+
enter(openapiElement) {
|
|
38
|
+
const isServersUndefined = typeof openapiElement.servers === 'undefined';
|
|
39
|
+
const isServersArrayElement = predicates.isArrayElement(openapiElement.servers);
|
|
40
|
+
const isServersEmpty = isServersArrayElement && openapiElement.servers.length === 0;
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
const defaultServer = namespace.elements.Server.refract({
|
|
43
|
+
url: '/'
|
|
44
|
+
});
|
|
45
|
+
if (isServersUndefined || !isServersArrayElement) {
|
|
46
|
+
openapiElement.servers = new _apidomNsOpenapi.ServersElement([defaultServer]);
|
|
47
|
+
} else if (isServersArrayElement && isServersEmpty) {
|
|
48
|
+
openapiElement.servers.push(defaultServer);
|
|
49
|
+
}
|
|
50
|
+
storage = new _NormalizeStorage.default(openapiElement, storageField, 'servers');
|
|
51
|
+
},
|
|
52
|
+
leave() {
|
|
53
|
+
storage = undefined;
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
PathItemElement(pathItemElement, key, parent, path, ancestors) {
|
|
57
|
+
// skip visiting this Path Item
|
|
58
|
+
if (ancestors.some(predicates.isComponentsElement)) return;
|
|
59
|
+
if (!ancestors.some(predicates.isOpenApi3_1Element)) return;
|
|
60
|
+
const pathItemJSONPointer = ancestorLineageToJSONPointer([...ancestors, parent, pathItemElement]);
|
|
61
|
+
|
|
62
|
+
// skip visiting this Path Item Object if it's already normalized
|
|
63
|
+
if (storage.includes(pathItemJSONPointer)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const parentOpenapiElement = ancestors.find(predicates.isOpenApi3_1Element);
|
|
67
|
+
const isServersUndefined = typeof pathItemElement.servers === 'undefined';
|
|
68
|
+
const isServersArrayElement = predicates.isArrayElement(pathItemElement.servers);
|
|
69
|
+
const isServersEmpty = isServersArrayElement && pathItemElement.servers.length === 0;
|
|
70
|
+
|
|
71
|
+
// duplicate OpenAPI.servers into this Path Item object
|
|
72
|
+
if (predicates.isOpenApi3_1Element(parentOpenapiElement)) {
|
|
73
|
+
const openapiServersContent = parentOpenapiElement.servers?.content;
|
|
74
|
+
const openapiServers = openapiServersContent ?? [];
|
|
75
|
+
if (isServersUndefined || !isServersArrayElement) {
|
|
76
|
+
pathItemElement.servers = new _apidomNsOpenapi.PathItemServersElement(openapiServers);
|
|
77
|
+
} else if (isServersArrayElement && isServersEmpty) {
|
|
78
|
+
openapiServers.forEach(server => {
|
|
79
|
+
pathItemElement.servers.push(server);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
storage.append(pathItemJSONPointer);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
OperationElement(operationElement, key, parent, path, ancestors) {
|
|
86
|
+
// skip visiting this Operation
|
|
87
|
+
if (ancestors.some(predicates.isComponentsElement)) return;
|
|
88
|
+
if (!ancestors.some(predicates.isOpenApi3_1Element)) return;
|
|
89
|
+
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors, parent, operationElement]);
|
|
90
|
+
|
|
91
|
+
// skip visiting this Operation Object if it's already normalized
|
|
92
|
+
if (storage.includes(operationJSONPointer)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// @TODO(vladimir.gorej@gmail.com): can be replaced by Array.prototype.findLast in future
|
|
97
|
+
const parentPathItemElement = [...ancestors].reverse().find(predicates.isPathItemElement);
|
|
98
|
+
const isServersUndefined = typeof operationElement.servers === 'undefined';
|
|
99
|
+
const isServersArrayElement = predicates.isArrayElement(operationElement.servers);
|
|
100
|
+
const isServersEmpty = isServersArrayElement && operationElement.servers.length === 0;
|
|
101
|
+
if (predicates.isPathItemElement(parentPathItemElement)) {
|
|
102
|
+
const pathItemServersContent = parentPathItemElement.servers?.content;
|
|
103
|
+
const pathItemServers = pathItemServersContent ?? [];
|
|
104
|
+
if (isServersUndefined || !isServersArrayElement) {
|
|
105
|
+
// duplicate parent PathItem.servers into this Operation object
|
|
106
|
+
operationElement.servers = new _apidomNsOpenapi.OperationServersElement(pathItemServers);
|
|
107
|
+
} else if (isServersArrayElement && isServersEmpty) {
|
|
108
|
+
pathItemServers.forEach(server => {
|
|
109
|
+
operationElement.servers.push(server);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
storage.append(operationJSONPointer);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
var _default = exports.default = plugin;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { PathItemServersElement, OperationServersElement, ServersElement } from '@speclynx/apidom-ns-openapi-3-0';
|
|
2
|
+
import NormalizeStorage from "./normalize-header-examples/NormalizeStorage.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Override of Server Objects.
|
|
5
|
+
*
|
|
6
|
+
* List of Server Objects can be defined in OpenAPI 3.1 on multiple levels:
|
|
7
|
+
*
|
|
8
|
+
* - OpenAPI.servers
|
|
9
|
+
* - PathItem.servers
|
|
10
|
+
* - Operation.servers
|
|
11
|
+
*
|
|
12
|
+
* If a servers array is specified at the OpenAPI Object level, it will be overridden by `PathItem`.servers.
|
|
13
|
+
* If a servers array is specified at the Path Item Object or OpenAPI Object level, it will be overridden by Operation.servers.
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
const plugin = ({
|
|
20
|
+
storageField = 'x-normalized'
|
|
21
|
+
} = {}) => toolbox => {
|
|
22
|
+
const {
|
|
23
|
+
namespace,
|
|
24
|
+
ancestorLineageToJSONPointer,
|
|
25
|
+
predicates
|
|
26
|
+
} = toolbox;
|
|
27
|
+
let storage;
|
|
28
|
+
return {
|
|
29
|
+
visitor: {
|
|
30
|
+
OpenApi3_1Element: {
|
|
31
|
+
enter(openapiElement) {
|
|
32
|
+
const isServersUndefined = typeof openapiElement.servers === 'undefined';
|
|
33
|
+
const isServersArrayElement = predicates.isArrayElement(openapiElement.servers);
|
|
34
|
+
const isServersEmpty = isServersArrayElement && openapiElement.servers.length === 0;
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
const defaultServer = namespace.elements.Server.refract({
|
|
37
|
+
url: '/'
|
|
38
|
+
});
|
|
39
|
+
if (isServersUndefined || !isServersArrayElement) {
|
|
40
|
+
openapiElement.servers = new ServersElement([defaultServer]);
|
|
41
|
+
} else if (isServersArrayElement && isServersEmpty) {
|
|
42
|
+
openapiElement.servers.push(defaultServer);
|
|
43
|
+
}
|
|
44
|
+
storage = new NormalizeStorage(openapiElement, storageField, 'servers');
|
|
45
|
+
},
|
|
46
|
+
leave() {
|
|
47
|
+
storage = undefined;
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
PathItemElement(pathItemElement, key, parent, path, ancestors) {
|
|
51
|
+
// skip visiting this Path Item
|
|
52
|
+
if (ancestors.some(predicates.isComponentsElement)) return;
|
|
53
|
+
if (!ancestors.some(predicates.isOpenApi3_1Element)) return;
|
|
54
|
+
const pathItemJSONPointer = ancestorLineageToJSONPointer([...ancestors, parent, pathItemElement]);
|
|
55
|
+
|
|
56
|
+
// skip visiting this Path Item Object if it's already normalized
|
|
57
|
+
if (storage.includes(pathItemJSONPointer)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const parentOpenapiElement = ancestors.find(predicates.isOpenApi3_1Element);
|
|
61
|
+
const isServersUndefined = typeof pathItemElement.servers === 'undefined';
|
|
62
|
+
const isServersArrayElement = predicates.isArrayElement(pathItemElement.servers);
|
|
63
|
+
const isServersEmpty = isServersArrayElement && pathItemElement.servers.length === 0;
|
|
64
|
+
|
|
65
|
+
// duplicate OpenAPI.servers into this Path Item object
|
|
66
|
+
if (predicates.isOpenApi3_1Element(parentOpenapiElement)) {
|
|
67
|
+
const openapiServersContent = parentOpenapiElement.servers?.content;
|
|
68
|
+
const openapiServers = openapiServersContent ?? [];
|
|
69
|
+
if (isServersUndefined || !isServersArrayElement) {
|
|
70
|
+
pathItemElement.servers = new PathItemServersElement(openapiServers);
|
|
71
|
+
} else if (isServersArrayElement && isServersEmpty) {
|
|
72
|
+
openapiServers.forEach(server => {
|
|
73
|
+
pathItemElement.servers.push(server);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
storage.append(pathItemJSONPointer);
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
OperationElement(operationElement, key, parent, path, ancestors) {
|
|
80
|
+
// skip visiting this Operation
|
|
81
|
+
if (ancestors.some(predicates.isComponentsElement)) return;
|
|
82
|
+
if (!ancestors.some(predicates.isOpenApi3_1Element)) return;
|
|
83
|
+
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors, parent, operationElement]);
|
|
84
|
+
|
|
85
|
+
// skip visiting this Operation Object if it's already normalized
|
|
86
|
+
if (storage.includes(operationJSONPointer)) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// @TODO(vladimir.gorej@gmail.com): can be replaced by Array.prototype.findLast in future
|
|
91
|
+
const parentPathItemElement = [...ancestors].reverse().find(predicates.isPathItemElement);
|
|
92
|
+
const isServersUndefined = typeof operationElement.servers === 'undefined';
|
|
93
|
+
const isServersArrayElement = predicates.isArrayElement(operationElement.servers);
|
|
94
|
+
const isServersEmpty = isServersArrayElement && operationElement.servers.length === 0;
|
|
95
|
+
if (predicates.isPathItemElement(parentPathItemElement)) {
|
|
96
|
+
const pathItemServersContent = parentPathItemElement.servers?.content;
|
|
97
|
+
const pathItemServers = pathItemServersContent ?? [];
|
|
98
|
+
if (isServersUndefined || !isServersArrayElement) {
|
|
99
|
+
// duplicate parent PathItem.servers into this Operation object
|
|
100
|
+
operationElement.servers = new OperationServersElement(pathItemServers);
|
|
101
|
+
} else if (isServersArrayElement && isServersEmpty) {
|
|
102
|
+
pathItemServers.forEach(server => {
|
|
103
|
+
operationElement.servers.push(server);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
storage.append(operationJSONPointer);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
export default plugin;
|