@usearazzo/runner 0.0.0-stage → 1.0.1-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.
Files changed (152) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +20 -0
  4. package/README.md +777 -2
  5. package/dist/arazzo-runner.browser.js +113254 -0
  6. package/dist/arazzo-runner.browser.min.js +1 -0
  7. package/package.json +91 -4
  8. package/src/action/ActionResolver.cjs +160 -0
  9. package/src/action/ActionResolver.mjs +150 -0
  10. package/src/assembler/OpenAPI2DocumentAssembler.cjs +111 -0
  11. package/src/assembler/OpenAPI2DocumentAssembler.mjs +104 -0
  12. package/src/assembler/OpenAPI30DocumentAssembler.cjs +110 -0
  13. package/src/assembler/OpenAPI30DocumentAssembler.mjs +103 -0
  14. package/src/assembler/OpenAPI31DocumentAssembler.cjs +111 -0
  15. package/src/assembler/OpenAPI31DocumentAssembler.mjs +104 -0
  16. package/src/assembler/OpenAPIDocumentAssembler.cjs +58 -0
  17. package/src/assembler/OpenAPIDocumentAssembler.mjs +50 -0
  18. package/src/client/HTTPClient.cjs +5 -0
  19. package/src/client/HTTPClient.mjs +1 -0
  20. package/src/client/HTTPClientFetch.cjs +16 -0
  21. package/src/client/HTTPClientFetch.mjs +10 -0
  22. package/src/client/OpenAPIOperationRequest.cjs +5 -0
  23. package/src/client/OpenAPIOperationRequest.mjs +1 -0
  24. package/src/client/OpenAPIOperationResponse.cjs +42 -0
  25. package/src/client/OpenAPIOperationResponse.mjs +36 -0
  26. package/src/client/OpenAPIOperationResponseNormalizer.cjs +48 -0
  27. package/src/client/OpenAPIOperationResponseNormalizer.mjs +40 -0
  28. package/src/client/ParameterDelivery.cjs +119 -0
  29. package/src/client/ParameterDelivery.mjs +113 -0
  30. package/src/constants.cjs +9 -0
  31. package/src/constants.mjs +3 -0
  32. package/src/criterion/CriterionEvaluator.cjs +205 -0
  33. package/src/criterion/CriterionEvaluator.mjs +196 -0
  34. package/src/criterion/JSONPathCriterionEvaluator.cjs +47 -0
  35. package/src/criterion/JSONPathCriterionEvaluator.mjs +40 -0
  36. package/src/criterion/RegexCriterionEvaluator.cjs +67 -0
  37. package/src/criterion/RegexCriterionEvaluator.mjs +60 -0
  38. package/src/criterion/SimpleCriterionEvaluator.cjs +50 -0
  39. package/src/criterion/SimpleCriterionEvaluator.mjs +43 -0
  40. package/src/criterion/XPathCriterionEvaluator.cjs +117 -0
  41. package/src/criterion/XPathCriterionEvaluator.mjs +109 -0
  42. package/src/document/APIDocument.cjs +35 -0
  43. package/src/document/APIDocument.mjs +30 -0
  44. package/src/document/ArazzoDocument.cjs +81 -0
  45. package/src/document/ArazzoDocument.mjs +74 -0
  46. package/src/document/ArazzoSourceDescriptionIndex.cjs +26 -0
  47. package/src/document/ArazzoSourceDescriptionIndex.mjs +20 -0
  48. package/src/document/ArazzoStepIndex.cjs +25 -0
  49. package/src/document/ArazzoStepIndex.mjs +19 -0
  50. package/src/document/ArazzoWorkflowIndex.cjs +17 -0
  51. package/src/document/ArazzoWorkflowIndex.mjs +11 -0
  52. package/src/document/OpenAPIDocument.cjs +28 -0
  53. package/src/document/OpenAPIDocument.mjs +21 -0
  54. package/src/document/OpenAPIOperationIndex.cjs +24 -0
  55. package/src/document/OpenAPIOperationIndex.mjs +18 -0
  56. package/src/document/ParameterIdentity.cjs +93 -0
  57. package/src/document/ParameterIdentity.mjs +88 -0
  58. package/src/document/openapi-types.cjs +5 -0
  59. package/src/document/openapi-types.mjs +1 -0
  60. package/src/errors/ArazzoRunnerError.cjs +10 -0
  61. package/src/errors/ArazzoRunnerError.mjs +5 -0
  62. package/src/errors/AssemblerError.cjs +11 -0
  63. package/src/errors/AssemblerError.mjs +4 -0
  64. package/src/errors/ClientError.cjs +11 -0
  65. package/src/errors/ClientError.mjs +4 -0
  66. package/src/errors/CriterionError.cjs +11 -0
  67. package/src/errors/CriterionError.mjs +4 -0
  68. package/src/errors/ExecutionError.cjs +11 -0
  69. package/src/errors/ExecutionError.mjs +4 -0
  70. package/src/errors/ExtractionError.cjs +11 -0
  71. package/src/errors/ExtractionError.mjs +4 -0
  72. package/src/errors/InvalidEntryDocumentError.cjs +11 -0
  73. package/src/errors/InvalidEntryDocumentError.mjs +4 -0
  74. package/src/errors/NormalizationError.cjs +11 -0
  75. package/src/errors/NormalizationError.mjs +4 -0
  76. package/src/errors/ResolverError.cjs +11 -0
  77. package/src/errors/ResolverError.mjs +4 -0
  78. package/src/errors/RuntimeExpressionError.cjs +11 -0
  79. package/src/errors/RuntimeExpressionError.mjs +4 -0
  80. package/src/errors/UnmatchedProviderError.cjs +11 -0
  81. package/src/errors/UnmatchedProviderError.mjs +4 -0
  82. package/src/executor/ArazzoWorkflowLocatorNormalizer.cjs +147 -0
  83. package/src/executor/ArazzoWorkflowLocatorNormalizer.mjs +137 -0
  84. package/src/executor/OpenAPIOperationExecutor.cjs +458 -0
  85. package/src/executor/OpenAPIOperationExecutor.mjs +447 -0
  86. package/src/executor/OpenAPIOperationLocatorNormalizer.cjs +197 -0
  87. package/src/executor/OpenAPIOperationLocatorNormalizer.mjs +189 -0
  88. package/src/executor/SourceDescriptionsLocatorNormalizer.cjs +44 -0
  89. package/src/executor/SourceDescriptionsLocatorNormalizer.mjs +38 -0
  90. package/src/executor/StepExecutor.cjs +333 -0
  91. package/src/executor/StepExecutor.mjs +326 -0
  92. package/src/executor/StepRetryRunner.cjs +226 -0
  93. package/src/executor/StepRetryRunner.mjs +215 -0
  94. package/src/executor/StepTransitionInterpreter.cjs +159 -0
  95. package/src/executor/StepTransitionInterpreter.mjs +151 -0
  96. package/src/executor/WorkflowCallStack.cjs +116 -0
  97. package/src/executor/WorkflowCallStack.mjs +106 -0
  98. package/src/executor/WorkflowExecutor.cjs +1091 -0
  99. package/src/executor/WorkflowExecutor.mjs +1077 -0
  100. package/src/executor/abort.cjs +70 -0
  101. package/src/executor/abort.mjs +60 -0
  102. package/src/expression/RuntimeExpressionContext.cjs +5 -0
  103. package/src/expression/RuntimeExpressionContext.mjs +1 -0
  104. package/src/expression/RuntimeExpressionEvaluator.cjs +337 -0
  105. package/src/expression/RuntimeExpressionEvaluator.mjs +328 -0
  106. package/src/extractor/ArazzoStepExtractor.cjs +48 -0
  107. package/src/extractor/ArazzoStepExtractor.mjs +41 -0
  108. package/src/extractor/ArazzoWorkflowExtractor.cjs +50 -0
  109. package/src/extractor/ArazzoWorkflowExtractor.mjs +43 -0
  110. package/src/extractor/OpenAPIOperationExtractor.cjs +84 -0
  111. package/src/extractor/OpenAPIOperationExtractor.mjs +77 -0
  112. package/src/index.cjs +419 -0
  113. package/src/index.mjs +73 -0
  114. package/src/normalizer/ArazzoStepNormalizer.cjs +23 -0
  115. package/src/normalizer/ArazzoStepNormalizer.mjs +17 -0
  116. package/src/normalizer/ArazzoWorkflowNormalizer.cjs +214 -0
  117. package/src/normalizer/ArazzoWorkflowNormalizer.mjs +206 -0
  118. package/src/normalizer/OpenAPI2OperationNormalizer.cjs +128 -0
  119. package/src/normalizer/OpenAPI2OperationNormalizer.mjs +120 -0
  120. package/src/normalizer/OpenAPI30OperationNormalizer.cjs +129 -0
  121. package/src/normalizer/OpenAPI30OperationNormalizer.mjs +121 -0
  122. package/src/normalizer/OpenAPI31OperationNormalizer.cjs +131 -0
  123. package/src/normalizer/OpenAPI31OperationNormalizer.mjs +123 -0
  124. package/src/normalizer/OpenAPIOperationNormalizer.cjs +58 -0
  125. package/src/normalizer/OpenAPIOperationNormalizer.mjs +50 -0
  126. package/src/registry/DocumentRegistry.cjs +160 -0
  127. package/src/registry/DocumentRegistry.mjs +151 -0
  128. package/src/registry/providers/ArazzoDocumentRegistryProvider.cjs +154 -0
  129. package/src/registry/providers/ArazzoDocumentRegistryProvider.mjs +146 -0
  130. package/src/registry/providers/DocumentRegistryProvider.cjs +31 -0
  131. package/src/registry/providers/DocumentRegistryProvider.mjs +25 -0
  132. package/src/registry/providers/OpenAPIDocumentRegistryProvider.cjs +122 -0
  133. package/src/registry/providers/OpenAPIDocumentRegistryProvider.mjs +114 -0
  134. package/src/resolver/ArazzoValueResolver.cjs +42 -0
  135. package/src/resolver/ArazzoValueResolver.mjs +37 -0
  136. package/src/resolver/OpenAPIOperationParameterResolver.cjs +117 -0
  137. package/src/resolver/OpenAPIOperationParameterResolver.mjs +110 -0
  138. package/src/resolver/OutputResolver.cjs +71 -0
  139. package/src/resolver/OutputResolver.mjs +64 -0
  140. package/src/resolver/RequestBodyResolver.cjs +227 -0
  141. package/src/resolver/RequestBodyResolver.mjs +220 -0
  142. package/src/resolver/ResolverScope.cjs +5 -0
  143. package/src/resolver/ResolverScope.mjs +1 -0
  144. package/src/resolver/StepParameterResolver.cjs +22 -0
  145. package/src/resolver/StepParameterResolver.mjs +15 -0
  146. package/src/resolver/WorkflowParameterResolver.cjs +73 -0
  147. package/src/resolver/WorkflowParameterResolver.mjs +66 -0
  148. package/src/state/WorkflowExecutionState.cjs +99 -0
  149. package/src/state/WorkflowExecutionState.mjs +93 -0
  150. package/src/vendor/swagger-client.cjs +1 -0
  151. package/src/vendor/swagger-client.mjs +1 -0
  152. package/types/runner.d.ts +2341 -0
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _apidomCore = require("@speclynx/apidom-core");
9
+ var _apidomDatamodel = require("@speclynx/apidom-datamodel");
10
+ var _resolver = require("@usearazzo/resolver");
11
+ var _empty = require("@speclynx/apidom-reference/configuration/empty");
12
+ var _apidomJsonPointer = require("@speclynx/apidom-json-pointer");
13
+ var _openapi = _interopRequireDefault(require("@speclynx/apidom-reference/dereference/strategies/openapi-3-0"));
14
+ var _apidomNsOpenapi = require("@speclynx/apidom-ns-openapi-3-0");
15
+ var _NormalizationError = _interopRequireDefault(require("../errors/NormalizationError.cjs"));
16
+ var _OpenAPIDocumentRegistryProvider = require("../registry/providers/OpenAPIDocumentRegistryProvider.cjs");
17
+ /**
18
+ * Options for normalizing an OpenAPI 3.0 operation.
19
+ * @public
20
+ */
21
+
22
+ const normalizerOptionsOverride = (0, _empty.mergeOptions)(_OpenAPIDocumentRegistryProvider.providerOptionsOverride, {
23
+ dereference: {
24
+ strategies: [new _openapi.default()]
25
+ }
26
+ });
27
+
28
+ /**
29
+ * Version-specific normalization for OpenAPI 3.0 operations.
30
+ *
31
+ * Dereferences the operation subtree and handles merging of servers,
32
+ * parameters, and security from path item and root levels.
33
+ * @public
34
+ */
35
+ class OpenAPI30OperationNormalizer {
36
+ #options;
37
+ constructor(options = {}) {
38
+ this.#options = (0, _empty.mergeOptions)(normalizerOptionsOverride, options);
39
+ }
40
+ async normalize(operation, document) {
41
+ const operationPointer = (0, _apidomCore.toValue)(operation.meta.get('pointer'));
42
+ if (!(0, _apidomJsonPointer.testJSONPointer)(operationPointer)) {
43
+ throw new _NormalizationError.default(`Operation is missing valid "pointer" metadata. Was it produced by OpenAPIOperationExtractor?`, {
44
+ operationId: (0, _apidomCore.toValue)(operation.operationId),
45
+ uri: document.uri,
46
+ operationPointer
47
+ });
48
+ }
49
+ const tokens = (0, _apidomJsonPointer.parse)(operationPointer).tree;
50
+ const pathItemPointer = (0, _apidomJsonPointer.compile)(tokens.slice(0, -1));
51
+ let pathItem;
52
+ try {
53
+ pathItem = (0, _apidomJsonPointer.evaluate)(document.parseResult.api, pathItemPointer);
54
+ } catch (error) {
55
+ throw new _NormalizationError.default(`Failed to evaluate path item pointer "${pathItemPointer}" in OpenAPI 3.0 document at "${document.uri}"`, {
56
+ cause: error,
57
+ operationId: (0, _apidomCore.toValue)(operation.operationId),
58
+ uri: document.uri,
59
+ operationPointer,
60
+ pathItemPointer
61
+ });
62
+ }
63
+ if (!(0, _apidomNsOpenapi.isPathItemElement)(pathItem)) {
64
+ throw new _NormalizationError.default(`Pointer "${pathItemPointer}" does not reference a path item in OpenAPI 3.0 document at "${document.uri}"`, {
65
+ operationId: (0, _apidomCore.toValue)(operation.operationId),
66
+ uri: document.uri,
67
+ operationPointer,
68
+ pathItemPointer
69
+ });
70
+ }
71
+
72
+ // preparing data for normalization by lazy dereferencing
73
+ const entry = document.parseResult.api;
74
+ const operationDeref = await this.#dereferenceOperation(operation, document);
75
+
76
+ // dereferencing Path Item Parameter Object references
77
+ if ((0, _apidomDatamodel.isArrayElement)(pathItem.parameters)) {
78
+ pathItem.parameters = await this.#dereferencePathItemParameters(pathItem, document);
79
+ }
80
+
81
+ // normalization (mutable)
82
+ _apidomNsOpenapi.refractorPluginNormalizeServers.ensureDefaultServer(entry);
83
+ _apidomNsOpenapi.refractorPluginNormalizeServers.inheritServersToPathItem(pathItem, entry);
84
+ _apidomNsOpenapi.refractorPluginNormalizeServers.inheritServersToOperation(operationDeref, pathItem);
85
+ _apidomNsOpenapi.refractorPluginNormalizeParameters.inheritParametersToOperation(operationDeref, pathItem);
86
+ _apidomNsOpenapi.refractorPluginNormalizeSecurityRequirements.inheritSecurityToOperation(operationDeref, entry);
87
+ return operationDeref;
88
+ }
89
+ async #dereferenceOperation(operation, document) {
90
+ try {
91
+ return await (0, _resolver.dereferenceOpenAPIElement)(operation, (0, _empty.mergeOptions)(_resolver.defaultDereferenceOpenAPIOptions, (0, _empty.mergeOptions)(this.#options, {
92
+ resolve: {
93
+ baseURI: document.uri
94
+ },
95
+ dereference: {
96
+ strategyOpts: {
97
+ parseResult: document.parseResult
98
+ }
99
+ }
100
+ })));
101
+ } catch (error) {
102
+ throw new _NormalizationError.default(`Failed to dereference Operation("${(0, _apidomCore.toValue)(operation.operationId)}") in OpenAPI 3.0 document at "${document.uri}"`, {
103
+ cause: error,
104
+ operationId: (0, _apidomCore.toValue)(operation.operationId),
105
+ uri: document.uri
106
+ });
107
+ }
108
+ }
109
+ async #dereferencePathItemParameters(pathItem, document) {
110
+ try {
111
+ return await (0, _resolver.dereferenceOpenAPIElement)(pathItem.parameters, (0, _empty.mergeOptions)(_resolver.defaultDereferenceOpenAPIOptions, (0, _empty.mergeOptions)(this.#options, {
112
+ resolve: {
113
+ baseURI: document.uri
114
+ },
115
+ dereference: {
116
+ strategyOpts: {
117
+ parseResult: document.parseResult
118
+ }
119
+ }
120
+ })));
121
+ } catch (error) {
122
+ throw new _NormalizationError.default(`Failed to dereference Path Item parameters in OpenAPI 3.0 document at "${document.uri}"`, {
123
+ cause: error,
124
+ uri: document.uri
125
+ });
126
+ }
127
+ }
128
+ }
129
+ var _default = exports.default = OpenAPI30OperationNormalizer;
@@ -0,0 +1,121 @@
1
+ import { toValue } from '@speclynx/apidom-core';
2
+ import { isArrayElement } from '@speclynx/apidom-datamodel';
3
+ import { dereferenceOpenAPIElement, defaultDereferenceOpenAPIOptions } from '@usearazzo/resolver';
4
+ import { mergeOptions } from '@speclynx/apidom-reference/configuration/empty';
5
+ import { evaluate, parse, compile, testJSONPointer } from '@speclynx/apidom-json-pointer';
6
+ import OpenAPI30DereferenceStrategy from '@speclynx/apidom-reference/dereference/strategies/openapi-3-0';
7
+ import { isPathItemElement, refractorPluginNormalizeServers, refractorPluginNormalizeParameters, refractorPluginNormalizeSecurityRequirements } from '@speclynx/apidom-ns-openapi-3-0';
8
+ import NormalizationError from "../errors/NormalizationError.mjs";
9
+ import { providerOptionsOverride as openAPIProviderOptions } from "../registry/providers/OpenAPIDocumentRegistryProvider.mjs";
10
+ /**
11
+ * Options for normalizing an OpenAPI 3.0 operation.
12
+ * @public
13
+ */
14
+ const normalizerOptionsOverride = mergeOptions(openAPIProviderOptions, {
15
+ dereference: {
16
+ strategies: [new OpenAPI30DereferenceStrategy()]
17
+ }
18
+ });
19
+
20
+ /**
21
+ * Version-specific normalization for OpenAPI 3.0 operations.
22
+ *
23
+ * Dereferences the operation subtree and handles merging of servers,
24
+ * parameters, and security from path item and root levels.
25
+ * @public
26
+ */
27
+ class OpenAPI30OperationNormalizer {
28
+ #options;
29
+ constructor(options = {}) {
30
+ this.#options = mergeOptions(normalizerOptionsOverride, options);
31
+ }
32
+ async normalize(operation, document) {
33
+ const operationPointer = toValue(operation.meta.get('pointer'));
34
+ if (!testJSONPointer(operationPointer)) {
35
+ throw new NormalizationError(`Operation is missing valid "pointer" metadata. Was it produced by OpenAPIOperationExtractor?`, {
36
+ operationId: toValue(operation.operationId),
37
+ uri: document.uri,
38
+ operationPointer
39
+ });
40
+ }
41
+ const tokens = parse(operationPointer).tree;
42
+ const pathItemPointer = compile(tokens.slice(0, -1));
43
+ let pathItem;
44
+ try {
45
+ pathItem = evaluate(document.parseResult.api, pathItemPointer);
46
+ } catch (error) {
47
+ throw new NormalizationError(`Failed to evaluate path item pointer "${pathItemPointer}" in OpenAPI 3.0 document at "${document.uri}"`, {
48
+ cause: error,
49
+ operationId: toValue(operation.operationId),
50
+ uri: document.uri,
51
+ operationPointer,
52
+ pathItemPointer
53
+ });
54
+ }
55
+ if (!isPathItemElement(pathItem)) {
56
+ throw new NormalizationError(`Pointer "${pathItemPointer}" does not reference a path item in OpenAPI 3.0 document at "${document.uri}"`, {
57
+ operationId: toValue(operation.operationId),
58
+ uri: document.uri,
59
+ operationPointer,
60
+ pathItemPointer
61
+ });
62
+ }
63
+
64
+ // preparing data for normalization by lazy dereferencing
65
+ const entry = document.parseResult.api;
66
+ const operationDeref = await this.#dereferenceOperation(operation, document);
67
+
68
+ // dereferencing Path Item Parameter Object references
69
+ if (isArrayElement(pathItem.parameters)) {
70
+ pathItem.parameters = await this.#dereferencePathItemParameters(pathItem, document);
71
+ }
72
+
73
+ // normalization (mutable)
74
+ refractorPluginNormalizeServers.ensureDefaultServer(entry);
75
+ refractorPluginNormalizeServers.inheritServersToPathItem(pathItem, entry);
76
+ refractorPluginNormalizeServers.inheritServersToOperation(operationDeref, pathItem);
77
+ refractorPluginNormalizeParameters.inheritParametersToOperation(operationDeref, pathItem);
78
+ refractorPluginNormalizeSecurityRequirements.inheritSecurityToOperation(operationDeref, entry);
79
+ return operationDeref;
80
+ }
81
+ async #dereferenceOperation(operation, document) {
82
+ try {
83
+ return await dereferenceOpenAPIElement(operation, mergeOptions(defaultDereferenceOpenAPIOptions, mergeOptions(this.#options, {
84
+ resolve: {
85
+ baseURI: document.uri
86
+ },
87
+ dereference: {
88
+ strategyOpts: {
89
+ parseResult: document.parseResult
90
+ }
91
+ }
92
+ })));
93
+ } catch (error) {
94
+ throw new NormalizationError(`Failed to dereference Operation("${toValue(operation.operationId)}") in OpenAPI 3.0 document at "${document.uri}"`, {
95
+ cause: error,
96
+ operationId: toValue(operation.operationId),
97
+ uri: document.uri
98
+ });
99
+ }
100
+ }
101
+ async #dereferencePathItemParameters(pathItem, document) {
102
+ try {
103
+ return await dereferenceOpenAPIElement(pathItem.parameters, mergeOptions(defaultDereferenceOpenAPIOptions, mergeOptions(this.#options, {
104
+ resolve: {
105
+ baseURI: document.uri
106
+ },
107
+ dereference: {
108
+ strategyOpts: {
109
+ parseResult: document.parseResult
110
+ }
111
+ }
112
+ })));
113
+ } catch (error) {
114
+ throw new NormalizationError(`Failed to dereference Path Item parameters in OpenAPI 3.0 document at "${document.uri}"`, {
115
+ cause: error,
116
+ uri: document.uri
117
+ });
118
+ }
119
+ }
120
+ }
121
+ export default OpenAPI30OperationNormalizer;
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _apidomCore = require("@speclynx/apidom-core");
9
+ var _apidomDatamodel = require("@speclynx/apidom-datamodel");
10
+ var _resolver = require("@usearazzo/resolver");
11
+ var _empty = require("@speclynx/apidom-reference/configuration/empty");
12
+ var _apidomJsonPointer = require("@speclynx/apidom-json-pointer");
13
+ var _openapi = _interopRequireDefault(require("@speclynx/apidom-reference/dereference/strategies/openapi-3-1"));
14
+ var _apidomNsOpenapi = require("@speclynx/apidom-ns-openapi-3-1");
15
+ var _NormalizationError = _interopRequireDefault(require("../errors/NormalizationError.cjs"));
16
+ var _OpenAPIDocumentRegistryProvider = require("../registry/providers/OpenAPIDocumentRegistryProvider.cjs");
17
+ /**
18
+ * Options for normalizing an OpenAPI 3.1 operation.
19
+ * @public
20
+ */
21
+
22
+ const normalizerOptionsOverride = (0, _empty.mergeOptions)(_OpenAPIDocumentRegistryProvider.providerOptionsOverride, {
23
+ dereference: {
24
+ strategies: [new _openapi.default()]
25
+ }
26
+ });
27
+
28
+ /**
29
+ * Version-specific normalization for OpenAPI 3.1 operations.
30
+ *
31
+ * Dereferences the operation subtree and handles merging of servers,
32
+ * parameters, and security from path item and root levels.
33
+ * Same inheritance rules as 3.0 but with JSON Schema $id semantics
34
+ * for schema resolution.
35
+ * @public
36
+ */
37
+ class OpenAPI31OperationNormalizer {
38
+ #options;
39
+ constructor(options = {}) {
40
+ this.#options = (0, _empty.mergeOptions)(normalizerOptionsOverride, options);
41
+ }
42
+ async normalize(operation, document) {
43
+ const operationPointer = (0, _apidomCore.toValue)(operation.meta.get('pointer'));
44
+ if (!(0, _apidomJsonPointer.testJSONPointer)(operationPointer)) {
45
+ throw new _NormalizationError.default(`Operation is missing valid "pointer" metadata. Was it produced by OpenAPIOperationExtractor?`, {
46
+ operationId: (0, _apidomCore.toValue)(operation.operationId),
47
+ uri: document.uri,
48
+ operationPointer
49
+ });
50
+ }
51
+ const tokens = (0, _apidomJsonPointer.parse)(operationPointer).tree;
52
+ const pathItemPointer = (0, _apidomJsonPointer.compile)(tokens.slice(0, -1));
53
+ let pathItem;
54
+ try {
55
+ pathItem = (0, _apidomJsonPointer.evaluate)(document.parseResult.api, pathItemPointer);
56
+ } catch (error) {
57
+ throw new _NormalizationError.default(`Failed to evaluate path item pointer "${pathItemPointer}" in OpenAPI 3.1 document at "${document.uri}"`, {
58
+ cause: error,
59
+ operationId: (0, _apidomCore.toValue)(operation.operationId),
60
+ uri: document.uri,
61
+ operationPointer,
62
+ pathItemPointer
63
+ });
64
+ }
65
+ if (!(0, _apidomNsOpenapi.isPathItemElement)(pathItem)) {
66
+ throw new _NormalizationError.default(`Pointer "${pathItemPointer}" does not reference a path item in OpenAPI 3.1 document at "${document.uri}"`, {
67
+ operationId: (0, _apidomCore.toValue)(operation.operationId),
68
+ uri: document.uri,
69
+ operationPointer,
70
+ pathItemPointer
71
+ });
72
+ }
73
+
74
+ // preparing data for normalization by lazy dereferencing
75
+ const entry = document.parseResult.api;
76
+ const operationDeref = await this.#dereferenceOperation(operation, document);
77
+
78
+ // dereferencing Path Item Parameter Object references
79
+ if ((0, _apidomDatamodel.isArrayElement)(pathItem.parameters)) {
80
+ pathItem.parameters = await this.#dereferencePathItemParameters(pathItem, document);
81
+ }
82
+
83
+ // normalization (mutable)
84
+ _apidomNsOpenapi.refractorPluginNormalizeServers.ensureDefaultServer(entry);
85
+ _apidomNsOpenapi.refractorPluginNormalizeServers.inheritServersToPathItem(pathItem, entry);
86
+ _apidomNsOpenapi.refractorPluginNormalizeServers.inheritServersToOperation(operationDeref, pathItem);
87
+ _apidomNsOpenapi.refractorPluginNormalizeParameters.inheritParametersToOperation(operationDeref, pathItem);
88
+ _apidomNsOpenapi.refractorPluginNormalizeSecurityRequirements.inheritSecurityToOperation(operationDeref, entry);
89
+ return operationDeref;
90
+ }
91
+ async #dereferenceOperation(operation, document) {
92
+ try {
93
+ return await (0, _resolver.dereferenceOpenAPIElement)(operation, (0, _empty.mergeOptions)(_resolver.defaultDereferenceOpenAPIOptions, (0, _empty.mergeOptions)(this.#options, {
94
+ resolve: {
95
+ baseURI: document.uri
96
+ },
97
+ dereference: {
98
+ strategyOpts: {
99
+ parseResult: document.parseResult
100
+ }
101
+ }
102
+ })));
103
+ } catch (error) {
104
+ throw new _NormalizationError.default(`Failed to dereference Operation("${(0, _apidomCore.toValue)(operation.operationId)}") in OpenAPI 3.1 document at "${document.uri}"`, {
105
+ cause: error,
106
+ operationId: (0, _apidomCore.toValue)(operation.operationId),
107
+ uri: document.uri
108
+ });
109
+ }
110
+ }
111
+ async #dereferencePathItemParameters(pathItem, document) {
112
+ try {
113
+ return await (0, _resolver.dereferenceOpenAPIElement)(pathItem.parameters, (0, _empty.mergeOptions)(_resolver.defaultDereferenceOpenAPIOptions, (0, _empty.mergeOptions)(this.#options, {
114
+ resolve: {
115
+ baseURI: document.uri
116
+ },
117
+ dereference: {
118
+ strategyOpts: {
119
+ parseResult: document.parseResult
120
+ }
121
+ }
122
+ })));
123
+ } catch (error) {
124
+ throw new _NormalizationError.default(`Failed to dereference Path Item parameters in OpenAPI 3.1 document at "${document.uri}"`, {
125
+ cause: error,
126
+ uri: document.uri
127
+ });
128
+ }
129
+ }
130
+ }
131
+ var _default = exports.default = OpenAPI31OperationNormalizer;
@@ -0,0 +1,123 @@
1
+ import { toValue } from '@speclynx/apidom-core';
2
+ import { isArrayElement } from '@speclynx/apidom-datamodel';
3
+ import { dereferenceOpenAPIElement, defaultDereferenceOpenAPIOptions } from '@usearazzo/resolver';
4
+ import { mergeOptions } from '@speclynx/apidom-reference/configuration/empty';
5
+ import { evaluate, parse, compile, testJSONPointer } from '@speclynx/apidom-json-pointer';
6
+ import OpenAPI31DereferenceStrategy from '@speclynx/apidom-reference/dereference/strategies/openapi-3-1';
7
+ import { isPathItemElement, refractorPluginNormalizeServers, refractorPluginNormalizeParameters, refractorPluginNormalizeSecurityRequirements } from '@speclynx/apidom-ns-openapi-3-1';
8
+ import NormalizationError from "../errors/NormalizationError.mjs";
9
+ import { providerOptionsOverride as openAPIProviderOptions } from "../registry/providers/OpenAPIDocumentRegistryProvider.mjs";
10
+ /**
11
+ * Options for normalizing an OpenAPI 3.1 operation.
12
+ * @public
13
+ */
14
+ const normalizerOptionsOverride = mergeOptions(openAPIProviderOptions, {
15
+ dereference: {
16
+ strategies: [new OpenAPI31DereferenceStrategy()]
17
+ }
18
+ });
19
+
20
+ /**
21
+ * Version-specific normalization for OpenAPI 3.1 operations.
22
+ *
23
+ * Dereferences the operation subtree and handles merging of servers,
24
+ * parameters, and security from path item and root levels.
25
+ * Same inheritance rules as 3.0 but with JSON Schema $id semantics
26
+ * for schema resolution.
27
+ * @public
28
+ */
29
+ class OpenAPI31OperationNormalizer {
30
+ #options;
31
+ constructor(options = {}) {
32
+ this.#options = mergeOptions(normalizerOptionsOverride, options);
33
+ }
34
+ async normalize(operation, document) {
35
+ const operationPointer = toValue(operation.meta.get('pointer'));
36
+ if (!testJSONPointer(operationPointer)) {
37
+ throw new NormalizationError(`Operation is missing valid "pointer" metadata. Was it produced by OpenAPIOperationExtractor?`, {
38
+ operationId: toValue(operation.operationId),
39
+ uri: document.uri,
40
+ operationPointer
41
+ });
42
+ }
43
+ const tokens = parse(operationPointer).tree;
44
+ const pathItemPointer = compile(tokens.slice(0, -1));
45
+ let pathItem;
46
+ try {
47
+ pathItem = evaluate(document.parseResult.api, pathItemPointer);
48
+ } catch (error) {
49
+ throw new NormalizationError(`Failed to evaluate path item pointer "${pathItemPointer}" in OpenAPI 3.1 document at "${document.uri}"`, {
50
+ cause: error,
51
+ operationId: toValue(operation.operationId),
52
+ uri: document.uri,
53
+ operationPointer,
54
+ pathItemPointer
55
+ });
56
+ }
57
+ if (!isPathItemElement(pathItem)) {
58
+ throw new NormalizationError(`Pointer "${pathItemPointer}" does not reference a path item in OpenAPI 3.1 document at "${document.uri}"`, {
59
+ operationId: toValue(operation.operationId),
60
+ uri: document.uri,
61
+ operationPointer,
62
+ pathItemPointer
63
+ });
64
+ }
65
+
66
+ // preparing data for normalization by lazy dereferencing
67
+ const entry = document.parseResult.api;
68
+ const operationDeref = await this.#dereferenceOperation(operation, document);
69
+
70
+ // dereferencing Path Item Parameter Object references
71
+ if (isArrayElement(pathItem.parameters)) {
72
+ pathItem.parameters = await this.#dereferencePathItemParameters(pathItem, document);
73
+ }
74
+
75
+ // normalization (mutable)
76
+ refractorPluginNormalizeServers.ensureDefaultServer(entry);
77
+ refractorPluginNormalizeServers.inheritServersToPathItem(pathItem, entry);
78
+ refractorPluginNormalizeServers.inheritServersToOperation(operationDeref, pathItem);
79
+ refractorPluginNormalizeParameters.inheritParametersToOperation(operationDeref, pathItem);
80
+ refractorPluginNormalizeSecurityRequirements.inheritSecurityToOperation(operationDeref, entry);
81
+ return operationDeref;
82
+ }
83
+ async #dereferenceOperation(operation, document) {
84
+ try {
85
+ return await dereferenceOpenAPIElement(operation, mergeOptions(defaultDereferenceOpenAPIOptions, mergeOptions(this.#options, {
86
+ resolve: {
87
+ baseURI: document.uri
88
+ },
89
+ dereference: {
90
+ strategyOpts: {
91
+ parseResult: document.parseResult
92
+ }
93
+ }
94
+ })));
95
+ } catch (error) {
96
+ throw new NormalizationError(`Failed to dereference Operation("${toValue(operation.operationId)}") in OpenAPI 3.1 document at "${document.uri}"`, {
97
+ cause: error,
98
+ operationId: toValue(operation.operationId),
99
+ uri: document.uri
100
+ });
101
+ }
102
+ }
103
+ async #dereferencePathItemParameters(pathItem, document) {
104
+ try {
105
+ return await dereferenceOpenAPIElement(pathItem.parameters, mergeOptions(defaultDereferenceOpenAPIOptions, mergeOptions(this.#options, {
106
+ resolve: {
107
+ baseURI: document.uri
108
+ },
109
+ dereference: {
110
+ strategyOpts: {
111
+ parseResult: document.parseResult
112
+ }
113
+ }
114
+ })));
115
+ } catch (error) {
116
+ throw new NormalizationError(`Failed to dereference Path Item parameters in OpenAPI 3.1 document at "${document.uri}"`, {
117
+ cause: error,
118
+ uri: document.uri
119
+ });
120
+ }
121
+ }
122
+ }
123
+ export default OpenAPI31OperationNormalizer;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _apidomNsOpenapi = require("@speclynx/apidom-ns-openapi-2");
9
+ var _apidomNsOpenapi2 = require("@speclynx/apidom-ns-openapi-3-0");
10
+ var _apidomNsOpenapi3 = require("@speclynx/apidom-ns-openapi-3-1");
11
+ var _NormalizationError = _interopRequireDefault(require("../errors/NormalizationError.cjs"));
12
+ var _OpenAPI2OperationNormalizer = _interopRequireDefault(require("./OpenAPI2OperationNormalizer.cjs"));
13
+ var _OpenAPI30OperationNormalizer = _interopRequireDefault(require("./OpenAPI30OperationNormalizer.cjs"));
14
+ var _OpenAPI31OperationNormalizer = _interopRequireDefault(require("./OpenAPI31OperationNormalizer.cjs"));
15
+ /**
16
+ * Options for the OpenAPI operation normalizer facade.
17
+ * @public
18
+ */
19
+
20
+ /**
21
+ * Facade for normalizing OpenAPI operations across all supported versions.
22
+ *
23
+ * Detects the OpenAPI version from the document and delegates to the
24
+ * appropriate version-specific normalizer (2.0, 3.0, or 3.1).
25
+ *
26
+ * Custom normalizer instances can be provided via constructor options.
27
+ * @public
28
+ */
29
+ class OpenAPIOperationNormalizer {
30
+ #openapi2;
31
+ #openapi30;
32
+ #openapi31;
33
+ constructor(options = {}) {
34
+ this.#openapi2 = options.openapi2 ?? new _OpenAPI2OperationNormalizer.default();
35
+ this.#openapi30 = options.openapi30 ?? new _OpenAPI30OperationNormalizer.default();
36
+ this.#openapi31 = options.openapi31 ?? new _OpenAPI31OperationNormalizer.default();
37
+ }
38
+
39
+ /**
40
+ * Normalizes the operation by delegating to the version-specific normalizer.
41
+ */
42
+ async normalize(operation, document) {
43
+ const root = document.parseResult.api;
44
+ if ((0, _apidomNsOpenapi.isSwaggerElement)(root)) {
45
+ return this.#openapi2.normalize(operation, document);
46
+ }
47
+ if ((0, _apidomNsOpenapi2.isOpenApi3_0Element)(root)) {
48
+ return this.#openapi30.normalize(operation, document);
49
+ }
50
+ if ((0, _apidomNsOpenapi3.isOpenApi3_1Element)(root)) {
51
+ return this.#openapi31.normalize(operation, document);
52
+ }
53
+ throw new _NormalizationError.default(`Unsupported OpenAPI version in document at "${document.uri}"`, {
54
+ uri: document.uri
55
+ });
56
+ }
57
+ }
58
+ var _default = exports.default = OpenAPIOperationNormalizer;
@@ -0,0 +1,50 @@
1
+ import { isSwaggerElement } from '@speclynx/apidom-ns-openapi-2';
2
+ import { isOpenApi3_0Element } from '@speclynx/apidom-ns-openapi-3-0';
3
+ import { isOpenApi3_1Element } from '@speclynx/apidom-ns-openapi-3-1';
4
+ import NormalizationError from "../errors/NormalizationError.mjs";
5
+ import OpenAPI2OperationNormalizer from "./OpenAPI2OperationNormalizer.mjs";
6
+ import OpenAPI30OperationNormalizer from "./OpenAPI30OperationNormalizer.mjs";
7
+ import OpenAPI31OperationNormalizer from "./OpenAPI31OperationNormalizer.mjs";
8
+ /**
9
+ * Options for the OpenAPI operation normalizer facade.
10
+ * @public
11
+ */
12
+ /**
13
+ * Facade for normalizing OpenAPI operations across all supported versions.
14
+ *
15
+ * Detects the OpenAPI version from the document and delegates to the
16
+ * appropriate version-specific normalizer (2.0, 3.0, or 3.1).
17
+ *
18
+ * Custom normalizer instances can be provided via constructor options.
19
+ * @public
20
+ */
21
+ class OpenAPIOperationNormalizer {
22
+ #openapi2;
23
+ #openapi30;
24
+ #openapi31;
25
+ constructor(options = {}) {
26
+ this.#openapi2 = options.openapi2 ?? new OpenAPI2OperationNormalizer();
27
+ this.#openapi30 = options.openapi30 ?? new OpenAPI30OperationNormalizer();
28
+ this.#openapi31 = options.openapi31 ?? new OpenAPI31OperationNormalizer();
29
+ }
30
+
31
+ /**
32
+ * Normalizes the operation by delegating to the version-specific normalizer.
33
+ */
34
+ async normalize(operation, document) {
35
+ const root = document.parseResult.api;
36
+ if (isSwaggerElement(root)) {
37
+ return this.#openapi2.normalize(operation, document);
38
+ }
39
+ if (isOpenApi3_0Element(root)) {
40
+ return this.#openapi30.normalize(operation, document);
41
+ }
42
+ if (isOpenApi3_1Element(root)) {
43
+ return this.#openapi31.normalize(operation, document);
44
+ }
45
+ throw new NormalizationError(`Unsupported OpenAPI version in document at "${document.uri}"`, {
46
+ uri: document.uri
47
+ });
48
+ }
49
+ }
50
+ export default OpenAPIOperationNormalizer;