@swagger-api/apidom-ns-openapi-3-1 1.0.0-alpha.0 → 1.0.0-alpha.10
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 +51 -0
- package/cjs/index.cjs +2 -2
- package/cjs/refractor/plugins/normalize-header-examples/NormalizeStorage.cjs +38 -0
- package/cjs/refractor/plugins/{normalize-header-examples.cjs → normalize-header-examples/index.cjs} +32 -6
- package/cjs/refractor/plugins/normalize-operation-ids.cjs +30 -12
- package/cjs/refractor/plugins/normalize-parameter-examples.cjs +32 -6
- package/cjs/refractor/plugins/normalize-parameters.cjs +29 -4
- package/cjs/refractor/plugins/normalize-security-requirements.cjs +21 -3
- package/cjs/refractor/plugins/normalize-servers.cjs +43 -16
- package/cjs/refractor/toolbox.cjs +23 -0
- package/dist/apidom-ns-openapi-3-1.browser.js +605 -212
- package/dist/apidom-ns-openapi-3-1.browser.min.js +1 -1
- package/es/index.mjs +1 -1
- package/es/refractor/plugins/normalize-header-examples/NormalizeStorage.mjs +34 -0
- package/es/refractor/plugins/{normalize-header-examples.mjs → normalize-header-examples/index.mjs} +30 -7
- package/es/refractor/plugins/normalize-operation-ids.mjs +29 -12
- package/es/refractor/plugins/normalize-parameter-examples.mjs +30 -7
- package/es/refractor/plugins/normalize-parameters.mjs +27 -4
- package/es/refractor/plugins/normalize-security-requirements.mjs +20 -4
- package/es/refractor/plugins/normalize-servers.mjs +42 -17
- package/es/refractor/toolbox.mjs +24 -1
- package/package.json +6 -5
- package/types/dist.d.ts +73 -36
package/es/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ export { default as refractorPluginNormalizeSecurityRequirements } from "./refra
|
|
|
7
7
|
export { default as refractorPluginNormalizeServers } from "./refractor/plugins/normalize-servers.mjs";
|
|
8
8
|
export { default as refractorPluginNormalizeOperationIds } from "./refractor/plugins/normalize-operation-ids.mjs";
|
|
9
9
|
export { default as refractorPluginNormalizeParameterExamples } from "./refractor/plugins/normalize-parameter-examples.mjs";
|
|
10
|
-
export { default as refractorPluginNormalizeHeaderExamples } from "./refractor/plugins/normalize-header-examples.mjs";
|
|
10
|
+
export { default as refractorPluginNormalizeHeaderExamples } from "./refractor/plugins/normalize-header-examples/index.mjs";
|
|
11
11
|
export { default as createToolbox } from "./refractor/toolbox.mjs";
|
|
12
12
|
export { default as specificationObj } from "./refractor/specification.mjs";
|
|
13
13
|
export { AlternatingVisitor } from '@swagger-api/apidom-ns-openapi-3-0';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ArrayElement, ObjectElement, isObjectElement, isArrayElement } from '@swagger-api/apidom-core';
|
|
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) {
|
|
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;
|
package/es/refractor/plugins/{normalize-header-examples.mjs → normalize-header-examples/index.mjs}
RENAMED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { cloneDeep } from '@swagger-api/apidom-core';
|
|
2
|
+
import NormalizeStorage from "./NormalizeStorage.mjs";
|
|
2
3
|
/**
|
|
3
4
|
* Override of Schema.example and Schema.examples field inside the Header Objects.
|
|
4
5
|
*
|
|
@@ -10,13 +11,27 @@ import { cloneDeep } from '@swagger-api/apidom-core';
|
|
|
10
11
|
*
|
|
11
12
|
* The example value SHALL override the example provided by the schema.
|
|
12
13
|
* Furthermore, if referencing a schema that contains an example, the examples value SHALL override the example provided by the schema.
|
|
14
|
+
*
|
|
15
|
+
* NOTE: this plugin is idempotent
|
|
13
16
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
const plugin = ({
|
|
18
|
+
storageField = 'x-normalized'
|
|
19
|
+
} = {}) => toolbox => {
|
|
20
|
+
const {
|
|
21
|
+
predicates,
|
|
22
|
+
ancestorLineageToJSONPointer
|
|
23
|
+
} = toolbox;
|
|
24
|
+
let storage;
|
|
18
25
|
return {
|
|
19
26
|
visitor: {
|
|
27
|
+
OpenApi3_1Element: {
|
|
28
|
+
enter(element) {
|
|
29
|
+
storage = new NormalizeStorage(element, storageField, 'header-examples');
|
|
30
|
+
},
|
|
31
|
+
leave() {
|
|
32
|
+
storage = undefined;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
20
35
|
HeaderElement: {
|
|
21
36
|
leave(headerElement, key, parent, path, ancestors) {
|
|
22
37
|
var _headerElement$schema, _headerElement$schema2;
|
|
@@ -33,6 +48,12 @@ const plugin = () => ({
|
|
|
33
48
|
if (typeof ((_headerElement$schema = headerElement.schema) === null || _headerElement$schema === void 0 ? void 0 : _headerElement$schema.example) === 'undefined' && typeof ((_headerElement$schema2 = headerElement.schema) === null || _headerElement$schema2 === void 0 ? void 0 : _headerElement$schema2.examples) === 'undefined') {
|
|
34
49
|
return;
|
|
35
50
|
}
|
|
51
|
+
const headerJSONPointer = ancestorLineageToJSONPointer([...ancestors, parent, headerElement]);
|
|
52
|
+
|
|
53
|
+
// skip visiting this Header Object if it's already normalized
|
|
54
|
+
if (storage.includes(headerJSONPointer)) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
36
57
|
|
|
37
58
|
/**
|
|
38
59
|
* Header.examples and Schema.examples have preferences over the older
|
|
@@ -45,9 +66,11 @@ const plugin = () => ({
|
|
|
45
66
|
});
|
|
46
67
|
if (typeof headerElement.schema.examples !== 'undefined') {
|
|
47
68
|
headerElement.schema.set('examples', examples);
|
|
69
|
+
storage.append(headerJSONPointer);
|
|
48
70
|
}
|
|
49
71
|
if (typeof headerElement.schema.example !== 'undefined') {
|
|
50
|
-
headerElement.schema.set('example', examples);
|
|
72
|
+
headerElement.schema.set('example', examples[0]);
|
|
73
|
+
storage.append(headerJSONPointer);
|
|
51
74
|
}
|
|
52
75
|
return;
|
|
53
76
|
}
|
|
@@ -58,9 +81,11 @@ const plugin = () => ({
|
|
|
58
81
|
if (typeof headerElement.example !== 'undefined') {
|
|
59
82
|
if (typeof headerElement.schema.examples !== 'undefined') {
|
|
60
83
|
headerElement.schema.set('examples', [cloneDeep(headerElement.example)]);
|
|
84
|
+
storage.append(headerJSONPointer);
|
|
61
85
|
}
|
|
62
86
|
if (typeof headerElement.schema.example !== 'undefined') {
|
|
63
87
|
headerElement.schema.set('example', cloneDeep(headerElement.example));
|
|
88
|
+
storage.append(headerJSONPointer);
|
|
64
89
|
}
|
|
65
90
|
}
|
|
66
91
|
}
|
|
@@ -68,6 +93,4 @@ const plugin = () => ({
|
|
|
68
93
|
}
|
|
69
94
|
};
|
|
70
95
|
};
|
|
71
|
-
/* eslint-enable */
|
|
72
|
-
|
|
73
96
|
export default plugin;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { last, defaultTo, groupBy } from 'ramda';
|
|
2
2
|
import { toValue, cloneDeep } from '@swagger-api/apidom-core';
|
|
3
|
+
import NormalizeStorage from "./normalize-header-examples/NormalizeStorage.mjs";
|
|
3
4
|
const removeSpaces = operationId => {
|
|
4
5
|
return operationId.replace(/\s/g, '');
|
|
5
6
|
};
|
|
@@ -33,21 +34,29 @@ const normalizeOperationId = (operationId, path, method) => {
|
|
|
33
34
|
* This plugin also guarantees the uniqueness of all defined Operation.operationId fields,
|
|
34
35
|
* and make sure Link.operationId fields are pointing to correct and normalized Operation.operationId fields.
|
|
35
36
|
*
|
|
37
|
+
* NOTE: this plugin is idempotent
|
|
36
38
|
*/
|
|
37
|
-
/* eslint-disable no-param-reassign */
|
|
38
39
|
|
|
40
|
+
/* eslint-disable no-param-reassign */
|
|
39
41
|
const plugin = ({
|
|
42
|
+
storageField = 'x-normalized',
|
|
40
43
|
operationIdNormalizer = normalizeOperationId
|
|
41
|
-
} = {}) =>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
} = {}) => toolbox => {
|
|
45
|
+
const {
|
|
46
|
+
predicates,
|
|
47
|
+
ancestorLineageToJSONPointer,
|
|
48
|
+
namespace
|
|
49
|
+
} = toolbox;
|
|
50
|
+
const pathTemplates = [];
|
|
46
51
|
const normalizedOperations = [];
|
|
47
52
|
const links = [];
|
|
53
|
+
let storage;
|
|
48
54
|
return {
|
|
49
55
|
visitor: {
|
|
50
56
|
OpenApi3_1Element: {
|
|
57
|
+
enter(element) {
|
|
58
|
+
storage = new NormalizeStorage(element, storageField, 'operation-ids');
|
|
59
|
+
},
|
|
51
60
|
leave() {
|
|
52
61
|
// group normalized operations by normalized operationId
|
|
53
62
|
const normalizedOperationGroups = groupBy(operationElement => {
|
|
@@ -84,30 +93,37 @@ const plugin = ({
|
|
|
84
93
|
// cleanup the references
|
|
85
94
|
normalizedOperations.length = 0;
|
|
86
95
|
links.length = 0;
|
|
96
|
+
storage = undefined;
|
|
87
97
|
}
|
|
88
98
|
},
|
|
89
99
|
PathItemElement: {
|
|
90
100
|
enter(pathItemElement) {
|
|
91
101
|
// `path` meta may not be always available, e.g. in Callback Object or Components Object
|
|
92
|
-
const
|
|
93
|
-
|
|
102
|
+
const pathTemplate = defaultTo('path', toValue(pathItemElement.meta.get('path')));
|
|
103
|
+
pathTemplates.push(pathTemplate);
|
|
94
104
|
},
|
|
95
105
|
leave() {
|
|
96
|
-
|
|
106
|
+
pathTemplates.pop();
|
|
97
107
|
}
|
|
98
108
|
},
|
|
99
109
|
OperationElement: {
|
|
100
|
-
enter(operationElement) {
|
|
110
|
+
enter(operationElement, key, parent, path, ancestors) {
|
|
101
111
|
// operationId field is undefined, needs no normalization
|
|
102
112
|
if (typeof operationElement.operationId === 'undefined') return;
|
|
113
|
+
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors, parent, operationElement]);
|
|
114
|
+
|
|
115
|
+
// skip visiting this Operation Object if it's already normalized
|
|
116
|
+
if (storage.includes(operationJSONPointer)) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
103
119
|
|
|
104
120
|
// cast operationId to string type
|
|
105
121
|
const originalOperationId = String(toValue(operationElement.operationId));
|
|
106
122
|
// perform operationId normalization
|
|
107
|
-
const
|
|
123
|
+
const pathTemplate = last(pathTemplates);
|
|
108
124
|
// `http-method` meta may not be always available, e.g. in Callback Object or Components Object
|
|
109
125
|
const method = defaultTo('method', toValue(operationElement.meta.get('http-method')));
|
|
110
|
-
const normalizedOperationId = operationIdNormalizer(originalOperationId,
|
|
126
|
+
const normalizedOperationId = operationIdNormalizer(originalOperationId, pathTemplate, method);
|
|
111
127
|
|
|
112
128
|
// normalization is not necessary
|
|
113
129
|
if (originalOperationId === normalizedOperationId) return;
|
|
@@ -117,6 +133,7 @@ const plugin = ({
|
|
|
117
133
|
operationElement.set('__originalOperationId', originalOperationId);
|
|
118
134
|
operationElement.meta.set('originalOperationId', originalOperationId);
|
|
119
135
|
normalizedOperations.push(operationElement);
|
|
136
|
+
storage.append(operationJSONPointer);
|
|
120
137
|
}
|
|
121
138
|
},
|
|
122
139
|
LinkElement: {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { cloneDeep } from '@swagger-api/apidom-core';
|
|
2
|
+
import NormalizeStorage from "./normalize-header-examples/NormalizeStorage.mjs";
|
|
2
3
|
/**
|
|
3
4
|
* Override of Schema.example and Schema.examples field inside the Parameter Objects.
|
|
4
5
|
*
|
|
@@ -10,13 +11,27 @@ import { cloneDeep } from '@swagger-api/apidom-core';
|
|
|
10
11
|
*
|
|
11
12
|
* The example value SHALL override the example provided by the schema.
|
|
12
13
|
* Furthermore, if referencing a schema that contains an example, the examples value SHALL override the example provided by the schema.
|
|
14
|
+
*
|
|
15
|
+
* NOTE: this plugin is idempotent
|
|
13
16
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
const plugin = ({
|
|
18
|
+
storageField = 'x-normalized'
|
|
19
|
+
} = {}) => toolbox => {
|
|
20
|
+
const {
|
|
21
|
+
predicates,
|
|
22
|
+
ancestorLineageToJSONPointer
|
|
23
|
+
} = toolbox;
|
|
24
|
+
let storage;
|
|
18
25
|
return {
|
|
19
26
|
visitor: {
|
|
27
|
+
OpenApi3_1Element: {
|
|
28
|
+
enter(element) {
|
|
29
|
+
storage = new NormalizeStorage(element, storageField, 'parameter-examples');
|
|
30
|
+
},
|
|
31
|
+
leave() {
|
|
32
|
+
storage = undefined;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
20
35
|
ParameterElement: {
|
|
21
36
|
leave(parameterElement, key, parent, path, ancestors) {
|
|
22
37
|
var _parameterElement$sch, _parameterElement$sch2;
|
|
@@ -33,6 +48,12 @@ const plugin = () => ({
|
|
|
33
48
|
if (typeof ((_parameterElement$sch = parameterElement.schema) === null || _parameterElement$sch === void 0 ? void 0 : _parameterElement$sch.example) === 'undefined' && typeof ((_parameterElement$sch2 = parameterElement.schema) === null || _parameterElement$sch2 === void 0 ? void 0 : _parameterElement$sch2.examples) === 'undefined') {
|
|
34
49
|
return;
|
|
35
50
|
}
|
|
51
|
+
const parameterJSONPointer = ancestorLineageToJSONPointer([...ancestors, parent, parameterElement]);
|
|
52
|
+
|
|
53
|
+
// skip visiting this Parameter Object if it's already normalized
|
|
54
|
+
if (storage.includes(parameterJSONPointer)) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
36
57
|
|
|
37
58
|
/**
|
|
38
59
|
* Parameter.examples and Schema.examples have preferences over the older
|
|
@@ -45,9 +66,11 @@ const plugin = () => ({
|
|
|
45
66
|
});
|
|
46
67
|
if (typeof parameterElement.schema.examples !== 'undefined') {
|
|
47
68
|
parameterElement.schema.set('examples', examples);
|
|
69
|
+
storage.append(parameterJSONPointer);
|
|
48
70
|
}
|
|
49
71
|
if (typeof parameterElement.schema.example !== 'undefined') {
|
|
50
|
-
parameterElement.schema.set('example', examples);
|
|
72
|
+
parameterElement.schema.set('example', examples[0]);
|
|
73
|
+
storage.append(parameterJSONPointer);
|
|
51
74
|
}
|
|
52
75
|
return;
|
|
53
76
|
}
|
|
@@ -58,9 +81,11 @@ const plugin = () => ({
|
|
|
58
81
|
if (typeof parameterElement.example !== 'undefined') {
|
|
59
82
|
if (typeof parameterElement.schema.examples !== 'undefined') {
|
|
60
83
|
parameterElement.schema.set('examples', [cloneDeep(parameterElement.example)]);
|
|
84
|
+
storage.append(parameterJSONPointer);
|
|
61
85
|
}
|
|
62
86
|
if (typeof parameterElement.schema.example !== 'undefined') {
|
|
63
87
|
parameterElement.schema.set('example', cloneDeep(parameterElement.example));
|
|
88
|
+
storage.append(parameterJSONPointer);
|
|
64
89
|
}
|
|
65
90
|
}
|
|
66
91
|
}
|
|
@@ -68,6 +93,4 @@ const plugin = () => ({
|
|
|
68
93
|
}
|
|
69
94
|
};
|
|
70
95
|
};
|
|
71
|
-
/* eslint-enable */
|
|
72
|
-
|
|
73
96
|
export default plugin;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { uniqWith, pathOr, last } from 'ramda';
|
|
2
2
|
import { toValue } from '@swagger-api/apidom-core';
|
|
3
3
|
import { OperationParametersElement } from '@swagger-api/apidom-ns-openapi-3-0';
|
|
4
|
+
import NormalizeStorage from "./normalize-header-examples/NormalizeStorage.mjs";
|
|
4
5
|
/**
|
|
5
6
|
* Inheritance of Parameter Objects.
|
|
6
7
|
*
|
|
@@ -9,11 +10,17 @@ import { OperationParametersElement } from '@swagger-api/apidom-ns-openapi-3-0';
|
|
|
9
10
|
* A list of parameters that are applicable for this operation. If a parameter is already defined at the Path Item,
|
|
10
11
|
* the new definition will override it but can never remove it. The list MUST NOT include duplicated parameters.
|
|
11
12
|
* A unique parameter is defined by a combination of a name and location.
|
|
13
|
+
*
|
|
14
|
+
* NOTE: this plugin is idempotent
|
|
12
15
|
*/
|
|
13
16
|
/* eslint-disable no-param-reassign */
|
|
14
|
-
const plugin = (
|
|
15
|
-
|
|
16
|
-
}) => {
|
|
17
|
+
const plugin = ({
|
|
18
|
+
storageField = 'x-normalized'
|
|
19
|
+
} = {}) => toolbox => {
|
|
20
|
+
const {
|
|
21
|
+
predicates,
|
|
22
|
+
ancestorLineageToJSONPointer
|
|
23
|
+
} = toolbox;
|
|
17
24
|
/**
|
|
18
25
|
* Establishes identity between two Parameter Objects.
|
|
19
26
|
*
|
|
@@ -29,8 +36,17 @@ const plugin = () => ({
|
|
|
29
36
|
return toValue(parameter1.name) === toValue(parameter2.name) && toValue(parameter1.in) === toValue(parameter2.in);
|
|
30
37
|
};
|
|
31
38
|
const pathItemParameters = [];
|
|
39
|
+
let storage;
|
|
32
40
|
return {
|
|
33
41
|
visitor: {
|
|
42
|
+
OpenApi3_1Element: {
|
|
43
|
+
enter(element) {
|
|
44
|
+
storage = new NormalizeStorage(element, storageField, 'parameters');
|
|
45
|
+
},
|
|
46
|
+
leave() {
|
|
47
|
+
storage = undefined;
|
|
48
|
+
}
|
|
49
|
+
},
|
|
34
50
|
PathItemElement: {
|
|
35
51
|
enter(pathItemElement, key, parent, path, ancestors) {
|
|
36
52
|
// skip visiting this Path Item
|
|
@@ -51,18 +67,25 @@ const plugin = () => ({
|
|
|
51
67
|
}
|
|
52
68
|
},
|
|
53
69
|
OperationElement: {
|
|
54
|
-
leave(operationElement) {
|
|
70
|
+
leave(operationElement, key, parent, path, ancestors) {
|
|
55
71
|
const parentPathItemParameters = last(pathItemParameters);
|
|
56
72
|
|
|
57
73
|
// no Path Item Object parameters to inherit from
|
|
58
74
|
if (!Array.isArray(parentPathItemParameters) || parentPathItemParameters.length === 0) {
|
|
59
75
|
return;
|
|
60
76
|
}
|
|
77
|
+
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors, parent, operationElement]);
|
|
78
|
+
|
|
79
|
+
// skip visiting this Operation Object if it's already normalized
|
|
80
|
+
if (storage.includes(operationJSONPointer)) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
61
83
|
const operationParameters = pathOr([], ['parameters', 'content'], operationElement);
|
|
62
84
|
|
|
63
85
|
// prefers the first item if two items compare equal based on the predicate
|
|
64
86
|
const mergedParameters = uniqWith(parameterEquals, [...operationParameters, ...parentPathItemParameters]);
|
|
65
87
|
operationElement.parameters = new OperationParametersElement(mergedParameters);
|
|
88
|
+
storage.append(operationJSONPointer);
|
|
66
89
|
}
|
|
67
90
|
}
|
|
68
91
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { OperationSecurityElement } from '@swagger-api/apidom-ns-openapi-3-0';
|
|
2
|
+
import NormalizeStorage from "./normalize-header-examples/NormalizeStorage.mjs";
|
|
2
3
|
/**
|
|
3
4
|
* Override of Security Requirement Objects.
|
|
4
5
|
*
|
|
@@ -8,22 +9,30 @@ import { OperationSecurityElement } from '@swagger-api/apidom-ns-openapi-3-0';
|
|
|
8
9
|
* To remove a top-level security declaration, an empty array can be used.
|
|
9
10
|
* When a list of Security Requirement Objects is defined on the OpenAPI Object or Operation Object,
|
|
10
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
|
|
11
14
|
*/
|
|
12
|
-
|
|
13
15
|
/* eslint-disable no-param-reassign */
|
|
14
|
-
const plugin = (
|
|
15
|
-
|
|
16
|
-
}) => {
|
|
16
|
+
const plugin = ({
|
|
17
|
+
storageField = 'x-normalized'
|
|
18
|
+
} = {}) => toolbox => {
|
|
19
|
+
const {
|
|
20
|
+
predicates,
|
|
21
|
+
ancestorLineageToJSONPointer
|
|
22
|
+
} = toolbox;
|
|
17
23
|
let topLevelSecurity;
|
|
24
|
+
let storage;
|
|
18
25
|
return {
|
|
19
26
|
visitor: {
|
|
20
27
|
OpenApi3_1Element: {
|
|
21
28
|
enter(openapiElement) {
|
|
29
|
+
storage = new NormalizeStorage(openapiElement, storageField, 'security-requirements');
|
|
22
30
|
if (predicates.isArrayElement(openapiElement.security)) {
|
|
23
31
|
topLevelSecurity = openapiElement.security;
|
|
24
32
|
}
|
|
25
33
|
},
|
|
26
34
|
leave() {
|
|
35
|
+
storage = undefined;
|
|
27
36
|
topLevelSecurity = undefined;
|
|
28
37
|
}
|
|
29
38
|
},
|
|
@@ -33,11 +42,18 @@ const plugin = () => ({
|
|
|
33
42
|
if (ancestors.some(predicates.isComponentsElement)) {
|
|
34
43
|
return;
|
|
35
44
|
}
|
|
45
|
+
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors, parent, operationElement]);
|
|
46
|
+
|
|
47
|
+
// skip visiting this Operation Object if it's already normalized
|
|
48
|
+
if (storage.includes(operationJSONPointer)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
36
51
|
const missingOperationLevelSecurity = typeof operationElement.security === 'undefined';
|
|
37
52
|
const hasTopLevelSecurity = typeof topLevelSecurity !== 'undefined';
|
|
38
53
|
if (missingOperationLevelSecurity && hasTopLevelSecurity) {
|
|
39
54
|
var _topLevelSecurity;
|
|
40
55
|
operationElement.security = new OperationSecurityElement((_topLevelSecurity = topLevelSecurity) === null || _topLevelSecurity === void 0 ? void 0 : _topLevelSecurity.content);
|
|
56
|
+
storage.append(operationJSONPointer);
|
|
41
57
|
}
|
|
42
58
|
}
|
|
43
59
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PathItemServersElement, OperationServersElement, ServersElement } from '@swagger-api/apidom-ns-openapi-3-0';
|
|
2
|
+
import NormalizeStorage from "./normalize-header-examples/NormalizeStorage.mjs";
|
|
2
3
|
/**
|
|
3
4
|
* Override of Server Objects.
|
|
4
5
|
*
|
|
@@ -11,32 +12,48 @@ import { PathItemServersElement, OperationServersElement, ServersElement } from
|
|
|
11
12
|
* If an alternative server object is specified at the Path Item Object level, it will override OpenAPI.servers.
|
|
12
13
|
* If an alternative server object is specified at the Operation Object level, it will override PathItem.servers and OpenAPI.servers respectively.
|
|
13
14
|
*/
|
|
14
|
-
|
|
15
15
|
/* eslint-disable no-param-reassign */
|
|
16
|
-
const plugin = (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const plugin = ({
|
|
17
|
+
storageField = 'x-normalized'
|
|
18
|
+
} = {}) => toolbox => {
|
|
19
|
+
const {
|
|
20
|
+
namespace,
|
|
21
|
+
ancestorLineageToJSONPointer,
|
|
22
|
+
predicates
|
|
23
|
+
} = toolbox;
|
|
24
|
+
let storage;
|
|
20
25
|
return {
|
|
21
26
|
visitor: {
|
|
22
|
-
OpenApi3_1Element
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
OpenApi3_1Element: {
|
|
28
|
+
enter(openapiElement) {
|
|
29
|
+
const isServersUndefined = typeof openapiElement.servers === 'undefined';
|
|
30
|
+
const isServersArrayElement = predicates.isArrayElement(openapiElement.servers);
|
|
31
|
+
const isServersEmpty = isServersArrayElement && openapiElement.servers.length === 0;
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
const defaultServer = namespace.elements.Server.refract({
|
|
34
|
+
url: '/'
|
|
35
|
+
});
|
|
36
|
+
if (isServersUndefined || !isServersArrayElement) {
|
|
37
|
+
openapiElement.servers = new ServersElement([defaultServer]);
|
|
38
|
+
} else if (isServersArrayElement && isServersEmpty) {
|
|
39
|
+
openapiElement.servers.push(defaultServer);
|
|
40
|
+
}
|
|
41
|
+
storage = new NormalizeStorage(openapiElement, storageField, 'servers');
|
|
42
|
+
},
|
|
43
|
+
leave() {
|
|
44
|
+
storage = undefined;
|
|
34
45
|
}
|
|
35
46
|
},
|
|
36
47
|
PathItemElement(pathItemElement, key, parent, path, ancestors) {
|
|
37
48
|
// skip visiting this Path Item
|
|
38
49
|
if (ancestors.some(predicates.isComponentsElement)) return;
|
|
39
50
|
if (!ancestors.some(predicates.isOpenApi3_1Element)) return;
|
|
51
|
+
const pathItemJSONPointer = ancestorLineageToJSONPointer([...ancestors, parent, pathItemElement]);
|
|
52
|
+
|
|
53
|
+
// skip visiting this Path Item Object if it's already normalized
|
|
54
|
+
if (storage.includes(pathItemJSONPointer)) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
40
57
|
const parentOpenapiElement = ancestors.find(predicates.isOpenApi3_1Element);
|
|
41
58
|
const isServersUndefined = typeof pathItemElement.servers === 'undefined';
|
|
42
59
|
const isServersArrayElement = predicates.isArrayElement(pathItemElement.servers);
|
|
@@ -54,12 +71,19 @@ const plugin = () => ({
|
|
|
54
71
|
pathItemElement.servers.push(server);
|
|
55
72
|
});
|
|
56
73
|
}
|
|
74
|
+
storage.append(pathItemJSONPointer);
|
|
57
75
|
}
|
|
58
76
|
},
|
|
59
77
|
OperationElement(operationElement, key, parent, path, ancestors) {
|
|
60
78
|
// skip visiting this Operation
|
|
61
79
|
if (ancestors.some(predicates.isComponentsElement)) return;
|
|
62
80
|
if (!ancestors.some(predicates.isOpenApi3_1Element)) return;
|
|
81
|
+
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors, parent, operationElement]);
|
|
82
|
+
|
|
83
|
+
// skip visiting this Operation Object if it's already normalized
|
|
84
|
+
if (storage.includes(operationJSONPointer)) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
63
87
|
|
|
64
88
|
// @TODO(vladimir.gorej@gmail.com): can be replaced by Array.prototype.findLast in future
|
|
65
89
|
const parentPathItemElement = [...ancestors].reverse().find(predicates.isPathItemElement);
|
|
@@ -78,6 +102,7 @@ const plugin = () => ({
|
|
|
78
102
|
operationElement.servers.push(server);
|
|
79
103
|
});
|
|
80
104
|
}
|
|
105
|
+
storage.append(operationJSONPointer);
|
|
81
106
|
}
|
|
82
107
|
}
|
|
83
108
|
}
|
package/es/refractor/toolbox.mjs
CHANGED
|
@@ -1,7 +1,29 @@
|
|
|
1
|
-
import { isElement, isStringElement, isArrayElement, isObjectElement, isMemberElement, createNamespace, includesClasses, hasElementSourceMap } from '@swagger-api/apidom-core';
|
|
1
|
+
import { isElement, isStringElement, isArrayElement, isObjectElement, isMemberElement, toValue, createNamespace, includesClasses, hasElementSourceMap } from '@swagger-api/apidom-core';
|
|
2
|
+
import { compile as compileJSONPointerTokens } from '@swagger-api/apidom-json-pointer';
|
|
2
3
|
import { isServersElement } from '@swagger-api/apidom-ns-openapi-3-0';
|
|
3
4
|
import * as openApi3_1Predicates from "../predicates.mjs";
|
|
4
5
|
import openApi3_1Namespace from "../namespace.mjs";
|
|
6
|
+
/**
|
|
7
|
+
* Translates visitor ancestor lineage to a JSON Pointer tokens.
|
|
8
|
+
* Ancestor lineage is constructed of following visitor method arguments:
|
|
9
|
+
*
|
|
10
|
+
* - ancestors
|
|
11
|
+
* - parent
|
|
12
|
+
* - element
|
|
13
|
+
*/
|
|
14
|
+
const ancestorLineageToJSONPointer = elementPath => {
|
|
15
|
+
const jsonPointerTokens = elementPath.reduce((path, element, index) => {
|
|
16
|
+
if (isMemberElement(element)) {
|
|
17
|
+
const token = String(toValue(element.key));
|
|
18
|
+
path.push(token);
|
|
19
|
+
} else if (isArrayElement(elementPath[index - 2])) {
|
|
20
|
+
const token = String(elementPath[index - 2].content.indexOf(element));
|
|
21
|
+
path.push(token);
|
|
22
|
+
}
|
|
23
|
+
return path;
|
|
24
|
+
}, []);
|
|
25
|
+
return compileJSONPointerTokens(jsonPointerTokens);
|
|
26
|
+
};
|
|
5
27
|
const createToolbox = () => {
|
|
6
28
|
const namespace = createNamespace(openApi3_1Namespace);
|
|
7
29
|
const predicates = {
|
|
@@ -17,6 +39,7 @@ const createToolbox = () => {
|
|
|
17
39
|
};
|
|
18
40
|
return {
|
|
19
41
|
predicates,
|
|
42
|
+
ancestorLineageToJSONPointer,
|
|
20
43
|
namespace
|
|
21
44
|
};
|
|
22
45
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swagger-api/apidom-ns-openapi-3-1",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.10",
|
|
4
4
|
"description": "OpenAPI 3.1.x namespace for ApiDOM.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -45,9 +45,10 @@
|
|
|
45
45
|
"license": "Apache-2.0",
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@babel/runtime-corejs3": "^7.20.7",
|
|
48
|
-
"@swagger-api/apidom-ast": "^1.0.0-alpha.
|
|
49
|
-
"@swagger-api/apidom-core": "^1.0.0-alpha.
|
|
50
|
-
"@swagger-api/apidom-
|
|
48
|
+
"@swagger-api/apidom-ast": "^1.0.0-alpha.10",
|
|
49
|
+
"@swagger-api/apidom-core": "^1.0.0-alpha.10",
|
|
50
|
+
"@swagger-api/apidom-json-pointer": "^1.0.0-alpha.10",
|
|
51
|
+
"@swagger-api/apidom-ns-openapi-3-0": "^1.0.0-alpha.10",
|
|
51
52
|
"@types/ramda": "~0.30.0",
|
|
52
53
|
"ramda": "~0.30.0",
|
|
53
54
|
"ramda-adjunct": "^5.0.0",
|
|
@@ -63,5 +64,5 @@
|
|
|
63
64
|
"README.md",
|
|
64
65
|
"CHANGELOG.md"
|
|
65
66
|
],
|
|
66
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "0fbbdb5d453d7a4661f62ce5e4b690d279e50b74"
|
|
67
68
|
}
|