@speclynx/apidom-ns-openapi-3-1 4.0.5 → 4.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 +6 -0
- package/dist/apidom-ns-openapi-3-1.browser.js +215 -252
- package/dist/apidom-ns-openapi-3-1.browser.min.js +1 -1
- package/package.json +8 -8
- package/src/index.cjs +35 -35
- package/src/index.mjs +1 -1
- package/src/refractor/plugins/{normalize-header-examples/index.cjs → normalize-header-examples.cjs} +4 -5
- package/src/refractor/plugins/{normalize-header-examples/index.mjs → normalize-header-examples.mjs} +3 -4
- package/src/refractor/plugins/normalize-operation-ids.cjs +3 -5
- package/src/refractor/plugins/normalize-operation-ids.mjs +2 -4
- package/src/refractor/plugins/normalize-parameter-examples.cjs +4 -5
- package/src/refractor/plugins/normalize-parameter-examples.mjs +3 -4
- package/src/refractor/plugins/normalize-parameters.cjs +48 -50
- package/src/refractor/plugins/normalize-parameters.mjs +48 -50
- package/src/refractor/plugins/normalize-security-requirements.cjs +20 -6
- package/src/refractor/plugins/normalize-security-requirements.mjs +19 -5
- package/src/refractor/plugins/normalize-servers.cjs +69 -46
- package/src/refractor/plugins/normalize-servers.mjs +67 -44
- package/src/refractor/plugins/{normalize-header-examples/NormalizeStorage.cjs → normalize-storage/index.cjs} +1 -1
- package/src/refractor/plugins/{normalize-header-examples/NormalizeStorage.mjs → normalize-storage/index.mjs} +1 -1
- package/src/refractor/toolbox.cjs +1 -29
- package/src/refractor/toolbox.mjs +1 -28
- package/types/apidom-ns-openapi-3-1.d.ts +34 -39
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
4
|
exports.__esModule = true;
|
|
5
5
|
exports.default = void 0;
|
|
6
|
+
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
6
7
|
var _apidomNsOpenapi = require("@speclynx/apidom-ns-openapi-3-0");
|
|
7
|
-
var
|
|
8
|
+
var _index = _interopRequireDefault(require("./normalize-storage/index.cjs"));
|
|
8
9
|
/**
|
|
9
10
|
* Override of Security Requirement Objects.
|
|
10
11
|
*
|
|
@@ -19,6 +20,19 @@ var _NormalizeStorage = _interopRequireDefault(require("./normalize-header-examp
|
|
|
19
20
|
* @public
|
|
20
21
|
*/
|
|
21
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Inherits top-level security requirements into an Operation element.
|
|
25
|
+
* If Operation.security is missing and OpenAPI.security is defined, copies it down.
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
const inheritSecurityToOperation = (operationElement, openapiElement) => {
|
|
29
|
+
const missingOperationLevelSecurity = typeof operationElement.security === 'undefined';
|
|
30
|
+
const hasTopLevelSecurity = (0, _apidomDatamodel.isArrayElement)(openapiElement.security);
|
|
31
|
+
if (missingOperationLevelSecurity && hasTopLevelSecurity) {
|
|
32
|
+
operationElement.security = new _apidomNsOpenapi.OperationSecurityElement([...openapiElement.security]);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
22
36
|
/**
|
|
23
37
|
* @public
|
|
24
38
|
*/
|
|
@@ -26,8 +40,7 @@ const plugin = ({
|
|
|
26
40
|
storageField = 'x-normalized'
|
|
27
41
|
} = {}) => toolbox => {
|
|
28
42
|
const {
|
|
29
|
-
predicates
|
|
30
|
-
ancestorLineageToJSONPointer
|
|
43
|
+
predicates
|
|
31
44
|
} = toolbox;
|
|
32
45
|
let topLevelSecurity;
|
|
33
46
|
let storage;
|
|
@@ -36,7 +49,7 @@ const plugin = ({
|
|
|
36
49
|
OpenApi3_1Element: {
|
|
37
50
|
enter(path) {
|
|
38
51
|
const openapiElement = path.node;
|
|
39
|
-
storage = new
|
|
52
|
+
storage = new _index.default(openapiElement, storageField, 'security-requirements');
|
|
40
53
|
if (predicates.isArrayElement(openapiElement.security)) {
|
|
41
54
|
topLevelSecurity = openapiElement.security;
|
|
42
55
|
}
|
|
@@ -55,7 +68,7 @@ const plugin = ({
|
|
|
55
68
|
if (ancestors.some(predicates.isComponentsElement)) {
|
|
56
69
|
return;
|
|
57
70
|
}
|
|
58
|
-
const operationJSONPointer =
|
|
71
|
+
const operationJSONPointer = path.formatPath();
|
|
59
72
|
|
|
60
73
|
// skip visiting this Operation Object if it's already normalized
|
|
61
74
|
if (storage.includes(operationJSONPointer)) {
|
|
@@ -64,7 +77,7 @@ const plugin = ({
|
|
|
64
77
|
const missingOperationLevelSecurity = typeof operationElement.security === 'undefined';
|
|
65
78
|
const hasTopLevelSecurity = typeof topLevelSecurity !== 'undefined';
|
|
66
79
|
if (missingOperationLevelSecurity && hasTopLevelSecurity) {
|
|
67
|
-
operationElement.security = new _apidomNsOpenapi.OperationSecurityElement(topLevelSecurity
|
|
80
|
+
operationElement.security = new _apidomNsOpenapi.OperationSecurityElement([...topLevelSecurity]);
|
|
68
81
|
storage.append(operationJSONPointer);
|
|
69
82
|
}
|
|
70
83
|
}
|
|
@@ -72,4 +85,5 @@ const plugin = ({
|
|
|
72
85
|
}
|
|
73
86
|
};
|
|
74
87
|
};
|
|
88
|
+
plugin.inheritSecurityToOperation = inheritSecurityToOperation;
|
|
75
89
|
var _default = exports.default = plugin;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { isArrayElement } from '@speclynx/apidom-datamodel';
|
|
1
2
|
import { OperationSecurityElement } from '@speclynx/apidom-ns-openapi-3-0';
|
|
2
|
-
import NormalizeStorage from "./normalize-
|
|
3
|
+
import NormalizeStorage from "./normalize-storage/index.mjs";
|
|
3
4
|
/**
|
|
4
5
|
* Override of Security Requirement Objects.
|
|
5
6
|
*
|
|
@@ -13,6 +14,19 @@ import NormalizeStorage from "./normalize-header-examples/NormalizeStorage.mjs";
|
|
|
13
14
|
* NOTE: this plugin is idempotent
|
|
14
15
|
* @public
|
|
15
16
|
*/
|
|
17
|
+
/**
|
|
18
|
+
* Inherits top-level security requirements into an Operation element.
|
|
19
|
+
* If Operation.security is missing and OpenAPI.security is defined, copies it down.
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
const inheritSecurityToOperation = (operationElement, openapiElement) => {
|
|
23
|
+
const missingOperationLevelSecurity = typeof operationElement.security === 'undefined';
|
|
24
|
+
const hasTopLevelSecurity = isArrayElement(openapiElement.security);
|
|
25
|
+
if (missingOperationLevelSecurity && hasTopLevelSecurity) {
|
|
26
|
+
operationElement.security = new OperationSecurityElement([...openapiElement.security]);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
16
30
|
/**
|
|
17
31
|
* @public
|
|
18
32
|
*/
|
|
@@ -20,8 +34,7 @@ const plugin = ({
|
|
|
20
34
|
storageField = 'x-normalized'
|
|
21
35
|
} = {}) => toolbox => {
|
|
22
36
|
const {
|
|
23
|
-
predicates
|
|
24
|
-
ancestorLineageToJSONPointer
|
|
37
|
+
predicates
|
|
25
38
|
} = toolbox;
|
|
26
39
|
let topLevelSecurity;
|
|
27
40
|
let storage;
|
|
@@ -49,7 +62,7 @@ const plugin = ({
|
|
|
49
62
|
if (ancestors.some(predicates.isComponentsElement)) {
|
|
50
63
|
return;
|
|
51
64
|
}
|
|
52
|
-
const operationJSONPointer =
|
|
65
|
+
const operationJSONPointer = path.formatPath();
|
|
53
66
|
|
|
54
67
|
// skip visiting this Operation Object if it's already normalized
|
|
55
68
|
if (storage.includes(operationJSONPointer)) {
|
|
@@ -58,7 +71,7 @@ const plugin = ({
|
|
|
58
71
|
const missingOperationLevelSecurity = typeof operationElement.security === 'undefined';
|
|
59
72
|
const hasTopLevelSecurity = typeof topLevelSecurity !== 'undefined';
|
|
60
73
|
if (missingOperationLevelSecurity && hasTopLevelSecurity) {
|
|
61
|
-
operationElement.security = new OperationSecurityElement(topLevelSecurity
|
|
74
|
+
operationElement.security = new OperationSecurityElement([...topLevelSecurity]);
|
|
62
75
|
storage.append(operationJSONPointer);
|
|
63
76
|
}
|
|
64
77
|
}
|
|
@@ -66,4 +79,5 @@ const plugin = ({
|
|
|
66
79
|
}
|
|
67
80
|
};
|
|
68
81
|
};
|
|
82
|
+
plugin.inheritSecurityToOperation = inheritSecurityToOperation;
|
|
69
83
|
export default plugin;
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
4
|
exports.__esModule = true;
|
|
5
5
|
exports.default = void 0;
|
|
6
|
+
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
6
7
|
var _apidomNsOpenapi = require("@speclynx/apidom-ns-openapi-3-0");
|
|
7
|
-
var
|
|
8
|
-
var
|
|
8
|
+
var _index = _interopRequireDefault(require("./normalize-storage/index.cjs"));
|
|
9
|
+
var _index2 = require("../index.cjs");
|
|
9
10
|
/**
|
|
10
11
|
* Override of Server Objects.
|
|
11
12
|
*
|
|
@@ -20,6 +21,63 @@ var _index = require("../index.cjs");
|
|
|
20
21
|
* @public
|
|
21
22
|
*/
|
|
22
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Ensures the OpenAPI document has at least one server defined.
|
|
26
|
+
* If `servers` is missing or empty, adds a default server with `url: "/"`.
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
const ensureDefaultServer = openapiElement => {
|
|
30
|
+
const isServersUndefined = typeof openapiElement.servers === 'undefined';
|
|
31
|
+
const isServersArray = (0, _apidomDatamodel.isArrayElement)(openapiElement.servers);
|
|
32
|
+
const isServersEmpty = isServersArray && openapiElement.servers.length === 0;
|
|
33
|
+
const defaultServer = (0, _index2.refractServer)({
|
|
34
|
+
url: '/'
|
|
35
|
+
});
|
|
36
|
+
if (isServersUndefined || !isServersArray) {
|
|
37
|
+
openapiElement.servers = new _apidomNsOpenapi.ServersElement([defaultServer]);
|
|
38
|
+
} else if (isServersArray && isServersEmpty) {
|
|
39
|
+
openapiElement.servers.push(defaultServer);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Inherits servers from the OpenAPI root into a PathItem element.
|
|
45
|
+
* If PathItem.servers is missing or empty, copies from OpenAPI.servers.
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
const inheritServersToPathItem = (pathItemElement, openapiElement) => {
|
|
49
|
+
const isServersUndefined = typeof pathItemElement.servers === 'undefined';
|
|
50
|
+
const isServersArray = (0, _apidomDatamodel.isArrayElement)(pathItemElement.servers);
|
|
51
|
+
const isServersEmpty = isServersArray && pathItemElement.servers.length === 0;
|
|
52
|
+
const openapiServers = [...(openapiElement.servers ?? [])];
|
|
53
|
+
if (isServersUndefined || !isServersArray) {
|
|
54
|
+
pathItemElement.servers = new _apidomNsOpenapi.PathItemServersElement(openapiServers);
|
|
55
|
+
} else if (isServersArray && isServersEmpty) {
|
|
56
|
+
openapiServers.forEach(server => {
|
|
57
|
+
pathItemElement.servers.push(server);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Inherits servers from a PathItem into an Operation element.
|
|
64
|
+
* If Operation.servers is missing or empty, copies from PathItem.servers.
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
67
|
+
const inheritServersToOperation = (operationElement, pathItemElement) => {
|
|
68
|
+
const isServersUndefined = typeof operationElement.servers === 'undefined';
|
|
69
|
+
const isServersArray = (0, _apidomDatamodel.isArrayElement)(operationElement.servers);
|
|
70
|
+
const isServersEmpty = isServersArray && operationElement.servers.length === 0;
|
|
71
|
+
const pathItemServers = [...(pathItemElement.servers ?? [])];
|
|
72
|
+
if (isServersUndefined || !isServersArray) {
|
|
73
|
+
operationElement.servers = new _apidomNsOpenapi.OperationServersElement(pathItemServers);
|
|
74
|
+
} else if (isServersArray && isServersEmpty) {
|
|
75
|
+
pathItemServers.forEach(server => {
|
|
76
|
+
operationElement.servers.push(server);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
23
81
|
/**
|
|
24
82
|
* @public
|
|
25
83
|
*/
|
|
@@ -27,7 +85,6 @@ const plugin = ({
|
|
|
27
85
|
storageField = 'x-normalized'
|
|
28
86
|
} = {}) => toolbox => {
|
|
29
87
|
const {
|
|
30
|
-
ancestorLineageToJSONPointer,
|
|
31
88
|
predicates
|
|
32
89
|
} = toolbox;
|
|
33
90
|
let storage;
|
|
@@ -36,18 +93,8 @@ const plugin = ({
|
|
|
36
93
|
OpenApi3_1Element: {
|
|
37
94
|
enter(path) {
|
|
38
95
|
const openapiElement = path.node;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const isServersEmpty = isServersArrayElement && openapiElement.servers.length === 0;
|
|
42
|
-
const defaultServer = (0, _index.refractServer)({
|
|
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');
|
|
96
|
+
ensureDefaultServer(openapiElement);
|
|
97
|
+
storage = new _index.default(openapiElement, storageField, 'servers');
|
|
51
98
|
},
|
|
52
99
|
leave() {
|
|
53
100
|
storage = undefined;
|
|
@@ -60,28 +107,15 @@ const plugin = ({
|
|
|
60
107
|
// skip visiting this Path Item
|
|
61
108
|
if (ancestors.some(predicates.isComponentsElement)) return;
|
|
62
109
|
if (!ancestors.some(predicates.isOpenApi3_1Element)) return;
|
|
63
|
-
const pathItemJSONPointer =
|
|
110
|
+
const pathItemJSONPointer = path.formatPath();
|
|
64
111
|
|
|
65
112
|
// skip visiting this Path Item Object if it's already normalized
|
|
66
113
|
if (storage.includes(pathItemJSONPointer)) {
|
|
67
114
|
return;
|
|
68
115
|
}
|
|
69
116
|
const parentOpenapiElement = ancestors.find(predicates.isOpenApi3_1Element);
|
|
70
|
-
const isServersUndefined = typeof pathItemElement.servers === 'undefined';
|
|
71
|
-
const isServersArrayElement = predicates.isArrayElement(pathItemElement.servers);
|
|
72
|
-
const isServersEmpty = isServersArrayElement && pathItemElement.servers.length === 0;
|
|
73
|
-
|
|
74
|
-
// duplicate OpenAPI.servers into this Path Item object
|
|
75
117
|
if (predicates.isOpenApi3_1Element(parentOpenapiElement)) {
|
|
76
|
-
|
|
77
|
-
const openapiServers = openapiServersContent ?? [];
|
|
78
|
-
if (isServersUndefined || !isServersArrayElement) {
|
|
79
|
-
pathItemElement.servers = new _apidomNsOpenapi.PathItemServersElement(openapiServers);
|
|
80
|
-
} else if (isServersArrayElement && isServersEmpty) {
|
|
81
|
-
openapiServers.forEach(server => {
|
|
82
|
-
pathItemElement.servers.push(server);
|
|
83
|
-
});
|
|
84
|
-
}
|
|
118
|
+
inheritServersToPathItem(pathItemElement, parentOpenapiElement);
|
|
85
119
|
storage.append(pathItemJSONPointer);
|
|
86
120
|
}
|
|
87
121
|
},
|
|
@@ -92,33 +126,22 @@ const plugin = ({
|
|
|
92
126
|
// skip visiting this Operation
|
|
93
127
|
if (ancestors.some(predicates.isComponentsElement)) return;
|
|
94
128
|
if (!ancestors.some(predicates.isOpenApi3_1Element)) return;
|
|
95
|
-
const operationJSONPointer =
|
|
129
|
+
const operationJSONPointer = path.formatPath();
|
|
96
130
|
|
|
97
131
|
// skip visiting this Operation Object if it's already normalized
|
|
98
132
|
if (storage.includes(operationJSONPointer)) {
|
|
99
133
|
return;
|
|
100
134
|
}
|
|
101
|
-
|
|
102
|
-
// @TODO(vladimir.gorej@gmail.com): can be replaced by Array.prototype.findLast in future
|
|
103
135
|
const parentPathItemElement = ancestors.findLast(predicates.isPathItemElement);
|
|
104
|
-
const isServersUndefined = typeof operationElement.servers === 'undefined';
|
|
105
|
-
const isServersArrayElement = predicates.isArrayElement(operationElement.servers);
|
|
106
|
-
const isServersEmpty = isServersArrayElement && operationElement.servers.length === 0;
|
|
107
136
|
if (predicates.isPathItemElement(parentPathItemElement)) {
|
|
108
|
-
|
|
109
|
-
const pathItemServers = pathItemServersContent ?? [];
|
|
110
|
-
if (isServersUndefined || !isServersArrayElement) {
|
|
111
|
-
// duplicate parent PathItem.servers into this Operation object
|
|
112
|
-
operationElement.servers = new _apidomNsOpenapi.OperationServersElement(pathItemServers);
|
|
113
|
-
} else if (isServersArrayElement && isServersEmpty) {
|
|
114
|
-
pathItemServers.forEach(server => {
|
|
115
|
-
operationElement.servers.push(server);
|
|
116
|
-
});
|
|
117
|
-
}
|
|
137
|
+
inheritServersToOperation(operationElement, parentPathItemElement);
|
|
118
138
|
storage.append(operationJSONPointer);
|
|
119
139
|
}
|
|
120
140
|
}
|
|
121
141
|
}
|
|
122
142
|
};
|
|
123
143
|
};
|
|
144
|
+
plugin.ensureDefaultServer = ensureDefaultServer;
|
|
145
|
+
plugin.inheritServersToPathItem = inheritServersToPathItem;
|
|
146
|
+
plugin.inheritServersToOperation = inheritServersToOperation;
|
|
124
147
|
var _default = exports.default = plugin;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { isArrayElement } from '@speclynx/apidom-datamodel';
|
|
1
2
|
import { PathItemServersElement, OperationServersElement, ServersElement } from '@speclynx/apidom-ns-openapi-3-0';
|
|
2
|
-
import NormalizeStorage from "./normalize-
|
|
3
|
+
import NormalizeStorage from "./normalize-storage/index.mjs";
|
|
3
4
|
import { refractServer } from "../index.mjs";
|
|
4
5
|
/**
|
|
5
6
|
* Override of Server Objects.
|
|
@@ -14,6 +15,63 @@ import { refractServer } from "../index.mjs";
|
|
|
14
15
|
* If a servers array is specified at the Path Item Object or OpenAPI Object level, it will be overridden by Operation.servers.
|
|
15
16
|
* @public
|
|
16
17
|
*/
|
|
18
|
+
/**
|
|
19
|
+
* Ensures the OpenAPI document has at least one server defined.
|
|
20
|
+
* If `servers` is missing or empty, adds a default server with `url: "/"`.
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
const ensureDefaultServer = openapiElement => {
|
|
24
|
+
const isServersUndefined = typeof openapiElement.servers === 'undefined';
|
|
25
|
+
const isServersArray = isArrayElement(openapiElement.servers);
|
|
26
|
+
const isServersEmpty = isServersArray && openapiElement.servers.length === 0;
|
|
27
|
+
const defaultServer = refractServer({
|
|
28
|
+
url: '/'
|
|
29
|
+
});
|
|
30
|
+
if (isServersUndefined || !isServersArray) {
|
|
31
|
+
openapiElement.servers = new ServersElement([defaultServer]);
|
|
32
|
+
} else if (isServersArray && isServersEmpty) {
|
|
33
|
+
openapiElement.servers.push(defaultServer);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Inherits servers from the OpenAPI root into a PathItem element.
|
|
39
|
+
* If PathItem.servers is missing or empty, copies from OpenAPI.servers.
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
const inheritServersToPathItem = (pathItemElement, openapiElement) => {
|
|
43
|
+
const isServersUndefined = typeof pathItemElement.servers === 'undefined';
|
|
44
|
+
const isServersArray = isArrayElement(pathItemElement.servers);
|
|
45
|
+
const isServersEmpty = isServersArray && pathItemElement.servers.length === 0;
|
|
46
|
+
const openapiServers = [...(openapiElement.servers ?? [])];
|
|
47
|
+
if (isServersUndefined || !isServersArray) {
|
|
48
|
+
pathItemElement.servers = new PathItemServersElement(openapiServers);
|
|
49
|
+
} else if (isServersArray && isServersEmpty) {
|
|
50
|
+
openapiServers.forEach(server => {
|
|
51
|
+
pathItemElement.servers.push(server);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Inherits servers from a PathItem into an Operation element.
|
|
58
|
+
* If Operation.servers is missing or empty, copies from PathItem.servers.
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
const inheritServersToOperation = (operationElement, pathItemElement) => {
|
|
62
|
+
const isServersUndefined = typeof operationElement.servers === 'undefined';
|
|
63
|
+
const isServersArray = isArrayElement(operationElement.servers);
|
|
64
|
+
const isServersEmpty = isServersArray && operationElement.servers.length === 0;
|
|
65
|
+
const pathItemServers = [...(pathItemElement.servers ?? [])];
|
|
66
|
+
if (isServersUndefined || !isServersArray) {
|
|
67
|
+
operationElement.servers = new OperationServersElement(pathItemServers);
|
|
68
|
+
} else if (isServersArray && isServersEmpty) {
|
|
69
|
+
pathItemServers.forEach(server => {
|
|
70
|
+
operationElement.servers.push(server);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
17
75
|
/**
|
|
18
76
|
* @public
|
|
19
77
|
*/
|
|
@@ -21,7 +79,6 @@ const plugin = ({
|
|
|
21
79
|
storageField = 'x-normalized'
|
|
22
80
|
} = {}) => toolbox => {
|
|
23
81
|
const {
|
|
24
|
-
ancestorLineageToJSONPointer,
|
|
25
82
|
predicates
|
|
26
83
|
} = toolbox;
|
|
27
84
|
let storage;
|
|
@@ -30,17 +87,7 @@ const plugin = ({
|
|
|
30
87
|
OpenApi3_1Element: {
|
|
31
88
|
enter(path) {
|
|
32
89
|
const openapiElement = path.node;
|
|
33
|
-
|
|
34
|
-
const isServersArrayElement = predicates.isArrayElement(openapiElement.servers);
|
|
35
|
-
const isServersEmpty = isServersArrayElement && openapiElement.servers.length === 0;
|
|
36
|
-
const defaultServer = refractServer({
|
|
37
|
-
url: '/'
|
|
38
|
-
});
|
|
39
|
-
if (isServersUndefined || !isServersArrayElement) {
|
|
40
|
-
openapiElement.servers = new ServersElement([defaultServer]);
|
|
41
|
-
} else if (isServersArrayElement && isServersEmpty) {
|
|
42
|
-
openapiElement.servers.push(defaultServer);
|
|
43
|
-
}
|
|
90
|
+
ensureDefaultServer(openapiElement);
|
|
44
91
|
storage = new NormalizeStorage(openapiElement, storageField, 'servers');
|
|
45
92
|
},
|
|
46
93
|
leave() {
|
|
@@ -54,28 +101,15 @@ const plugin = ({
|
|
|
54
101
|
// skip visiting this Path Item
|
|
55
102
|
if (ancestors.some(predicates.isComponentsElement)) return;
|
|
56
103
|
if (!ancestors.some(predicates.isOpenApi3_1Element)) return;
|
|
57
|
-
const pathItemJSONPointer =
|
|
104
|
+
const pathItemJSONPointer = path.formatPath();
|
|
58
105
|
|
|
59
106
|
// skip visiting this Path Item Object if it's already normalized
|
|
60
107
|
if (storage.includes(pathItemJSONPointer)) {
|
|
61
108
|
return;
|
|
62
109
|
}
|
|
63
110
|
const parentOpenapiElement = ancestors.find(predicates.isOpenApi3_1Element);
|
|
64
|
-
const isServersUndefined = typeof pathItemElement.servers === 'undefined';
|
|
65
|
-
const isServersArrayElement = predicates.isArrayElement(pathItemElement.servers);
|
|
66
|
-
const isServersEmpty = isServersArrayElement && pathItemElement.servers.length === 0;
|
|
67
|
-
|
|
68
|
-
// duplicate OpenAPI.servers into this Path Item object
|
|
69
111
|
if (predicates.isOpenApi3_1Element(parentOpenapiElement)) {
|
|
70
|
-
|
|
71
|
-
const openapiServers = openapiServersContent ?? [];
|
|
72
|
-
if (isServersUndefined || !isServersArrayElement) {
|
|
73
|
-
pathItemElement.servers = new PathItemServersElement(openapiServers);
|
|
74
|
-
} else if (isServersArrayElement && isServersEmpty) {
|
|
75
|
-
openapiServers.forEach(server => {
|
|
76
|
-
pathItemElement.servers.push(server);
|
|
77
|
-
});
|
|
78
|
-
}
|
|
112
|
+
inheritServersToPathItem(pathItemElement, parentOpenapiElement);
|
|
79
113
|
storage.append(pathItemJSONPointer);
|
|
80
114
|
}
|
|
81
115
|
},
|
|
@@ -86,33 +120,22 @@ const plugin = ({
|
|
|
86
120
|
// skip visiting this Operation
|
|
87
121
|
if (ancestors.some(predicates.isComponentsElement)) return;
|
|
88
122
|
if (!ancestors.some(predicates.isOpenApi3_1Element)) return;
|
|
89
|
-
const operationJSONPointer =
|
|
123
|
+
const operationJSONPointer = path.formatPath();
|
|
90
124
|
|
|
91
125
|
// skip visiting this Operation Object if it's already normalized
|
|
92
126
|
if (storage.includes(operationJSONPointer)) {
|
|
93
127
|
return;
|
|
94
128
|
}
|
|
95
|
-
|
|
96
|
-
// @TODO(vladimir.gorej@gmail.com): can be replaced by Array.prototype.findLast in future
|
|
97
129
|
const parentPathItemElement = ancestors.findLast(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
130
|
if (predicates.isPathItemElement(parentPathItemElement)) {
|
|
102
|
-
|
|
103
|
-
const pathItemServers = pathItemServersContent ?? [];
|
|
104
|
-
if (isServersUndefined || !isServersArrayElement) {
|
|
105
|
-
// duplicate parent PathItem.servers into this Operation object
|
|
106
|
-
operationElement.servers = new OperationServersElement(pathItemServers);
|
|
107
|
-
} else if (isServersArrayElement && isServersEmpty) {
|
|
108
|
-
pathItemServers.forEach(server => {
|
|
109
|
-
operationElement.servers.push(server);
|
|
110
|
-
});
|
|
111
|
-
}
|
|
131
|
+
inheritServersToOperation(operationElement, parentPathItemElement);
|
|
112
132
|
storage.append(operationJSONPointer);
|
|
113
133
|
}
|
|
114
134
|
}
|
|
115
135
|
}
|
|
116
136
|
};
|
|
117
137
|
};
|
|
138
|
+
plugin.ensureDefaultServer = ensureDefaultServer;
|
|
139
|
+
plugin.inheritServersToPathItem = inheritServersToPathItem;
|
|
140
|
+
plugin.inheritServersToOperation = inheritServersToOperation;
|
|
118
141
|
export default plugin;
|
|
@@ -11,7 +11,7 @@ class NormalizeStorage {
|
|
|
11
11
|
this.storageSubField = storageSubField;
|
|
12
12
|
}
|
|
13
13
|
get store() {
|
|
14
|
-
if (
|
|
14
|
+
if (this.internalStore === undefined) {
|
|
15
15
|
let rootStore = this.storageElement.get(this.storageField);
|
|
16
16
|
if (!(0, _apidomDatamodel.isObjectElement)(rootStore)) {
|
|
17
17
|
rootStore = new _apidomDatamodel.ObjectElement();
|
|
@@ -7,7 +7,7 @@ class NormalizeStorage {
|
|
|
7
7
|
this.storageSubField = storageSubField;
|
|
8
8
|
}
|
|
9
9
|
get store() {
|
|
10
|
-
if (
|
|
10
|
+
if (this.internalStore === undefined) {
|
|
11
11
|
let rootStore = this.storageElement.get(this.storageField);
|
|
12
12
|
if (!isObjectElement(rootStore)) {
|
|
13
13
|
rootStore = new ObjectElement();
|
|
@@ -3,10 +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.default =
|
|
6
|
+
exports.default = void 0;
|
|
7
7
|
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
8
|
-
var _apidomCore = require("@speclynx/apidom-core");
|
|
9
|
-
var _apidomJsonPointer = require("@speclynx/apidom-json-pointer");
|
|
10
8
|
var openApi3_1Predicates = _interopRequireWildcard(require("../predicates.cjs"));
|
|
11
9
|
var refractorPredicates = _interopRequireWildcard(require("./predicates.cjs"));
|
|
12
10
|
var _namespace = _interopRequireDefault(require("../namespace.cjs"));
|
|
@@ -15,33 +13,8 @@ var _namespace = _interopRequireDefault(require("../namespace.cjs"));
|
|
|
15
13
|
*/
|
|
16
14
|
|
|
17
15
|
/**
|
|
18
|
-
* Translates visitor ancestor lineage to a JSON Pointer tokens.
|
|
19
|
-
* Ancestor lineage is constructed of following visitor method arguments:
|
|
20
|
-
*
|
|
21
|
-
* - ancestors
|
|
22
|
-
* - parent
|
|
23
|
-
* - element
|
|
24
16
|
* @public
|
|
25
17
|
*/
|
|
26
|
-
const ancestorLineageToJSONPointer = elementPath => {
|
|
27
|
-
const jsonPointerTokens = elementPath.reduce((path, element, index) => {
|
|
28
|
-
if ((0, _apidomDatamodel.isMemberElement)(element)) {
|
|
29
|
-
const token = String((0, _apidomCore.toValue)(element.key));
|
|
30
|
-
path.push(token);
|
|
31
|
-
} else if ((0, _apidomDatamodel.isArrayElement)(elementPath[index - 2])) {
|
|
32
|
-
const arrayElement = elementPath[index - 2];
|
|
33
|
-
const token = String(arrayElement.content?.indexOf(element) ?? -1);
|
|
34
|
-
path.push(token);
|
|
35
|
-
}
|
|
36
|
-
return path;
|
|
37
|
-
}, []);
|
|
38
|
-
return (0, _apidomJsonPointer.compile)(jsonPointerTokens);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @public
|
|
43
|
-
*/
|
|
44
|
-
exports.ancestorLineageToJSONPointer = ancestorLineageToJSONPointer;
|
|
45
18
|
const createToolbox = () => {
|
|
46
19
|
const namespace = new _apidomDatamodel.Namespace();
|
|
47
20
|
const predicates = {
|
|
@@ -54,7 +27,6 @@ const createToolbox = () => {
|
|
|
54
27
|
namespace.use(_namespace.default);
|
|
55
28
|
return {
|
|
56
29
|
predicates,
|
|
57
|
-
ancestorLineageToJSONPointer,
|
|
58
30
|
namespace
|
|
59
31
|
};
|
|
60
32
|
};
|
|
@@ -1,36 +1,10 @@
|
|
|
1
|
-
import { Namespace, isStringElement, isArrayElement, isObjectElement
|
|
2
|
-
import { toValue } from '@speclynx/apidom-core';
|
|
3
|
-
import { compile as compileJSONPointerTokens } from '@speclynx/apidom-json-pointer';
|
|
1
|
+
import { Namespace, isStringElement, isArrayElement, isObjectElement } from '@speclynx/apidom-datamodel';
|
|
4
2
|
import * as openApi3_1Predicates from "../predicates.mjs";
|
|
5
3
|
import * as refractorPredicates from "./predicates.mjs";
|
|
6
4
|
import openApi3_1Namespace from "../namespace.mjs";
|
|
7
5
|
/**
|
|
8
6
|
* @public
|
|
9
7
|
*/
|
|
10
|
-
/**
|
|
11
|
-
* Translates visitor ancestor lineage to a JSON Pointer tokens.
|
|
12
|
-
* Ancestor lineage is constructed of following visitor method arguments:
|
|
13
|
-
*
|
|
14
|
-
* - ancestors
|
|
15
|
-
* - parent
|
|
16
|
-
* - element
|
|
17
|
-
* @public
|
|
18
|
-
*/
|
|
19
|
-
export const ancestorLineageToJSONPointer = elementPath => {
|
|
20
|
-
const jsonPointerTokens = elementPath.reduce((path, element, index) => {
|
|
21
|
-
if (isMemberElement(element)) {
|
|
22
|
-
const token = String(toValue(element.key));
|
|
23
|
-
path.push(token);
|
|
24
|
-
} else if (isArrayElement(elementPath[index - 2])) {
|
|
25
|
-
const arrayElement = elementPath[index - 2];
|
|
26
|
-
const token = String(arrayElement.content?.indexOf(element) ?? -1);
|
|
27
|
-
path.push(token);
|
|
28
|
-
}
|
|
29
|
-
return path;
|
|
30
|
-
}, []);
|
|
31
|
-
return compileJSONPointerTokens(jsonPointerTokens);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
8
|
/**
|
|
35
9
|
* @public
|
|
36
10
|
*/
|
|
@@ -46,7 +20,6 @@ const createToolbox = () => {
|
|
|
46
20
|
namespace.use(openApi3_1Namespace);
|
|
47
21
|
return {
|
|
48
22
|
predicates,
|
|
49
|
-
ancestorLineageToJSONPointer,
|
|
50
23
|
namespace
|
|
51
24
|
};
|
|
52
25
|
};
|