@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/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,57 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.0.0-alpha.10](https://github.com/swagger-api/apidom/compare/v1.0.0-alpha.9...v1.0.0-alpha.10) (2024-10-21)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
|
|
9
|
+
|
|
10
|
+
# [1.0.0-alpha.9](https://github.com/swagger-api/apidom/compare/v1.0.0-alpha.8...v1.0.0-alpha.9) (2024-08-14)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
|
|
13
|
+
|
|
14
|
+
# [1.0.0-alpha.8](https://github.com/swagger-api/apidom/compare/v1.0.0-alpha.7...v1.0.0-alpha.8) (2024-08-08)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
|
|
17
|
+
|
|
18
|
+
# [1.0.0-alpha.7](https://github.com/swagger-api/apidom/compare/v1.0.0-alpha.6...v1.0.0-alpha.7) (2024-08-05)
|
|
19
|
+
|
|
20
|
+
**Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
|
|
21
|
+
|
|
22
|
+
# [1.0.0-alpha.6](https://github.com/swagger-api/apidom/compare/v1.0.0-alpha.5...v1.0.0-alpha.6) (2024-07-09)
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
- **ns-openapi-3-1:** set example to first element of examples in parameter examples refractor plugin ([#4230](https://github.com/swagger-api/apidom/issues/4230)) ([d85f72a](https://github.com/swagger-api/apidom/commit/d85f72ae327d521ae63e6096824ae994b9e486ca)), closes [#4229](https://github.com/swagger-api/apidom/issues/4229)
|
|
27
|
+
|
|
28
|
+
# [1.0.0-alpha.5](https://github.com/swagger-api/apidom/compare/v1.0.0-alpha.4...v1.0.0-alpha.5) (2024-05-29)
|
|
29
|
+
|
|
30
|
+
**Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
|
|
31
|
+
|
|
32
|
+
# [1.0.0-alpha.4](https://github.com/swagger-api/apidom/compare/v1.0.0-alpha.3...v1.0.0-alpha.4) (2024-05-29)
|
|
33
|
+
|
|
34
|
+
### Features
|
|
35
|
+
|
|
36
|
+
- **ns-openapi-3-1:** add idempotence to parameter examples refractor plugin ([#4142](https://github.com/swagger-api/apidom/issues/4142)) ([7cee6e9](https://github.com/swagger-api/apidom/commit/7cee6e9a74746338e60480a764485c7ec31a206f)), closes [#4134](https://github.com/swagger-api/apidom/issues/4134)
|
|
37
|
+
- **ns-openapi-3-1:** make header example refractor plugin idempotent ([#4135](https://github.com/swagger-api/apidom/issues/4135)) ([524cce2](https://github.com/swagger-api/apidom/commit/524cce246b3919bed92aa197ce189dfc2792fb26)), closes [#4134](https://github.com/swagger-api/apidom/issues/4134)
|
|
38
|
+
- **ns-openapi-3-1:** make operation ids refractor plugin idempotent ([#4151](https://github.com/swagger-api/apidom/issues/4151)) ([858cec6](https://github.com/swagger-api/apidom/commit/858cec60259ca74f00f90456dcdcebcdefbef288)), closes [#4134](https://github.com/swagger-api/apidom/issues/4134)
|
|
39
|
+
- **ns-openapi-3-1:** make parameters plugin idempotent ([#4150](https://github.com/swagger-api/apidom/issues/4150)) ([7fdf6b5](https://github.com/swagger-api/apidom/commit/7fdf6b50263fb658e6fe62c54d91de746e73dc4e)), closes [#4134](https://github.com/swagger-api/apidom/issues/4134)
|
|
40
|
+
- **ns-openapi-3-1:** make security requirements refractor plugin idempotent ([#4149](https://github.com/swagger-api/apidom/issues/4149)) ([e28f053](https://github.com/swagger-api/apidom/commit/e28f0533e32760f4a4ea5bf92351066327bff4dc)), closes [#4134](https://github.com/swagger-api/apidom/issues/4134)
|
|
41
|
+
- **ns-openapi-3-1:** make servers refractor plugin idempotent ([#4152](https://github.com/swagger-api/apidom/issues/4152)) ([93e2d0f](https://github.com/swagger-api/apidom/commit/93e2d0f7f08add82309843abe991a3013440e5e2)), closes [#4134](https://github.com/swagger-api/apidom/issues/4134)
|
|
42
|
+
|
|
43
|
+
# [1.0.0-alpha.3](https://github.com/swagger-api/apidom/compare/v1.0.0-alpha.2...v1.0.0-alpha.3) (2024-05-21)
|
|
44
|
+
|
|
45
|
+
**Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
|
|
46
|
+
|
|
47
|
+
# [1.0.0-alpha.2](https://github.com/swagger-api/apidom/compare/v1.0.0-alpha.1...v1.0.0-alpha.2) (2024-05-20)
|
|
48
|
+
|
|
49
|
+
### Features
|
|
50
|
+
|
|
51
|
+
- **ast:** add support for mutable node replacements ([#4121](https://github.com/swagger-api/apidom/issues/4121)) ([b37ecd2](https://github.com/swagger-api/apidom/commit/b37ecd2dba83aaa3813bb539ae64e98b290f0292)), closes [#4120](https://github.com/swagger-api/apidom/issues/4120)
|
|
52
|
+
|
|
53
|
+
# [1.0.0-alpha.1](https://github.com/swagger-api/apidom/compare/v1.0.0-alpha.0...v1.0.0-alpha.1) (2024-05-15)
|
|
54
|
+
|
|
55
|
+
**Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
|
|
56
|
+
|
|
6
57
|
# [1.0.0-alpha.0](https://github.com/swagger-api/apidom/compare/v0.99.2...v1.0.0-alpha.0) (2024-05-14)
|
|
7
58
|
|
|
8
59
|
**Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
|
package/cjs/index.cjs
CHANGED
|
@@ -33,8 +33,8 @@ var _normalizeOperationIds = _interopRequireDefault(require("./refractor/plugins
|
|
|
33
33
|
exports.refractorPluginNormalizeOperationIds = _normalizeOperationIds.default;
|
|
34
34
|
var _normalizeParameterExamples = _interopRequireDefault(require("./refractor/plugins/normalize-parameter-examples.cjs"));
|
|
35
35
|
exports.refractorPluginNormalizeParameterExamples = _normalizeParameterExamples.default;
|
|
36
|
-
var
|
|
37
|
-
exports.refractorPluginNormalizeHeaderExamples =
|
|
36
|
+
var _index = _interopRequireDefault(require("./refractor/plugins/normalize-header-examples/index.cjs"));
|
|
37
|
+
exports.refractorPluginNormalizeHeaderExamples = _index.default;
|
|
38
38
|
var _toolbox = _interopRequireDefault(require("./refractor/toolbox.cjs"));
|
|
39
39
|
exports.createToolbox = _toolbox.default;
|
|
40
40
|
var _specification = _interopRequireDefault(require("./refractor/specification.cjs"));
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
var _apidomCore = require("@swagger-api/apidom-core");
|
|
6
|
+
class NormalizeStorage {
|
|
7
|
+
internalStore;
|
|
8
|
+
constructor(storageElement, storageField, storageSubField) {
|
|
9
|
+
this.storageElement = storageElement;
|
|
10
|
+
this.storageField = storageField;
|
|
11
|
+
this.storageSubField = storageSubField;
|
|
12
|
+
}
|
|
13
|
+
get store() {
|
|
14
|
+
if (!this.internalStore) {
|
|
15
|
+
let rootStore = this.storageElement.get(this.storageField);
|
|
16
|
+
if (!(0, _apidomCore.isObjectElement)(rootStore)) {
|
|
17
|
+
rootStore = new _apidomCore.ObjectElement();
|
|
18
|
+
this.storageElement.set(this.storageField, rootStore);
|
|
19
|
+
}
|
|
20
|
+
let store = rootStore.get(this.storageSubField);
|
|
21
|
+
if (!(0, _apidomCore.isArrayElement)(store)) {
|
|
22
|
+
store = new _apidomCore.ArrayElement();
|
|
23
|
+
rootStore.set(this.storageSubField, store);
|
|
24
|
+
}
|
|
25
|
+
this.internalStore = store;
|
|
26
|
+
}
|
|
27
|
+
return this.internalStore;
|
|
28
|
+
}
|
|
29
|
+
append(pointer) {
|
|
30
|
+
if (!this.includes(pointer)) {
|
|
31
|
+
this.store.push(pointer);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
includes(pointer) {
|
|
35
|
+
return this.store.includes(pointer);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
var _default = exports.default = NormalizeStorage;
|
package/cjs/refractor/plugins/{normalize-header-examples.cjs → normalize-header-examples/index.cjs}
RENAMED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
3
4
|
exports.__esModule = true;
|
|
4
5
|
exports.default = void 0;
|
|
5
6
|
var _apidomCore = require("@swagger-api/apidom-core");
|
|
7
|
+
var _NormalizeStorage = _interopRequireDefault(require("./NormalizeStorage.cjs"));
|
|
6
8
|
/**
|
|
7
9
|
* Override of Schema.example and Schema.examples field inside the Header Objects.
|
|
8
10
|
*
|
|
@@ -14,13 +16,28 @@ var _apidomCore = require("@swagger-api/apidom-core");
|
|
|
14
16
|
*
|
|
15
17
|
* The example value SHALL override the example provided by the schema.
|
|
16
18
|
* Furthermore, if referencing a schema that contains an example, the examples value SHALL override the example provided by the schema.
|
|
19
|
+
*
|
|
20
|
+
* NOTE: this plugin is idempotent
|
|
17
21
|
*/
|
|
18
|
-
|
|
19
|
-
const plugin = (
|
|
20
|
-
|
|
21
|
-
}) => {
|
|
22
|
+
|
|
23
|
+
const plugin = ({
|
|
24
|
+
storageField = 'x-normalized'
|
|
25
|
+
} = {}) => toolbox => {
|
|
26
|
+
const {
|
|
27
|
+
predicates,
|
|
28
|
+
ancestorLineageToJSONPointer
|
|
29
|
+
} = toolbox;
|
|
30
|
+
let storage;
|
|
22
31
|
return {
|
|
23
32
|
visitor: {
|
|
33
|
+
OpenApi3_1Element: {
|
|
34
|
+
enter(element) {
|
|
35
|
+
storage = new _NormalizeStorage.default(element, storageField, 'header-examples');
|
|
36
|
+
},
|
|
37
|
+
leave() {
|
|
38
|
+
storage = undefined;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
24
41
|
HeaderElement: {
|
|
25
42
|
leave(headerElement, key, parent, path, ancestors) {
|
|
26
43
|
var _headerElement$schema, _headerElement$schema2;
|
|
@@ -37,6 +54,12 @@ const plugin = () => ({
|
|
|
37
54
|
if (typeof ((_headerElement$schema = headerElement.schema) == null ? void 0 : _headerElement$schema.example) === 'undefined' && typeof ((_headerElement$schema2 = headerElement.schema) == null ? void 0 : _headerElement$schema2.examples) === 'undefined') {
|
|
38
55
|
return;
|
|
39
56
|
}
|
|
57
|
+
const headerJSONPointer = ancestorLineageToJSONPointer([...ancestors, parent, headerElement]);
|
|
58
|
+
|
|
59
|
+
// skip visiting this Header Object if it's already normalized
|
|
60
|
+
if (storage.includes(headerJSONPointer)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
40
63
|
|
|
41
64
|
/**
|
|
42
65
|
* Header.examples and Schema.examples have preferences over the older
|
|
@@ -49,9 +72,11 @@ const plugin = () => ({
|
|
|
49
72
|
});
|
|
50
73
|
if (typeof headerElement.schema.examples !== 'undefined') {
|
|
51
74
|
headerElement.schema.set('examples', examples);
|
|
75
|
+
storage.append(headerJSONPointer);
|
|
52
76
|
}
|
|
53
77
|
if (typeof headerElement.schema.example !== 'undefined') {
|
|
54
|
-
headerElement.schema.set('example', examples);
|
|
78
|
+
headerElement.schema.set('example', examples[0]);
|
|
79
|
+
storage.append(headerJSONPointer);
|
|
55
80
|
}
|
|
56
81
|
return;
|
|
57
82
|
}
|
|
@@ -62,9 +87,11 @@ const plugin = () => ({
|
|
|
62
87
|
if (typeof headerElement.example !== 'undefined') {
|
|
63
88
|
if (typeof headerElement.schema.examples !== 'undefined') {
|
|
64
89
|
headerElement.schema.set('examples', [(0, _apidomCore.cloneDeep)(headerElement.example)]);
|
|
90
|
+
storage.append(headerJSONPointer);
|
|
65
91
|
}
|
|
66
92
|
if (typeof headerElement.schema.example !== 'undefined') {
|
|
67
93
|
headerElement.schema.set('example', (0, _apidomCore.cloneDeep)(headerElement.example));
|
|
94
|
+
storage.append(headerJSONPointer);
|
|
68
95
|
}
|
|
69
96
|
}
|
|
70
97
|
}
|
|
@@ -72,5 +99,4 @@ const plugin = () => ({
|
|
|
72
99
|
}
|
|
73
100
|
};
|
|
74
101
|
};
|
|
75
|
-
/* eslint-enable */
|
|
76
102
|
var _default = exports.default = plugin;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
3
4
|
exports.__esModule = true;
|
|
4
5
|
exports.default = void 0;
|
|
5
6
|
var _ramda = require("ramda");
|
|
6
7
|
var _apidomCore = require("@swagger-api/apidom-core");
|
|
8
|
+
var _NormalizeStorage = _interopRequireDefault(require("./normalize-header-examples/NormalizeStorage.cjs"));
|
|
7
9
|
const removeSpaces = operationId => {
|
|
8
10
|
return operationId.replace(/\s/g, '');
|
|
9
11
|
};
|
|
@@ -37,21 +39,29 @@ const normalizeOperationId = (operationId, path, method) => {
|
|
|
37
39
|
* This plugin also guarantees the uniqueness of all defined Operation.operationId fields,
|
|
38
40
|
* and make sure Link.operationId fields are pointing to correct and normalized Operation.operationId fields.
|
|
39
41
|
*
|
|
42
|
+
* NOTE: this plugin is idempotent
|
|
40
43
|
*/
|
|
41
|
-
/* eslint-disable no-param-reassign */
|
|
42
44
|
|
|
45
|
+
/* eslint-disable no-param-reassign */
|
|
43
46
|
const plugin = ({
|
|
47
|
+
storageField = 'x-normalized',
|
|
44
48
|
operationIdNormalizer = normalizeOperationId
|
|
45
|
-
} = {}) =>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
} = {}) => toolbox => {
|
|
50
|
+
const {
|
|
51
|
+
predicates,
|
|
52
|
+
ancestorLineageToJSONPointer,
|
|
53
|
+
namespace
|
|
54
|
+
} = toolbox;
|
|
55
|
+
const pathTemplates = [];
|
|
50
56
|
const normalizedOperations = [];
|
|
51
57
|
const links = [];
|
|
58
|
+
let storage;
|
|
52
59
|
return {
|
|
53
60
|
visitor: {
|
|
54
61
|
OpenApi3_1Element: {
|
|
62
|
+
enter(element) {
|
|
63
|
+
storage = new _NormalizeStorage.default(element, storageField, 'operation-ids');
|
|
64
|
+
},
|
|
55
65
|
leave() {
|
|
56
66
|
// group normalized operations by normalized operationId
|
|
57
67
|
const normalizedOperationGroups = (0, _ramda.groupBy)(operationElement => {
|
|
@@ -88,30 +98,37 @@ const plugin = ({
|
|
|
88
98
|
// cleanup the references
|
|
89
99
|
normalizedOperations.length = 0;
|
|
90
100
|
links.length = 0;
|
|
101
|
+
storage = undefined;
|
|
91
102
|
}
|
|
92
103
|
},
|
|
93
104
|
PathItemElement: {
|
|
94
105
|
enter(pathItemElement) {
|
|
95
106
|
// `path` meta may not be always available, e.g. in Callback Object or Components Object
|
|
96
|
-
const
|
|
97
|
-
|
|
107
|
+
const pathTemplate = (0, _ramda.defaultTo)('path', (0, _apidomCore.toValue)(pathItemElement.meta.get('path')));
|
|
108
|
+
pathTemplates.push(pathTemplate);
|
|
98
109
|
},
|
|
99
110
|
leave() {
|
|
100
|
-
|
|
111
|
+
pathTemplates.pop();
|
|
101
112
|
}
|
|
102
113
|
},
|
|
103
114
|
OperationElement: {
|
|
104
|
-
enter(operationElement) {
|
|
115
|
+
enter(operationElement, key, parent, path, ancestors) {
|
|
105
116
|
// operationId field is undefined, needs no normalization
|
|
106
117
|
if (typeof operationElement.operationId === 'undefined') return;
|
|
118
|
+
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors, parent, operationElement]);
|
|
119
|
+
|
|
120
|
+
// skip visiting this Operation Object if it's already normalized
|
|
121
|
+
if (storage.includes(operationJSONPointer)) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
107
124
|
|
|
108
125
|
// cast operationId to string type
|
|
109
126
|
const originalOperationId = String((0, _apidomCore.toValue)(operationElement.operationId));
|
|
110
127
|
// perform operationId normalization
|
|
111
|
-
const
|
|
128
|
+
const pathTemplate = (0, _ramda.last)(pathTemplates);
|
|
112
129
|
// `http-method` meta may not be always available, e.g. in Callback Object or Components Object
|
|
113
130
|
const method = (0, _ramda.defaultTo)('method', (0, _apidomCore.toValue)(operationElement.meta.get('http-method')));
|
|
114
|
-
const normalizedOperationId = operationIdNormalizer(originalOperationId,
|
|
131
|
+
const normalizedOperationId = operationIdNormalizer(originalOperationId, pathTemplate, method);
|
|
115
132
|
|
|
116
133
|
// normalization is not necessary
|
|
117
134
|
if (originalOperationId === normalizedOperationId) return;
|
|
@@ -121,6 +138,7 @@ const plugin = ({
|
|
|
121
138
|
operationElement.set('__originalOperationId', originalOperationId);
|
|
122
139
|
operationElement.meta.set('originalOperationId', originalOperationId);
|
|
123
140
|
normalizedOperations.push(operationElement);
|
|
141
|
+
storage.append(operationJSONPointer);
|
|
124
142
|
}
|
|
125
143
|
},
|
|
126
144
|
LinkElement: {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
3
4
|
exports.__esModule = true;
|
|
4
5
|
exports.default = void 0;
|
|
5
6
|
var _apidomCore = require("@swagger-api/apidom-core");
|
|
7
|
+
var _NormalizeStorage = _interopRequireDefault(require("./normalize-header-examples/NormalizeStorage.cjs"));
|
|
6
8
|
/**
|
|
7
9
|
* Override of Schema.example and Schema.examples field inside the Parameter Objects.
|
|
8
10
|
*
|
|
@@ -14,13 +16,28 @@ var _apidomCore = require("@swagger-api/apidom-core");
|
|
|
14
16
|
*
|
|
15
17
|
* The example value SHALL override the example provided by the schema.
|
|
16
18
|
* Furthermore, if referencing a schema that contains an example, the examples value SHALL override the example provided by the schema.
|
|
19
|
+
*
|
|
20
|
+
* NOTE: this plugin is idempotent
|
|
17
21
|
*/
|
|
18
|
-
|
|
19
|
-
const plugin = (
|
|
20
|
-
|
|
21
|
-
}) => {
|
|
22
|
+
|
|
23
|
+
const plugin = ({
|
|
24
|
+
storageField = 'x-normalized'
|
|
25
|
+
} = {}) => toolbox => {
|
|
26
|
+
const {
|
|
27
|
+
predicates,
|
|
28
|
+
ancestorLineageToJSONPointer
|
|
29
|
+
} = toolbox;
|
|
30
|
+
let storage;
|
|
22
31
|
return {
|
|
23
32
|
visitor: {
|
|
33
|
+
OpenApi3_1Element: {
|
|
34
|
+
enter(element) {
|
|
35
|
+
storage = new _NormalizeStorage.default(element, storageField, 'parameter-examples');
|
|
36
|
+
},
|
|
37
|
+
leave() {
|
|
38
|
+
storage = undefined;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
24
41
|
ParameterElement: {
|
|
25
42
|
leave(parameterElement, key, parent, path, ancestors) {
|
|
26
43
|
var _parameterElement$sch, _parameterElement$sch2;
|
|
@@ -37,6 +54,12 @@ const plugin = () => ({
|
|
|
37
54
|
if (typeof ((_parameterElement$sch = parameterElement.schema) == null ? void 0 : _parameterElement$sch.example) === 'undefined' && typeof ((_parameterElement$sch2 = parameterElement.schema) == null ? void 0 : _parameterElement$sch2.examples) === 'undefined') {
|
|
38
55
|
return;
|
|
39
56
|
}
|
|
57
|
+
const parameterJSONPointer = ancestorLineageToJSONPointer([...ancestors, parent, parameterElement]);
|
|
58
|
+
|
|
59
|
+
// skip visiting this Parameter Object if it's already normalized
|
|
60
|
+
if (storage.includes(parameterJSONPointer)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
40
63
|
|
|
41
64
|
/**
|
|
42
65
|
* Parameter.examples and Schema.examples have preferences over the older
|
|
@@ -49,9 +72,11 @@ const plugin = () => ({
|
|
|
49
72
|
});
|
|
50
73
|
if (typeof parameterElement.schema.examples !== 'undefined') {
|
|
51
74
|
parameterElement.schema.set('examples', examples);
|
|
75
|
+
storage.append(parameterJSONPointer);
|
|
52
76
|
}
|
|
53
77
|
if (typeof parameterElement.schema.example !== 'undefined') {
|
|
54
|
-
parameterElement.schema.set('example', examples);
|
|
78
|
+
parameterElement.schema.set('example', examples[0]);
|
|
79
|
+
storage.append(parameterJSONPointer);
|
|
55
80
|
}
|
|
56
81
|
return;
|
|
57
82
|
}
|
|
@@ -62,9 +87,11 @@ const plugin = () => ({
|
|
|
62
87
|
if (typeof parameterElement.example !== 'undefined') {
|
|
63
88
|
if (typeof parameterElement.schema.examples !== 'undefined') {
|
|
64
89
|
parameterElement.schema.set('examples', [(0, _apidomCore.cloneDeep)(parameterElement.example)]);
|
|
90
|
+
storage.append(parameterJSONPointer);
|
|
65
91
|
}
|
|
66
92
|
if (typeof parameterElement.schema.example !== 'undefined') {
|
|
67
93
|
parameterElement.schema.set('example', (0, _apidomCore.cloneDeep)(parameterElement.example));
|
|
94
|
+
storage.append(parameterJSONPointer);
|
|
68
95
|
}
|
|
69
96
|
}
|
|
70
97
|
}
|
|
@@ -72,5 +99,4 @@ const plugin = () => ({
|
|
|
72
99
|
}
|
|
73
100
|
};
|
|
74
101
|
};
|
|
75
|
-
/* eslint-enable */
|
|
76
102
|
var _default = exports.default = plugin;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
3
4
|
exports.__esModule = true;
|
|
4
5
|
exports.default = void 0;
|
|
5
6
|
var _ramda = require("ramda");
|
|
6
7
|
var _apidomCore = require("@swagger-api/apidom-core");
|
|
7
8
|
var _apidomNsOpenapi = require("@swagger-api/apidom-ns-openapi-3-0");
|
|
9
|
+
var _NormalizeStorage = _interopRequireDefault(require("./normalize-header-examples/NormalizeStorage.cjs"));
|
|
8
10
|
/**
|
|
9
11
|
* Inheritance of Parameter Objects.
|
|
10
12
|
*
|
|
@@ -13,11 +15,18 @@ var _apidomNsOpenapi = require("@swagger-api/apidom-ns-openapi-3-0");
|
|
|
13
15
|
* A list of parameters that are applicable for this operation. If a parameter is already defined at the Path Item,
|
|
14
16
|
* the new definition will override it but can never remove it. The list MUST NOT include duplicated parameters.
|
|
15
17
|
* A unique parameter is defined by a combination of a name and location.
|
|
18
|
+
*
|
|
19
|
+
* NOTE: this plugin is idempotent
|
|
16
20
|
*/
|
|
21
|
+
|
|
17
22
|
/* eslint-disable no-param-reassign */
|
|
18
|
-
const plugin = (
|
|
19
|
-
|
|
20
|
-
}) => {
|
|
23
|
+
const plugin = ({
|
|
24
|
+
storageField = 'x-normalized'
|
|
25
|
+
} = {}) => toolbox => {
|
|
26
|
+
const {
|
|
27
|
+
predicates,
|
|
28
|
+
ancestorLineageToJSONPointer
|
|
29
|
+
} = toolbox;
|
|
21
30
|
/**
|
|
22
31
|
* Establishes identity between two Parameter Objects.
|
|
23
32
|
*
|
|
@@ -33,8 +42,17 @@ const plugin = () => ({
|
|
|
33
42
|
return (0, _apidomCore.toValue)(parameter1.name) === (0, _apidomCore.toValue)(parameter2.name) && (0, _apidomCore.toValue)(parameter1.in) === (0, _apidomCore.toValue)(parameter2.in);
|
|
34
43
|
};
|
|
35
44
|
const pathItemParameters = [];
|
|
45
|
+
let storage;
|
|
36
46
|
return {
|
|
37
47
|
visitor: {
|
|
48
|
+
OpenApi3_1Element: {
|
|
49
|
+
enter(element) {
|
|
50
|
+
storage = new _NormalizeStorage.default(element, storageField, 'parameters');
|
|
51
|
+
},
|
|
52
|
+
leave() {
|
|
53
|
+
storage = undefined;
|
|
54
|
+
}
|
|
55
|
+
},
|
|
38
56
|
PathItemElement: {
|
|
39
57
|
enter(pathItemElement, key, parent, path, ancestors) {
|
|
40
58
|
// skip visiting this Path Item
|
|
@@ -55,18 +73,25 @@ const plugin = () => ({
|
|
|
55
73
|
}
|
|
56
74
|
},
|
|
57
75
|
OperationElement: {
|
|
58
|
-
leave(operationElement) {
|
|
76
|
+
leave(operationElement, key, parent, path, ancestors) {
|
|
59
77
|
const parentPathItemParameters = (0, _ramda.last)(pathItemParameters);
|
|
60
78
|
|
|
61
79
|
// no Path Item Object parameters to inherit from
|
|
62
80
|
if (!Array.isArray(parentPathItemParameters) || parentPathItemParameters.length === 0) {
|
|
63
81
|
return;
|
|
64
82
|
}
|
|
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
|
+
}
|
|
65
89
|
const operationParameters = (0, _ramda.pathOr)([], ['parameters', 'content'], operationElement);
|
|
66
90
|
|
|
67
91
|
// prefers the first item if two items compare equal based on the predicate
|
|
68
92
|
const mergedParameters = (0, _ramda.uniqWith)(parameterEquals, [...operationParameters, ...parentPathItemParameters]);
|
|
69
93
|
operationElement.parameters = new _apidomNsOpenapi.OperationParametersElement(mergedParameters);
|
|
94
|
+
storage.append(operationJSONPointer);
|
|
70
95
|
}
|
|
71
96
|
}
|
|
72
97
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
3
4
|
exports.__esModule = true;
|
|
4
5
|
exports.default = void 0;
|
|
5
6
|
var _apidomNsOpenapi = require("@swagger-api/apidom-ns-openapi-3-0");
|
|
7
|
+
var _NormalizeStorage = _interopRequireDefault(require("./normalize-header-examples/NormalizeStorage.cjs"));
|
|
6
8
|
/**
|
|
7
9
|
* Override of Security Requirement Objects.
|
|
8
10
|
*
|
|
@@ -12,22 +14,31 @@ var _apidomNsOpenapi = require("@swagger-api/apidom-ns-openapi-3-0");
|
|
|
12
14
|
* To remove a top-level security declaration, an empty array can be used.
|
|
13
15
|
* When a list of Security Requirement Objects is defined on the OpenAPI Object or Operation Object,
|
|
14
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
|
|
15
19
|
*/
|
|
16
20
|
|
|
17
21
|
/* eslint-disable no-param-reassign */
|
|
18
|
-
const plugin = (
|
|
19
|
-
|
|
20
|
-
}) => {
|
|
22
|
+
const plugin = ({
|
|
23
|
+
storageField = 'x-normalized'
|
|
24
|
+
} = {}) => toolbox => {
|
|
25
|
+
const {
|
|
26
|
+
predicates,
|
|
27
|
+
ancestorLineageToJSONPointer
|
|
28
|
+
} = toolbox;
|
|
21
29
|
let topLevelSecurity;
|
|
30
|
+
let storage;
|
|
22
31
|
return {
|
|
23
32
|
visitor: {
|
|
24
33
|
OpenApi3_1Element: {
|
|
25
34
|
enter(openapiElement) {
|
|
35
|
+
storage = new _NormalizeStorage.default(openapiElement, storageField, 'security-requirements');
|
|
26
36
|
if (predicates.isArrayElement(openapiElement.security)) {
|
|
27
37
|
topLevelSecurity = openapiElement.security;
|
|
28
38
|
}
|
|
29
39
|
},
|
|
30
40
|
leave() {
|
|
41
|
+
storage = undefined;
|
|
31
42
|
topLevelSecurity = undefined;
|
|
32
43
|
}
|
|
33
44
|
},
|
|
@@ -37,11 +48,18 @@ const plugin = () => ({
|
|
|
37
48
|
if (ancestors.some(predicates.isComponentsElement)) {
|
|
38
49
|
return;
|
|
39
50
|
}
|
|
51
|
+
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors, parent, operationElement]);
|
|
52
|
+
|
|
53
|
+
// skip visiting this Operation Object if it's already normalized
|
|
54
|
+
if (storage.includes(operationJSONPointer)) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
40
57
|
const missingOperationLevelSecurity = typeof operationElement.security === 'undefined';
|
|
41
58
|
const hasTopLevelSecurity = typeof topLevelSecurity !== 'undefined';
|
|
42
59
|
if (missingOperationLevelSecurity && hasTopLevelSecurity) {
|
|
43
60
|
var _topLevelSecurity;
|
|
44
61
|
operationElement.security = new _apidomNsOpenapi.OperationSecurityElement((_topLevelSecurity = topLevelSecurity) == null ? void 0 : _topLevelSecurity.content);
|
|
62
|
+
storage.append(operationJSONPointer);
|
|
45
63
|
}
|
|
46
64
|
}
|
|
47
65
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
3
4
|
exports.__esModule = true;
|
|
4
5
|
exports.default = void 0;
|
|
5
6
|
var _apidomNsOpenapi = require("@swagger-api/apidom-ns-openapi-3-0");
|
|
7
|
+
var _NormalizeStorage = _interopRequireDefault(require("./normalize-header-examples/NormalizeStorage.cjs"));
|
|
6
8
|
/**
|
|
7
9
|
* Override of Server Objects.
|
|
8
10
|
*
|
|
@@ -17,30 +19,47 @@ var _apidomNsOpenapi = require("@swagger-api/apidom-ns-openapi-3-0");
|
|
|
17
19
|
*/
|
|
18
20
|
|
|
19
21
|
/* eslint-disable no-param-reassign */
|
|
20
|
-
const plugin = (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const plugin = ({
|
|
23
|
+
storageField = 'x-normalized'
|
|
24
|
+
} = {}) => toolbox => {
|
|
25
|
+
const {
|
|
26
|
+
namespace,
|
|
27
|
+
ancestorLineageToJSONPointer,
|
|
28
|
+
predicates
|
|
29
|
+
} = toolbox;
|
|
30
|
+
let storage;
|
|
24
31
|
return {
|
|
25
32
|
visitor: {
|
|
26
|
-
OpenApi3_1Element
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
OpenApi3_1Element: {
|
|
34
|
+
enter(openapiElement) {
|
|
35
|
+
const isServersUndefined = typeof openapiElement.servers === 'undefined';
|
|
36
|
+
const isServersArrayElement = predicates.isArrayElement(openapiElement.servers);
|
|
37
|
+
const isServersEmpty = isServersArrayElement && openapiElement.servers.length === 0;
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
const defaultServer = namespace.elements.Server.refract({
|
|
40
|
+
url: '/'
|
|
41
|
+
});
|
|
42
|
+
if (isServersUndefined || !isServersArrayElement) {
|
|
43
|
+
openapiElement.servers = new _apidomNsOpenapi.ServersElement([defaultServer]);
|
|
44
|
+
} else if (isServersArrayElement && isServersEmpty) {
|
|
45
|
+
openapiElement.servers.push(defaultServer);
|
|
46
|
+
}
|
|
47
|
+
storage = new _NormalizeStorage.default(openapiElement, storageField, 'servers');
|
|
48
|
+
},
|
|
49
|
+
leave() {
|
|
50
|
+
storage = undefined;
|
|
38
51
|
}
|
|
39
52
|
},
|
|
40
53
|
PathItemElement(pathItemElement, key, parent, path, ancestors) {
|
|
41
54
|
// skip visiting this Path Item
|
|
42
55
|
if (ancestors.some(predicates.isComponentsElement)) return;
|
|
43
56
|
if (!ancestors.some(predicates.isOpenApi3_1Element)) return;
|
|
57
|
+
const pathItemJSONPointer = ancestorLineageToJSONPointer([...ancestors, parent, pathItemElement]);
|
|
58
|
+
|
|
59
|
+
// skip visiting this Path Item Object if it's already normalized
|
|
60
|
+
if (storage.includes(pathItemJSONPointer)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
44
63
|
const parentOpenapiElement = ancestors.find(predicates.isOpenApi3_1Element);
|
|
45
64
|
const isServersUndefined = typeof pathItemElement.servers === 'undefined';
|
|
46
65
|
const isServersArrayElement = predicates.isArrayElement(pathItemElement.servers);
|
|
@@ -58,12 +77,19 @@ const plugin = () => ({
|
|
|
58
77
|
pathItemElement.servers.push(server);
|
|
59
78
|
});
|
|
60
79
|
}
|
|
80
|
+
storage.append(pathItemJSONPointer);
|
|
61
81
|
}
|
|
62
82
|
},
|
|
63
83
|
OperationElement(operationElement, key, parent, path, ancestors) {
|
|
64
84
|
// skip visiting this Operation
|
|
65
85
|
if (ancestors.some(predicates.isComponentsElement)) return;
|
|
66
86
|
if (!ancestors.some(predicates.isOpenApi3_1Element)) return;
|
|
87
|
+
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors, parent, operationElement]);
|
|
88
|
+
|
|
89
|
+
// skip visiting this Operation Object if it's already normalized
|
|
90
|
+
if (storage.includes(operationJSONPointer)) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
67
93
|
|
|
68
94
|
// @TODO(vladimir.gorej@gmail.com): can be replaced by Array.prototype.findLast in future
|
|
69
95
|
const parentPathItemElement = [...ancestors].reverse().find(predicates.isPathItemElement);
|
|
@@ -82,6 +108,7 @@ const plugin = () => ({
|
|
|
82
108
|
operationElement.servers.push(server);
|
|
83
109
|
});
|
|
84
110
|
}
|
|
111
|
+
storage.append(operationJSONPointer);
|
|
85
112
|
}
|
|
86
113
|
}
|
|
87
114
|
}
|
|
@@ -5,9 +5,31 @@ var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopReq
|
|
|
5
5
|
exports.__esModule = true;
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _apidomCore = require("@swagger-api/apidom-core");
|
|
8
|
+
var _apidomJsonPointer = require("@swagger-api/apidom-json-pointer");
|
|
8
9
|
var _apidomNsOpenapi = require("@swagger-api/apidom-ns-openapi-3-0");
|
|
9
10
|
var openApi3_1Predicates = _interopRequireWildcard(require("../predicates.cjs"));
|
|
10
11
|
var _namespace = _interopRequireDefault(require("../namespace.cjs"));
|
|
12
|
+
/**
|
|
13
|
+
* Translates visitor ancestor lineage to a JSON Pointer tokens.
|
|
14
|
+
* Ancestor lineage is constructed of following visitor method arguments:
|
|
15
|
+
*
|
|
16
|
+
* - ancestors
|
|
17
|
+
* - parent
|
|
18
|
+
* - element
|
|
19
|
+
*/
|
|
20
|
+
const ancestorLineageToJSONPointer = elementPath => {
|
|
21
|
+
const jsonPointerTokens = elementPath.reduce((path, element, index) => {
|
|
22
|
+
if ((0, _apidomCore.isMemberElement)(element)) {
|
|
23
|
+
const token = String((0, _apidomCore.toValue)(element.key));
|
|
24
|
+
path.push(token);
|
|
25
|
+
} else if ((0, _apidomCore.isArrayElement)(elementPath[index - 2])) {
|
|
26
|
+
const token = String(elementPath[index - 2].content.indexOf(element));
|
|
27
|
+
path.push(token);
|
|
28
|
+
}
|
|
29
|
+
return path;
|
|
30
|
+
}, []);
|
|
31
|
+
return (0, _apidomJsonPointer.compile)(jsonPointerTokens);
|
|
32
|
+
};
|
|
11
33
|
const createToolbox = () => {
|
|
12
34
|
const namespace = (0, _apidomCore.createNamespace)(_namespace.default);
|
|
13
35
|
const predicates = {
|
|
@@ -23,6 +45,7 @@ const createToolbox = () => {
|
|
|
23
45
|
};
|
|
24
46
|
return {
|
|
25
47
|
predicates,
|
|
48
|
+
ancestorLineageToJSONPointer,
|
|
26
49
|
namespace
|
|
27
50
|
};
|
|
28
51
|
};
|