@speclynx/apidom-ns-openapi-3-1 1.12.1 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/NOTICE +16 -7
- package/README.md +16 -29
- package/dist/apidom-ns-openapi-3-1.browser.js +11148 -16196
- package/dist/apidom-ns-openapi-3-1.browser.min.js +1 -1
- package/package.json +11 -11
- package/src/elements/JsonSchemaDialect.cjs +2 -2
- package/src/elements/JsonSchemaDialect.mjs +1 -1
- package/src/elements/OpenApi3-1.cjs +2 -2
- package/src/elements/OpenApi3-1.mjs +1 -1
- package/src/elements/PathItem.cjs +24 -24
- package/src/elements/PathItem.mjs +24 -24
- package/src/elements/nces/ComponentsPathItems.cjs +2 -2
- package/src/elements/nces/ComponentsPathItems.mjs +1 -1
- package/src/elements/nces/Webhooks.cjs +2 -2
- package/src/elements/nces/Webhooks.mjs +1 -1
- package/src/index.cjs +73 -49
- package/src/index.mjs +6 -3
- package/src/namespace.cjs +0 -1
- package/src/predicates.cjs +56 -187
- package/src/predicates.mjs +29 -186
- package/src/refractor/index.cjs +338 -17
- package/src/refractor/index.mjs +305 -16
- package/src/refractor/inspect.cjs +207 -0
- package/src/refractor/inspect.mjs +171 -0
- package/src/refractor/plugins/normalize-header-examples/NormalizeStorage.cjs +5 -5
- package/src/refractor/plugins/normalize-header-examples/NormalizeStorage.mjs +1 -1
- package/src/refractor/plugins/normalize-header-examples/index.cjs +11 -7
- package/src/refractor/plugins/normalize-header-examples/index.mjs +8 -4
- package/src/refractor/plugins/normalize-operation-ids.cjs +13 -6
- package/src/refractor/plugins/normalize-operation-ids.mjs +13 -6
- package/src/refractor/plugins/normalize-parameter-examples.cjs +11 -7
- package/src/refractor/plugins/normalize-parameter-examples.mjs +8 -4
- package/src/refractor/plugins/normalize-parameters.cjs +11 -5
- package/src/refractor/plugins/normalize-parameters.mjs +11 -5
- package/src/refractor/plugins/normalize-security-requirements.cjs +8 -4
- package/src/refractor/plugins/normalize-security-requirements.mjs +8 -4
- package/src/refractor/plugins/normalize-servers.cjs +15 -9
- package/src/refractor/plugins/normalize-servers.mjs +15 -9
- package/src/refractor/plugins/replace-empty-element.cjs +32 -30
- package/src/refractor/plugins/replace-empty-element.mjs +16 -15
- package/src/refractor/predicates.cjs +36 -0
- package/src/refractor/predicates.mjs +31 -0
- package/src/refractor/specification.cjs +43 -4
- package/src/refractor/specification.mjs +43 -4
- package/src/refractor/toolbox.cjs +12 -21
- package/src/refractor/toolbox.mjs +9 -16
- package/src/refractor/visitors/open-api-3-1/JsonSchemaDialectVisitor.cjs +5 -5
- package/src/refractor/visitors/open-api-3-1/JsonSchemaDialectVisitor.mjs +6 -6
- package/src/refractor/visitors/open-api-3-1/OpenapiVisitor.cjs +25 -0
- package/src/refractor/visitors/open-api-3-1/OpenapiVisitor.mjs +19 -0
- package/src/refractor/visitors/open-api-3-1/WebhooksVisitor.cjs +4 -5
- package/src/refractor/visitors/open-api-3-1/WebhooksVisitor.mjs +5 -6
- package/src/refractor/visitors/open-api-3-1/bases.cjs +46 -0
- package/src/refractor/visitors/open-api-3-1/bases.mjs +43 -0
- package/src/refractor/visitors/open-api-3-1/callback/index.cjs +2 -3
- package/src/refractor/visitors/open-api-3-1/callback/index.mjs +2 -3
- package/src/refractor/visitors/open-api-3-1/components/PathItemsVisitor.cjs +4 -5
- package/src/refractor/visitors/open-api-3-1/components/PathItemsVisitor.mjs +5 -6
- package/src/refractor/visitors/open-api-3-1/components/SchemasVisitor.cjs +2 -2
- package/src/refractor/visitors/open-api-3-1/components/SchemasVisitor.mjs +3 -5
- package/src/refractor/visitors/open-api-3-1/index.cjs +5 -4
- package/src/refractor/visitors/open-api-3-1/index.mjs +6 -5
- package/src/refractor/visitors/open-api-3-1/schema/index.cjs +11 -10
- package/src/refractor/visitors/open-api-3-1/schema/index.mjs +12 -11
- package/types/apidom-ns-openapi-3-1.d.ts +435 -274
- package/src/refractor/registration.cjs +0 -102
- package/src/refractor/registration.mjs +0 -66
- package/src/traversal/visitor.cjs +0 -57
- package/src/traversal/visitor.mjs +0 -54
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
4
|
exports.__esModule = true;
|
|
5
5
|
exports.default = void 0;
|
|
6
|
-
var
|
|
6
|
+
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
7
7
|
var _NormalizeStorage = _interopRequireDefault(require("./normalize-header-examples/NormalizeStorage.cjs"));
|
|
8
8
|
/**
|
|
9
9
|
* Override of Schema.example and Schema.examples field inside the Parameter Objects.
|
|
@@ -35,7 +35,8 @@ const plugin = ({
|
|
|
35
35
|
return {
|
|
36
36
|
visitor: {
|
|
37
37
|
OpenApi3_1Element: {
|
|
38
|
-
enter(
|
|
38
|
+
enter(path) {
|
|
39
|
+
const element = path.node;
|
|
39
40
|
storage = new _NormalizeStorage.default(element, storageField, 'parameter-examples');
|
|
40
41
|
},
|
|
41
42
|
leave() {
|
|
@@ -43,7 +44,10 @@ const plugin = ({
|
|
|
43
44
|
}
|
|
44
45
|
},
|
|
45
46
|
ParameterElement: {
|
|
46
|
-
leave(
|
|
47
|
+
leave(path) {
|
|
48
|
+
const parameterElement = path.node;
|
|
49
|
+
const ancestors = path.getAncestorNodes().reverse(); // root to parent order
|
|
50
|
+
|
|
47
51
|
// skip visiting this Parameter Object
|
|
48
52
|
if (ancestors.some(predicates.isComponentsElement)) {
|
|
49
53
|
return;
|
|
@@ -57,7 +61,7 @@ const plugin = ({
|
|
|
57
61
|
if (typeof parameterElement.schema?.example === 'undefined' && typeof parameterElement.schema?.examples === 'undefined') {
|
|
58
62
|
return;
|
|
59
63
|
}
|
|
60
|
-
const parameterJSONPointer = ancestorLineageToJSONPointer([...ancestors,
|
|
64
|
+
const parameterJSONPointer = ancestorLineageToJSONPointer([...ancestors, parameterElement]);
|
|
61
65
|
|
|
62
66
|
// skip visiting this Parameter Object if it's already normalized
|
|
63
67
|
if (storage.includes(parameterJSONPointer)) {
|
|
@@ -71,7 +75,7 @@ const plugin = ({
|
|
|
71
75
|
if (typeof parameterElement.examples !== 'undefined' && predicates.isObjectElement(parameterElement.examples)) {
|
|
72
76
|
// @ts-ignore
|
|
73
77
|
const examples = parameterElement.examples.map(example => {
|
|
74
|
-
return
|
|
78
|
+
return _apidomDatamodel.cloneDeep.safe(example.value);
|
|
75
79
|
});
|
|
76
80
|
if (typeof parameterElement.schema.examples !== 'undefined') {
|
|
77
81
|
parameterElement.schema.set('examples', examples);
|
|
@@ -89,11 +93,11 @@ const plugin = ({
|
|
|
89
93
|
*/
|
|
90
94
|
if (typeof parameterElement.example !== 'undefined') {
|
|
91
95
|
if (typeof parameterElement.schema.examples !== 'undefined') {
|
|
92
|
-
parameterElement.schema.set('examples', [(0,
|
|
96
|
+
parameterElement.schema.set('examples', [(0, _apidomDatamodel.cloneDeep)(parameterElement.example)]);
|
|
93
97
|
storage.append(parameterJSONPointer);
|
|
94
98
|
}
|
|
95
99
|
if (typeof parameterElement.schema.example !== 'undefined') {
|
|
96
|
-
parameterElement.schema.set('example', (0,
|
|
100
|
+
parameterElement.schema.set('example', (0, _apidomDatamodel.cloneDeep)(parameterElement.example));
|
|
97
101
|
storage.append(parameterJSONPointer);
|
|
98
102
|
}
|
|
99
103
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cloneDeep } from '@speclynx/apidom-
|
|
1
|
+
import { cloneDeep } from '@speclynx/apidom-datamodel';
|
|
2
2
|
import NormalizeStorage from "./normalize-header-examples/NormalizeStorage.mjs";
|
|
3
3
|
/**
|
|
4
4
|
* Override of Schema.example and Schema.examples field inside the Parameter Objects.
|
|
@@ -29,7 +29,8 @@ const plugin = ({
|
|
|
29
29
|
return {
|
|
30
30
|
visitor: {
|
|
31
31
|
OpenApi3_1Element: {
|
|
32
|
-
enter(
|
|
32
|
+
enter(path) {
|
|
33
|
+
const element = path.node;
|
|
33
34
|
storage = new NormalizeStorage(element, storageField, 'parameter-examples');
|
|
34
35
|
},
|
|
35
36
|
leave() {
|
|
@@ -37,7 +38,10 @@ const plugin = ({
|
|
|
37
38
|
}
|
|
38
39
|
},
|
|
39
40
|
ParameterElement: {
|
|
40
|
-
leave(
|
|
41
|
+
leave(path) {
|
|
42
|
+
const parameterElement = path.node;
|
|
43
|
+
const ancestors = path.getAncestorNodes().reverse(); // root to parent order
|
|
44
|
+
|
|
41
45
|
// skip visiting this Parameter Object
|
|
42
46
|
if (ancestors.some(predicates.isComponentsElement)) {
|
|
43
47
|
return;
|
|
@@ -51,7 +55,7 @@ const plugin = ({
|
|
|
51
55
|
if (typeof parameterElement.schema?.example === 'undefined' && typeof parameterElement.schema?.examples === 'undefined') {
|
|
52
56
|
return;
|
|
53
57
|
}
|
|
54
|
-
const parameterJSONPointer = ancestorLineageToJSONPointer([...ancestors,
|
|
58
|
+
const parameterJSONPointer = ancestorLineageToJSONPointer([...ancestors, parameterElement]);
|
|
55
59
|
|
|
56
60
|
// skip visiting this Parameter Object if it's already normalized
|
|
57
61
|
if (storage.includes(parameterJSONPointer)) {
|
|
@@ -49,7 +49,8 @@ const plugin = ({
|
|
|
49
49
|
return {
|
|
50
50
|
visitor: {
|
|
51
51
|
OpenApi3_1Element: {
|
|
52
|
-
enter(
|
|
52
|
+
enter(path) {
|
|
53
|
+
const element = path.node;
|
|
53
54
|
storage = new _NormalizeStorage.default(element, storageField, 'parameters');
|
|
54
55
|
},
|
|
55
56
|
leave() {
|
|
@@ -57,7 +58,10 @@ const plugin = ({
|
|
|
57
58
|
}
|
|
58
59
|
},
|
|
59
60
|
PathItemElement: {
|
|
60
|
-
enter(
|
|
61
|
+
enter(path) {
|
|
62
|
+
const pathItemElement = path.node;
|
|
63
|
+
const ancestors = path.getAncestorNodes().reverse(); // root to parent order
|
|
64
|
+
|
|
61
65
|
// skip visiting this Path Item
|
|
62
66
|
if (ancestors.some(predicates.isComponentsElement)) {
|
|
63
67
|
return;
|
|
@@ -66,7 +70,7 @@ const plugin = ({
|
|
|
66
70
|
parameters
|
|
67
71
|
} = pathItemElement;
|
|
68
72
|
if (predicates.isArrayElement(parameters)) {
|
|
69
|
-
pathItemParameters.push([...parameters.content]);
|
|
73
|
+
pathItemParameters.push([...(parameters.content ?? [])]);
|
|
70
74
|
} else {
|
|
71
75
|
pathItemParameters.push([]);
|
|
72
76
|
}
|
|
@@ -76,14 +80,16 @@ const plugin = ({
|
|
|
76
80
|
}
|
|
77
81
|
},
|
|
78
82
|
OperationElement: {
|
|
79
|
-
leave(
|
|
83
|
+
leave(path) {
|
|
84
|
+
const operationElement = path.node;
|
|
85
|
+
const ancestors = path.getAncestorNodes().reverse(); // root to parent order
|
|
80
86
|
const parentPathItemParameters = (0, _ramda.last)(pathItemParameters);
|
|
81
87
|
|
|
82
88
|
// no Path Item Object parameters to inherit from
|
|
83
89
|
if (!Array.isArray(parentPathItemParameters) || parentPathItemParameters.length === 0) {
|
|
84
90
|
return;
|
|
85
91
|
}
|
|
86
|
-
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors,
|
|
92
|
+
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors, operationElement]);
|
|
87
93
|
|
|
88
94
|
// skip visiting this Operation Object if it's already normalized
|
|
89
95
|
if (storage.includes(operationJSONPointer)) {
|
|
@@ -43,7 +43,8 @@ const plugin = ({
|
|
|
43
43
|
return {
|
|
44
44
|
visitor: {
|
|
45
45
|
OpenApi3_1Element: {
|
|
46
|
-
enter(
|
|
46
|
+
enter(path) {
|
|
47
|
+
const element = path.node;
|
|
47
48
|
storage = new NormalizeStorage(element, storageField, 'parameters');
|
|
48
49
|
},
|
|
49
50
|
leave() {
|
|
@@ -51,7 +52,10 @@ const plugin = ({
|
|
|
51
52
|
}
|
|
52
53
|
},
|
|
53
54
|
PathItemElement: {
|
|
54
|
-
enter(
|
|
55
|
+
enter(path) {
|
|
56
|
+
const pathItemElement = path.node;
|
|
57
|
+
const ancestors = path.getAncestorNodes().reverse(); // root to parent order
|
|
58
|
+
|
|
55
59
|
// skip visiting this Path Item
|
|
56
60
|
if (ancestors.some(predicates.isComponentsElement)) {
|
|
57
61
|
return;
|
|
@@ -60,7 +64,7 @@ const plugin = ({
|
|
|
60
64
|
parameters
|
|
61
65
|
} = pathItemElement;
|
|
62
66
|
if (predicates.isArrayElement(parameters)) {
|
|
63
|
-
pathItemParameters.push([...parameters.content]);
|
|
67
|
+
pathItemParameters.push([...(parameters.content ?? [])]);
|
|
64
68
|
} else {
|
|
65
69
|
pathItemParameters.push([]);
|
|
66
70
|
}
|
|
@@ -70,14 +74,16 @@ const plugin = ({
|
|
|
70
74
|
}
|
|
71
75
|
},
|
|
72
76
|
OperationElement: {
|
|
73
|
-
leave(
|
|
77
|
+
leave(path) {
|
|
78
|
+
const operationElement = path.node;
|
|
79
|
+
const ancestors = path.getAncestorNodes().reverse(); // root to parent order
|
|
74
80
|
const parentPathItemParameters = last(pathItemParameters);
|
|
75
81
|
|
|
76
82
|
// no Path Item Object parameters to inherit from
|
|
77
83
|
if (!Array.isArray(parentPathItemParameters) || parentPathItemParameters.length === 0) {
|
|
78
84
|
return;
|
|
79
85
|
}
|
|
80
|
-
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors,
|
|
86
|
+
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors, operationElement]);
|
|
81
87
|
|
|
82
88
|
// skip visiting this Operation Object if it's already normalized
|
|
83
89
|
if (storage.includes(operationJSONPointer)) {
|
|
@@ -34,7 +34,8 @@ const plugin = ({
|
|
|
34
34
|
return {
|
|
35
35
|
visitor: {
|
|
36
36
|
OpenApi3_1Element: {
|
|
37
|
-
enter(
|
|
37
|
+
enter(path) {
|
|
38
|
+
const openapiElement = path.node;
|
|
38
39
|
storage = new _NormalizeStorage.default(openapiElement, storageField, 'security-requirements');
|
|
39
40
|
if (predicates.isArrayElement(openapiElement.security)) {
|
|
40
41
|
topLevelSecurity = openapiElement.security;
|
|
@@ -46,12 +47,15 @@ const plugin = ({
|
|
|
46
47
|
}
|
|
47
48
|
},
|
|
48
49
|
OperationElement: {
|
|
49
|
-
leave(
|
|
50
|
+
leave(path) {
|
|
51
|
+
const operationElement = path.node;
|
|
52
|
+
const ancestors = path.getAncestorNodes().reverse(); // root to parent order
|
|
53
|
+
|
|
50
54
|
// skip visiting this Operation
|
|
51
55
|
if (ancestors.some(predicates.isComponentsElement)) {
|
|
52
56
|
return;
|
|
53
57
|
}
|
|
54
|
-
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors,
|
|
58
|
+
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors, operationElement]);
|
|
55
59
|
|
|
56
60
|
// skip visiting this Operation Object if it's already normalized
|
|
57
61
|
if (storage.includes(operationJSONPointer)) {
|
|
@@ -60,7 +64,7 @@ const plugin = ({
|
|
|
60
64
|
const missingOperationLevelSecurity = typeof operationElement.security === 'undefined';
|
|
61
65
|
const hasTopLevelSecurity = typeof topLevelSecurity !== 'undefined';
|
|
62
66
|
if (missingOperationLevelSecurity && hasTopLevelSecurity) {
|
|
63
|
-
operationElement.security = new _apidomNsOpenapi.OperationSecurityElement(topLevelSecurity?.content);
|
|
67
|
+
operationElement.security = new _apidomNsOpenapi.OperationSecurityElement(topLevelSecurity?.content ?? undefined);
|
|
64
68
|
storage.append(operationJSONPointer);
|
|
65
69
|
}
|
|
66
70
|
}
|
|
@@ -28,7 +28,8 @@ const plugin = ({
|
|
|
28
28
|
return {
|
|
29
29
|
visitor: {
|
|
30
30
|
OpenApi3_1Element: {
|
|
31
|
-
enter(
|
|
31
|
+
enter(path) {
|
|
32
|
+
const openapiElement = path.node;
|
|
32
33
|
storage = new NormalizeStorage(openapiElement, storageField, 'security-requirements');
|
|
33
34
|
if (predicates.isArrayElement(openapiElement.security)) {
|
|
34
35
|
topLevelSecurity = openapiElement.security;
|
|
@@ -40,12 +41,15 @@ const plugin = ({
|
|
|
40
41
|
}
|
|
41
42
|
},
|
|
42
43
|
OperationElement: {
|
|
43
|
-
leave(
|
|
44
|
+
leave(path) {
|
|
45
|
+
const operationElement = path.node;
|
|
46
|
+
const ancestors = path.getAncestorNodes().reverse(); // root to parent order
|
|
47
|
+
|
|
44
48
|
// skip visiting this Operation
|
|
45
49
|
if (ancestors.some(predicates.isComponentsElement)) {
|
|
46
50
|
return;
|
|
47
51
|
}
|
|
48
|
-
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors,
|
|
52
|
+
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors, operationElement]);
|
|
49
53
|
|
|
50
54
|
// skip visiting this Operation Object if it's already normalized
|
|
51
55
|
if (storage.includes(operationJSONPointer)) {
|
|
@@ -54,7 +58,7 @@ const plugin = ({
|
|
|
54
58
|
const missingOperationLevelSecurity = typeof operationElement.security === 'undefined';
|
|
55
59
|
const hasTopLevelSecurity = typeof topLevelSecurity !== 'undefined';
|
|
56
60
|
if (missingOperationLevelSecurity && hasTopLevelSecurity) {
|
|
57
|
-
operationElement.security = new OperationSecurityElement(topLevelSecurity?.content);
|
|
61
|
+
operationElement.security = new OperationSecurityElement(topLevelSecurity?.content ?? undefined);
|
|
58
62
|
storage.append(operationJSONPointer);
|
|
59
63
|
}
|
|
60
64
|
}
|
|
@@ -5,6 +5,7 @@ exports.__esModule = true;
|
|
|
5
5
|
exports.default = void 0;
|
|
6
6
|
var _apidomNsOpenapi = require("@speclynx/apidom-ns-openapi-3-0");
|
|
7
7
|
var _NormalizeStorage = _interopRequireDefault(require("./normalize-header-examples/NormalizeStorage.cjs"));
|
|
8
|
+
var _index = require("../index.cjs");
|
|
8
9
|
/**
|
|
9
10
|
* Override of Server Objects.
|
|
10
11
|
*
|
|
@@ -26,7 +27,6 @@ const plugin = ({
|
|
|
26
27
|
storageField = 'x-normalized'
|
|
27
28
|
} = {}) => toolbox => {
|
|
28
29
|
const {
|
|
29
|
-
namespace,
|
|
30
30
|
ancestorLineageToJSONPointer,
|
|
31
31
|
predicates
|
|
32
32
|
} = toolbox;
|
|
@@ -34,12 +34,12 @@ const plugin = ({
|
|
|
34
34
|
return {
|
|
35
35
|
visitor: {
|
|
36
36
|
OpenApi3_1Element: {
|
|
37
|
-
enter(
|
|
37
|
+
enter(path) {
|
|
38
|
+
const openapiElement = path.node;
|
|
38
39
|
const isServersUndefined = typeof openapiElement.servers === 'undefined';
|
|
39
40
|
const isServersArrayElement = predicates.isArrayElement(openapiElement.servers);
|
|
40
41
|
const isServersEmpty = isServersArrayElement && openapiElement.servers.length === 0;
|
|
41
|
-
|
|
42
|
-
const defaultServer = namespace.elements.Server.refract({
|
|
42
|
+
const defaultServer = (0, _index.refractServer)({
|
|
43
43
|
url: '/'
|
|
44
44
|
});
|
|
45
45
|
if (isServersUndefined || !isServersArrayElement) {
|
|
@@ -53,11 +53,14 @@ const plugin = ({
|
|
|
53
53
|
storage = undefined;
|
|
54
54
|
}
|
|
55
55
|
},
|
|
56
|
-
PathItemElement(
|
|
56
|
+
PathItemElement(path) {
|
|
57
|
+
const pathItemElement = path.node;
|
|
58
|
+
const ancestors = path.getAncestorNodes().reverse(); // root to parent order
|
|
59
|
+
|
|
57
60
|
// skip visiting this Path Item
|
|
58
61
|
if (ancestors.some(predicates.isComponentsElement)) return;
|
|
59
62
|
if (!ancestors.some(predicates.isOpenApi3_1Element)) return;
|
|
60
|
-
const pathItemJSONPointer = ancestorLineageToJSONPointer([...ancestors,
|
|
63
|
+
const pathItemJSONPointer = ancestorLineageToJSONPointer([...ancestors, pathItemElement]);
|
|
61
64
|
|
|
62
65
|
// skip visiting this Path Item Object if it's already normalized
|
|
63
66
|
if (storage.includes(pathItemJSONPointer)) {
|
|
@@ -82,11 +85,14 @@ const plugin = ({
|
|
|
82
85
|
storage.append(pathItemJSONPointer);
|
|
83
86
|
}
|
|
84
87
|
},
|
|
85
|
-
OperationElement(
|
|
88
|
+
OperationElement(path) {
|
|
89
|
+
const operationElement = path.node;
|
|
90
|
+
const ancestors = path.getAncestorNodes().reverse(); // root to parent order
|
|
91
|
+
|
|
86
92
|
// skip visiting this Operation
|
|
87
93
|
if (ancestors.some(predicates.isComponentsElement)) return;
|
|
88
94
|
if (!ancestors.some(predicates.isOpenApi3_1Element)) return;
|
|
89
|
-
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors,
|
|
95
|
+
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors, operationElement]);
|
|
90
96
|
|
|
91
97
|
// skip visiting this Operation Object if it's already normalized
|
|
92
98
|
if (storage.includes(operationJSONPointer)) {
|
|
@@ -94,7 +100,7 @@ const plugin = ({
|
|
|
94
100
|
}
|
|
95
101
|
|
|
96
102
|
// @TODO(vladimir.gorej@gmail.com): can be replaced by Array.prototype.findLast in future
|
|
97
|
-
const parentPathItemElement =
|
|
103
|
+
const parentPathItemElement = ancestors.findLast(predicates.isPathItemElement);
|
|
98
104
|
const isServersUndefined = typeof operationElement.servers === 'undefined';
|
|
99
105
|
const isServersArrayElement = predicates.isArrayElement(operationElement.servers);
|
|
100
106
|
const isServersEmpty = isServersArrayElement && operationElement.servers.length === 0;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PathItemServersElement, OperationServersElement, ServersElement } from '@speclynx/apidom-ns-openapi-3-0';
|
|
2
2
|
import NormalizeStorage from "./normalize-header-examples/NormalizeStorage.mjs";
|
|
3
|
+
import { refractServer } from "../index.mjs";
|
|
3
4
|
/**
|
|
4
5
|
* Override of Server Objects.
|
|
5
6
|
*
|
|
@@ -20,7 +21,6 @@ const plugin = ({
|
|
|
20
21
|
storageField = 'x-normalized'
|
|
21
22
|
} = {}) => toolbox => {
|
|
22
23
|
const {
|
|
23
|
-
namespace,
|
|
24
24
|
ancestorLineageToJSONPointer,
|
|
25
25
|
predicates
|
|
26
26
|
} = toolbox;
|
|
@@ -28,12 +28,12 @@ const plugin = ({
|
|
|
28
28
|
return {
|
|
29
29
|
visitor: {
|
|
30
30
|
OpenApi3_1Element: {
|
|
31
|
-
enter(
|
|
31
|
+
enter(path) {
|
|
32
|
+
const openapiElement = path.node;
|
|
32
33
|
const isServersUndefined = typeof openapiElement.servers === 'undefined';
|
|
33
34
|
const isServersArrayElement = predicates.isArrayElement(openapiElement.servers);
|
|
34
35
|
const isServersEmpty = isServersArrayElement && openapiElement.servers.length === 0;
|
|
35
|
-
|
|
36
|
-
const defaultServer = namespace.elements.Server.refract({
|
|
36
|
+
const defaultServer = refractServer({
|
|
37
37
|
url: '/'
|
|
38
38
|
});
|
|
39
39
|
if (isServersUndefined || !isServersArrayElement) {
|
|
@@ -47,11 +47,14 @@ const plugin = ({
|
|
|
47
47
|
storage = undefined;
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
|
-
PathItemElement(
|
|
50
|
+
PathItemElement(path) {
|
|
51
|
+
const pathItemElement = path.node;
|
|
52
|
+
const ancestors = path.getAncestorNodes().reverse(); // root to parent order
|
|
53
|
+
|
|
51
54
|
// skip visiting this Path Item
|
|
52
55
|
if (ancestors.some(predicates.isComponentsElement)) return;
|
|
53
56
|
if (!ancestors.some(predicates.isOpenApi3_1Element)) return;
|
|
54
|
-
const pathItemJSONPointer = ancestorLineageToJSONPointer([...ancestors,
|
|
57
|
+
const pathItemJSONPointer = ancestorLineageToJSONPointer([...ancestors, pathItemElement]);
|
|
55
58
|
|
|
56
59
|
// skip visiting this Path Item Object if it's already normalized
|
|
57
60
|
if (storage.includes(pathItemJSONPointer)) {
|
|
@@ -76,11 +79,14 @@ const plugin = ({
|
|
|
76
79
|
storage.append(pathItemJSONPointer);
|
|
77
80
|
}
|
|
78
81
|
},
|
|
79
|
-
OperationElement(
|
|
82
|
+
OperationElement(path) {
|
|
83
|
+
const operationElement = path.node;
|
|
84
|
+
const ancestors = path.getAncestorNodes().reverse(); // root to parent order
|
|
85
|
+
|
|
80
86
|
// skip visiting this Operation
|
|
81
87
|
if (ancestors.some(predicates.isComponentsElement)) return;
|
|
82
88
|
if (!ancestors.some(predicates.isOpenApi3_1Element)) return;
|
|
83
|
-
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors,
|
|
89
|
+
const operationJSONPointer = ancestorLineageToJSONPointer([...ancestors, operationElement]);
|
|
84
90
|
|
|
85
91
|
// skip visiting this Operation Object if it's already normalized
|
|
86
92
|
if (storage.includes(operationJSONPointer)) {
|
|
@@ -88,7 +94,7 @@ const plugin = ({
|
|
|
88
94
|
}
|
|
89
95
|
|
|
90
96
|
// @TODO(vladimir.gorej@gmail.com): can be replaced by Array.prototype.findLast in future
|
|
91
|
-
const parentPathItemElement =
|
|
97
|
+
const parentPathItemElement = ancestors.findLast(predicates.isPathItemElement);
|
|
92
98
|
const isServersUndefined = typeof operationElement.servers === 'undefined';
|
|
93
99
|
const isServersArrayElement = predicates.isArrayElement(operationElement.servers);
|
|
94
100
|
const isServersEmpty = isServersArrayElement && operationElement.servers.length === 0;
|
|
@@ -3,7 +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 _apidomCore = require("@speclynx/apidom-core");
|
|
8
|
+
var _apidomTraverse = require("@speclynx/apidom-traverse");
|
|
7
9
|
var _apidomNsOpenapi = require("@speclynx/apidom-ns-openapi-3-0");
|
|
8
10
|
var _Info = _interopRequireDefault(require("../../elements/Info.cjs"));
|
|
9
11
|
var _Contact = _interopRequireDefault(require("../../elements/Contact.cjs"));
|
|
@@ -35,7 +37,6 @@ var _SecurityRequirement = _interopRequireDefault(require("../../elements/Securi
|
|
|
35
37
|
var _Tag = _interopRequireDefault(require("../../elements/Tag.cjs"));
|
|
36
38
|
var _ComponentsPathItems = _interopRequireDefault(require("../../elements/nces/ComponentsPathItems.cjs"));
|
|
37
39
|
var _Webhooks = _interopRequireDefault(require("../../elements/nces/Webhooks.cjs"));
|
|
38
|
-
var _visitor = require("../../traversal/visitor.cjs");
|
|
39
40
|
/**
|
|
40
41
|
* OpenAPI 3.1.2 specification elements.
|
|
41
42
|
*/
|
|
@@ -119,7 +120,7 @@ const schema = {
|
|
|
119
120
|
},
|
|
120
121
|
ServerVariableElement: {
|
|
121
122
|
enum(...args) {
|
|
122
|
-
return new
|
|
123
|
+
return new _apidomDatamodel.ArrayElement(...args);
|
|
123
124
|
}
|
|
124
125
|
},
|
|
125
126
|
PathsElement: {
|
|
@@ -288,7 +289,7 @@ const schema = {
|
|
|
288
289
|
},
|
|
289
290
|
SecurityRequirementElement: {
|
|
290
291
|
'[key: *]': function key(...args) {
|
|
291
|
-
return new
|
|
292
|
+
return new _apidomDatamodel.ArrayElement(...args);
|
|
292
293
|
}
|
|
293
294
|
},
|
|
294
295
|
TagElement: {
|
|
@@ -298,27 +299,27 @@ const schema = {
|
|
|
298
299
|
},
|
|
299
300
|
SchemaElement: {
|
|
300
301
|
$vocabulary(...args) {
|
|
301
|
-
const element = new
|
|
302
|
+
const element = new _apidomDatamodel.ObjectElement(...args);
|
|
302
303
|
element.classes.push('json-schema-$vocabulary');
|
|
303
304
|
return element;
|
|
304
305
|
},
|
|
305
306
|
$defs(...args) {
|
|
306
|
-
const element = new
|
|
307
|
+
const element = new _apidomDatamodel.ObjectElement(...args);
|
|
307
308
|
element.classes.push('json-schema-$defs');
|
|
308
309
|
return element;
|
|
309
310
|
},
|
|
310
311
|
allOf(...args) {
|
|
311
|
-
const element = new
|
|
312
|
+
const element = new _apidomDatamodel.ArrayElement(...args);
|
|
312
313
|
element.classes.push('json-schema-allOf');
|
|
313
314
|
return element;
|
|
314
315
|
},
|
|
315
316
|
anyOf(...args) {
|
|
316
|
-
const element = new
|
|
317
|
+
const element = new _apidomDatamodel.ArrayElement(...args);
|
|
317
318
|
element.classes.push('json-schema-anyOf');
|
|
318
319
|
return element;
|
|
319
320
|
},
|
|
320
321
|
oneOf(...args) {
|
|
321
|
-
const element = new
|
|
322
|
+
const element = new _apidomDatamodel.ArrayElement(...args);
|
|
322
323
|
element.classes.push('json-schema-oneOf');
|
|
323
324
|
return element;
|
|
324
325
|
},
|
|
@@ -335,12 +336,12 @@ const schema = {
|
|
|
335
336
|
return new _Schema.default(...args);
|
|
336
337
|
},
|
|
337
338
|
dependentSchemas(...args) {
|
|
338
|
-
const element = new
|
|
339
|
+
const element = new _apidomDatamodel.ObjectElement(...args);
|
|
339
340
|
element.classes.push('json-schema-dependentSchemas');
|
|
340
341
|
return element;
|
|
341
342
|
},
|
|
342
343
|
prefixItems(...args) {
|
|
343
|
-
const element = new
|
|
344
|
+
const element = new _apidomDatamodel.ArrayElement(...args);
|
|
344
345
|
element.classes.push('json-schema-prefixItems');
|
|
345
346
|
return element;
|
|
346
347
|
},
|
|
@@ -351,12 +352,12 @@ const schema = {
|
|
|
351
352
|
return new _Schema.default(...args);
|
|
352
353
|
},
|
|
353
354
|
properties(...args) {
|
|
354
|
-
const element = new
|
|
355
|
+
const element = new _apidomDatamodel.ObjectElement(...args);
|
|
355
356
|
element.classes.push('json-schema-properties');
|
|
356
357
|
return element;
|
|
357
358
|
},
|
|
358
359
|
patternProperties(...args) {
|
|
359
|
-
const element = new
|
|
360
|
+
const element = new _apidomDatamodel.ObjectElement(...args);
|
|
360
361
|
element.classes.push('json-schema-patternProperties');
|
|
361
362
|
return element;
|
|
362
363
|
},
|
|
@@ -373,27 +374,27 @@ const schema = {
|
|
|
373
374
|
return new _Schema.default(...args);
|
|
374
375
|
},
|
|
375
376
|
type(...args) {
|
|
376
|
-
const element = new
|
|
377
|
+
const element = new _apidomDatamodel.ArrayElement(...args);
|
|
377
378
|
element.classes.push('json-schema-type');
|
|
378
379
|
return element;
|
|
379
380
|
},
|
|
380
381
|
enum(...args) {
|
|
381
|
-
const element = new
|
|
382
|
+
const element = new _apidomDatamodel.ArrayElement(...args);
|
|
382
383
|
element.classes.push('json-schema-enum');
|
|
383
384
|
return element;
|
|
384
385
|
},
|
|
385
386
|
required(...args) {
|
|
386
|
-
const element = new
|
|
387
|
+
const element = new _apidomDatamodel.ArrayElement(...args);
|
|
387
388
|
element.classes.push('json-schema-required');
|
|
388
389
|
return element;
|
|
389
390
|
},
|
|
390
391
|
dependentRequired(...args) {
|
|
391
|
-
const element = new
|
|
392
|
+
const element = new _apidomDatamodel.ObjectElement(...args);
|
|
392
393
|
element.classes.push('json-schema-dependentRequired');
|
|
393
394
|
return element;
|
|
394
395
|
},
|
|
395
396
|
examples(...args) {
|
|
396
|
-
const element = new
|
|
397
|
+
const element = new _apidomDatamodel.ArrayElement(...args);
|
|
397
398
|
element.classes.push('json-schema-examples');
|
|
398
399
|
return element;
|
|
399
400
|
},
|
|
@@ -625,7 +626,7 @@ const schema = {
|
|
|
625
626
|
}
|
|
626
627
|
};
|
|
627
628
|
const findElementFactory = (ancestor, keyName) => {
|
|
628
|
-
const elementType = (0,
|
|
629
|
+
const elementType = (0, _apidomTraverse.getNodeType)(ancestor);
|
|
629
630
|
const keyMapping = schema[elementType] || schema[(0, _apidomCore.toValue)(ancestor.classes.first)];
|
|
630
631
|
return typeof keyMapping === 'undefined' ? undefined : Object.hasOwn(keyMapping, '[key: *]') ? keyMapping['[key: *]'] : keyMapping[keyName];
|
|
631
632
|
};
|
|
@@ -633,31 +634,32 @@ const findElementFactory = (ancestor, keyName) => {
|
|
|
633
634
|
/**
|
|
634
635
|
* @public
|
|
635
636
|
*/
|
|
636
|
-
const plugin = () => ({
|
|
637
|
-
|
|
638
|
-
}) => {
|
|
639
|
-
const isEmptyElement = element => predicates.isStringElement(element) && predicates.includesClasses(['yaml-e-node', 'yaml-e-scalar'], element);
|
|
637
|
+
const plugin = () => () => {
|
|
638
|
+
const isEmptyElement = element => (0, _apidomDatamodel.isStringElement)(element) && (0, _apidomDatamodel.includesClasses)(element, ['yaml-e-node', 'yaml-e-scalar']);
|
|
640
639
|
return {
|
|
641
640
|
visitor: {
|
|
642
|
-
StringElement(
|
|
643
|
-
|
|
644
|
-
|
|
641
|
+
StringElement(path) {
|
|
642
|
+
const element = path.node;
|
|
643
|
+
if (!isEmptyElement(element)) return;
|
|
644
|
+
const lineage = path.getAncestorNodes().reverse(); // root to parent
|
|
645
645
|
const parentElement = lineage.at(-1);
|
|
646
646
|
let elementFactory;
|
|
647
647
|
let context;
|
|
648
|
-
if (
|
|
648
|
+
if ((0, _apidomDatamodel.isArrayElement)(parentElement)) {
|
|
649
649
|
context = element;
|
|
650
650
|
elementFactory = findElementFactory(parentElement, '<*>');
|
|
651
|
-
} else if (
|
|
651
|
+
} else if ((0, _apidomDatamodel.isMemberElement)(parentElement)) {
|
|
652
652
|
context = lineage.at(-2);
|
|
653
653
|
elementFactory = findElementFactory(context, (0, _apidomCore.toValue)(parentElement.key));
|
|
654
654
|
}
|
|
655
655
|
|
|
656
656
|
// no element factory found
|
|
657
|
-
if (typeof elementFactory !== 'function') return
|
|
658
|
-
|
|
657
|
+
if (typeof elementFactory !== 'function') return;
|
|
658
|
+
const newElement = elementFactory.call({
|
|
659
659
|
context
|
|
660
|
-
}, undefined, (0,
|
|
660
|
+
}, undefined, (0, _apidomDatamodel.cloneDeep)(element.meta), (0, _apidomDatamodel.cloneDeep)(element.attributes));
|
|
661
|
+
_apidomDatamodel.SourceMapElement.transfer(element, newElement);
|
|
662
|
+
path.replaceWith(newElement);
|
|
661
663
|
}
|
|
662
664
|
}
|
|
663
665
|
};
|