@usearazzo/runner 0.0.0-stage → 1.0.1-alpha.11
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 +37 -0
- package/LICENSE +202 -0
- package/NOTICE +20 -0
- package/README.md +163 -2
- package/dist/arazzo-runner.browser.js +113245 -0
- package/dist/arazzo-runner.browser.min.js +1 -0
- package/package.json +95 -4
- package/src/ArazzoRunner.cjs +122 -0
- package/src/ArazzoRunner.mjs +113 -0
- package/src/action/ActionResolver.cjs +160 -0
- package/src/action/ActionResolver.mjs +150 -0
- package/src/assembler/OpenAPI2DocumentAssembler.cjs +111 -0
- package/src/assembler/OpenAPI2DocumentAssembler.mjs +104 -0
- package/src/assembler/OpenAPI30DocumentAssembler.cjs +110 -0
- package/src/assembler/OpenAPI30DocumentAssembler.mjs +103 -0
- package/src/assembler/OpenAPI31DocumentAssembler.cjs +111 -0
- package/src/assembler/OpenAPI31DocumentAssembler.mjs +104 -0
- package/src/assembler/OpenAPIDocumentAssembler.cjs +58 -0
- package/src/assembler/OpenAPIDocumentAssembler.mjs +50 -0
- package/src/client/HTTPClient.cjs +5 -0
- package/src/client/HTTPClient.mjs +1 -0
- package/src/client/HTTPClientFetch.cjs +16 -0
- package/src/client/HTTPClientFetch.mjs +10 -0
- package/src/client/OpenAPIOperationRequest.cjs +5 -0
- package/src/client/OpenAPIOperationRequest.mjs +1 -0
- package/src/client/OpenAPIOperationResponse.cjs +42 -0
- package/src/client/OpenAPIOperationResponse.mjs +36 -0
- package/src/client/OpenAPIOperationResponseNormalizer.cjs +48 -0
- package/src/client/OpenAPIOperationResponseNormalizer.mjs +40 -0
- package/src/client/ParameterDelivery.cjs +119 -0
- package/src/client/ParameterDelivery.mjs +113 -0
- package/src/constants.cjs +9 -0
- package/src/constants.mjs +3 -0
- package/src/criterion/CriterionEvaluator.cjs +205 -0
- package/src/criterion/CriterionEvaluator.mjs +196 -0
- package/src/criterion/JSONPathCriterionEvaluator.cjs +47 -0
- package/src/criterion/JSONPathCriterionEvaluator.mjs +40 -0
- package/src/criterion/RegexCriterionEvaluator.cjs +67 -0
- package/src/criterion/RegexCriterionEvaluator.mjs +60 -0
- package/src/criterion/SimpleCriterionEvaluator.cjs +50 -0
- package/src/criterion/SimpleCriterionEvaluator.mjs +43 -0
- package/src/criterion/XPathCriterionEvaluator.cjs +117 -0
- package/src/criterion/XPathCriterionEvaluator.mjs +109 -0
- package/src/document/APIDocument.cjs +35 -0
- package/src/document/APIDocument.mjs +30 -0
- package/src/document/ArazzoDocument.cjs +81 -0
- package/src/document/ArazzoDocument.mjs +74 -0
- package/src/document/ArazzoSourceDescriptionIndex.cjs +26 -0
- package/src/document/ArazzoSourceDescriptionIndex.mjs +20 -0
- package/src/document/ArazzoStepIndex.cjs +25 -0
- package/src/document/ArazzoStepIndex.mjs +19 -0
- package/src/document/ArazzoWorkflowIndex.cjs +17 -0
- package/src/document/ArazzoWorkflowIndex.mjs +11 -0
- package/src/document/OpenAPIDocument.cjs +28 -0
- package/src/document/OpenAPIDocument.mjs +21 -0
- package/src/document/OpenAPIOperationIndex.cjs +24 -0
- package/src/document/OpenAPIOperationIndex.mjs +18 -0
- package/src/document/ParameterIdentity.cjs +93 -0
- package/src/document/ParameterIdentity.mjs +88 -0
- package/src/document/openapi-types.cjs +5 -0
- package/src/document/openapi-types.mjs +1 -0
- package/src/errors/ArazzoRunnerError.cjs +10 -0
- package/src/errors/ArazzoRunnerError.mjs +5 -0
- package/src/errors/AssemblerError.cjs +11 -0
- package/src/errors/AssemblerError.mjs +4 -0
- package/src/errors/ClientError.cjs +11 -0
- package/src/errors/ClientError.mjs +4 -0
- package/src/errors/CriterionError.cjs +11 -0
- package/src/errors/CriterionError.mjs +4 -0
- package/src/errors/ExecutionError.cjs +11 -0
- package/src/errors/ExecutionError.mjs +4 -0
- package/src/errors/ExtractionError.cjs +11 -0
- package/src/errors/ExtractionError.mjs +4 -0
- package/src/errors/InvalidEntryDocumentError.cjs +11 -0
- package/src/errors/InvalidEntryDocumentError.mjs +4 -0
- package/src/errors/NormalizationError.cjs +11 -0
- package/src/errors/NormalizationError.mjs +4 -0
- package/src/errors/ResolverError.cjs +11 -0
- package/src/errors/ResolverError.mjs +4 -0
- package/src/errors/RuntimeExpressionError.cjs +11 -0
- package/src/errors/RuntimeExpressionError.mjs +4 -0
- package/src/errors/UnmatchedProviderError.cjs +11 -0
- package/src/errors/UnmatchedProviderError.mjs +4 -0
- package/src/executor/ArazzoWorkflowLocatorNormalizer.cjs +147 -0
- package/src/executor/ArazzoWorkflowLocatorNormalizer.mjs +137 -0
- package/src/executor/OpenAPIOperationExecutor.cjs +458 -0
- package/src/executor/OpenAPIOperationExecutor.mjs +447 -0
- package/src/executor/OpenAPIOperationLocatorNormalizer.cjs +197 -0
- package/src/executor/OpenAPIOperationLocatorNormalizer.mjs +189 -0
- package/src/executor/SourceDescriptionsLocatorNormalizer.cjs +44 -0
- package/src/executor/SourceDescriptionsLocatorNormalizer.mjs +38 -0
- package/src/executor/StepExecutor.cjs +333 -0
- package/src/executor/StepExecutor.mjs +326 -0
- package/src/executor/StepRetryRunner.cjs +226 -0
- package/src/executor/StepRetryRunner.mjs +215 -0
- package/src/executor/StepTransitionInterpreter.cjs +159 -0
- package/src/executor/StepTransitionInterpreter.mjs +151 -0
- package/src/executor/WorkflowCallStack.cjs +116 -0
- package/src/executor/WorkflowCallStack.mjs +106 -0
- package/src/executor/WorkflowExecutor.cjs +1091 -0
- package/src/executor/WorkflowExecutor.mjs +1077 -0
- package/src/executor/abort.cjs +70 -0
- package/src/executor/abort.mjs +60 -0
- package/src/expression/RuntimeExpressionContext.cjs +5 -0
- package/src/expression/RuntimeExpressionContext.mjs +1 -0
- package/src/expression/RuntimeExpressionEvaluator.cjs +337 -0
- package/src/expression/RuntimeExpressionEvaluator.mjs +328 -0
- package/src/extractor/ArazzoStepExtractor.cjs +48 -0
- package/src/extractor/ArazzoStepExtractor.mjs +41 -0
- package/src/extractor/ArazzoWorkflowExtractor.cjs +50 -0
- package/src/extractor/ArazzoWorkflowExtractor.mjs +43 -0
- package/src/extractor/OpenAPIOperationExtractor.cjs +84 -0
- package/src/extractor/OpenAPIOperationExtractor.mjs +77 -0
- package/src/index.cjs +426 -0
- package/src/index.mjs +75 -0
- package/src/normalizer/ArazzoStepNormalizer.cjs +23 -0
- package/src/normalizer/ArazzoStepNormalizer.mjs +17 -0
- package/src/normalizer/ArazzoWorkflowNormalizer.cjs +214 -0
- package/src/normalizer/ArazzoWorkflowNormalizer.mjs +206 -0
- package/src/normalizer/OpenAPI2OperationNormalizer.cjs +128 -0
- package/src/normalizer/OpenAPI2OperationNormalizer.mjs +120 -0
- package/src/normalizer/OpenAPI30OperationNormalizer.cjs +129 -0
- package/src/normalizer/OpenAPI30OperationNormalizer.mjs +121 -0
- package/src/normalizer/OpenAPI31OperationNormalizer.cjs +131 -0
- package/src/normalizer/OpenAPI31OperationNormalizer.mjs +123 -0
- package/src/normalizer/OpenAPIOperationNormalizer.cjs +58 -0
- package/src/normalizer/OpenAPIOperationNormalizer.mjs +50 -0
- package/src/registry/DocumentRegistry.cjs +160 -0
- package/src/registry/DocumentRegistry.mjs +151 -0
- package/src/registry/providers/ArazzoDocumentRegistryProvider.cjs +154 -0
- package/src/registry/providers/ArazzoDocumentRegistryProvider.mjs +146 -0
- package/src/registry/providers/DocumentRegistryProvider.cjs +31 -0
- package/src/registry/providers/DocumentRegistryProvider.mjs +25 -0
- package/src/registry/providers/OpenAPIDocumentRegistryProvider.cjs +122 -0
- package/src/registry/providers/OpenAPIDocumentRegistryProvider.mjs +114 -0
- package/src/resolver/ArazzoValueResolver.cjs +42 -0
- package/src/resolver/ArazzoValueResolver.mjs +37 -0
- package/src/resolver/OpenAPIOperationParameterResolver.cjs +117 -0
- package/src/resolver/OpenAPIOperationParameterResolver.mjs +110 -0
- package/src/resolver/OutputResolver.cjs +71 -0
- package/src/resolver/OutputResolver.mjs +64 -0
- package/src/resolver/RequestBodyResolver.cjs +227 -0
- package/src/resolver/RequestBodyResolver.mjs +220 -0
- package/src/resolver/ResolverScope.cjs +5 -0
- package/src/resolver/ResolverScope.mjs +1 -0
- package/src/resolver/StepParameterResolver.cjs +22 -0
- package/src/resolver/StepParameterResolver.mjs +15 -0
- package/src/resolver/WorkflowParameterResolver.cjs +73 -0
- package/src/resolver/WorkflowParameterResolver.mjs +66 -0
- package/src/state/WorkflowExecutionState.cjs +99 -0
- package/src/state/WorkflowExecutionState.mjs +93 -0
- package/src/vendor/swagger-client.cjs +1 -0
- package/src/vendor/swagger-client.mjs +1 -0
- package/types/runner.d.ts +2410 -0
|
@@ -0,0 +1,111 @@
|
|
|
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 _apidomJsonPointer = require("@speclynx/apidom-json-pointer");
|
|
11
|
+
var _apidomNsOpenapi = require("@speclynx/apidom-ns-openapi-2");
|
|
12
|
+
var _OpenAPIDocument = _interopRequireDefault(require("../document/OpenAPIDocument.cjs"));
|
|
13
|
+
var _OpenAPIOperationIndex = _interopRequireDefault(require("../document/OpenAPIOperationIndex.cjs"));
|
|
14
|
+
var _AssemblerError = _interopRequireDefault(require("../errors/AssemblerError.cjs"));
|
|
15
|
+
/**
|
|
16
|
+
* Assembles a standalone OpenAPI 2.0 (Swagger) document from a
|
|
17
|
+
* normalized operation element.
|
|
18
|
+
*
|
|
19
|
+
* The assembled document is a valid Swagger 2.0 specification containing
|
|
20
|
+
* only the single operation with its host, basePath, schemes, and
|
|
21
|
+
* referenced security definitions from the source document.
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
class OpenAPI2DocumentAssembler {
|
|
25
|
+
/**
|
|
26
|
+
* Assembles a standalone Swagger 2.0 document from a normalized operation.
|
|
27
|
+
*/
|
|
28
|
+
assemble(operation, document) {
|
|
29
|
+
const entry = document.parseResult.api;
|
|
30
|
+
const method = (0, _apidomCore.toValue)(operation.meta.get('http-method'));
|
|
31
|
+
const path = (0, _apidomCore.toValue)(operation.meta.get('path'));
|
|
32
|
+
if (typeof method !== 'string' || typeof path !== 'string') {
|
|
33
|
+
throw new _AssemblerError.default(`Operation is missing valid "http-method" or "path" metadata. Was it produced by OpenAPIOperationExtractor?`, {
|
|
34
|
+
uri: document.uri,
|
|
35
|
+
operationId: (0, _apidomCore.toValue)(operation.operationId)
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (!(0, _apidomNsOpenapi.isSwaggerElement)(entry)) {
|
|
39
|
+
throw new _AssemblerError.default(`Expected OpenAPI 2.0 document at "${document.uri}"`, {
|
|
40
|
+
uri: document.uri
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// build Swagger 2.0 document
|
|
45
|
+
const swagger = new _apidomNsOpenapi.SwaggerElement({
|
|
46
|
+
swagger: entry.swagger
|
|
47
|
+
}, {
|
|
48
|
+
classes: ['api']
|
|
49
|
+
});
|
|
50
|
+
// prettier-ignore
|
|
51
|
+
{
|
|
52
|
+
if ((0, _apidomDatamodel.isElement)(entry.info)) swagger.info = entry.info;
|
|
53
|
+
if ((0, _apidomDatamodel.isElement)(entry.host)) swagger.host = entry.host;
|
|
54
|
+
if ((0, _apidomDatamodel.isElement)(entry.basePath)) swagger.basePath = entry.basePath;
|
|
55
|
+
if ((0, _apidomDatamodel.isElement)(entry.schemes)) swagger.schemes = entry.schemes;
|
|
56
|
+
if ((0, _apidomDatamodel.isElement)(entry.consumes)) swagger.consumes = entry.consumes;
|
|
57
|
+
if ((0, _apidomDatamodel.isElement)(entry.produces)) swagger.produces = entry.produces;
|
|
58
|
+
if ((0, _apidomDatamodel.isElement)(entry.tags)) swagger.tags = entry.tags;
|
|
59
|
+
if ((0, _apidomDatamodel.isElement)(entry.externalDocs)) swagger.externalDocs = entry.externalDocs;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// build paths with single operation
|
|
63
|
+
const pathItem = new _apidomNsOpenapi.PathItemElement();
|
|
64
|
+
const paths = new _apidomNsOpenapi.PathsElement();
|
|
65
|
+
pathItem.set(method, operation);
|
|
66
|
+
paths.set(path, pathItem);
|
|
67
|
+
swagger.paths = paths;
|
|
68
|
+
|
|
69
|
+
// include only referenced security definitions
|
|
70
|
+
const securityDefinitions = this.#extractReferencedSecurityDefinitions(operation, entry);
|
|
71
|
+
if (securityDefinitions.length > 0) {
|
|
72
|
+
swagger.securityDefinitions = securityDefinitions;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// wrap in ParseResultElement and return as OpenAPIDocument
|
|
76
|
+
const parseResult = new _apidomDatamodel.ParseResultElement([swagger]);
|
|
77
|
+
const operationIndex = new _OpenAPIOperationIndex.default();
|
|
78
|
+
const operationId = (0, _apidomCore.toValue)(operation.operationId);
|
|
79
|
+
if (typeof operationId === 'string' && operationId.length > 0) {
|
|
80
|
+
operationIndex.set(operationId, (0, _apidomJsonPointer.compile)(['paths', path, method]));
|
|
81
|
+
}
|
|
82
|
+
return new _OpenAPIDocument.default(document.uri, parseResult, operationIndex);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Extracts only the security definitions referenced by the operation's
|
|
87
|
+
* security requirements.
|
|
88
|
+
*/
|
|
89
|
+
#extractReferencedSecurityDefinitions(operation, entry) {
|
|
90
|
+
const securityDefinitions = new _apidomNsOpenapi.SecurityDefinitionsElement();
|
|
91
|
+
if (!(0, _apidomDatamodel.isArrayElement)(operation.security)) return securityDefinitions;
|
|
92
|
+
if (!(0, _apidomNsOpenapi.isSecurityDefinitionsElement)(entry.securityDefinitions)) return securityDefinitions;
|
|
93
|
+
|
|
94
|
+
// collect referenced names of Security Definitions
|
|
95
|
+
const referencedNames = new Set();
|
|
96
|
+
for (const securityRequirement of operation.security) {
|
|
97
|
+
if (!(0, _apidomNsOpenapi.isSecurityRequirementElement)(securityRequirement)) continue;
|
|
98
|
+
securityRequirement.forEach((_value, keyElement) => {
|
|
99
|
+
referencedNames.add((0, _apidomCore.toValue)(keyElement));
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
if (referencedNames.size === 0) return securityDefinitions;
|
|
103
|
+
for (const name of referencedNames) {
|
|
104
|
+
const securityScheme = entry.securityDefinitions.get(name);
|
|
105
|
+
if (!(0, _apidomNsOpenapi.isSecuritySchemeElement)(securityScheme)) continue;
|
|
106
|
+
securityDefinitions.set(name, securityScheme);
|
|
107
|
+
}
|
|
108
|
+
return securityDefinitions;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
var _default = exports.default = OpenAPI2DocumentAssembler;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { toValue } from '@speclynx/apidom-core';
|
|
2
|
+
import { isArrayElement, isElement, ParseResultElement } from '@speclynx/apidom-datamodel';
|
|
3
|
+
import { compile } from '@speclynx/apidom-json-pointer';
|
|
4
|
+
import { SwaggerElement, PathsElement, PathItemElement, SecurityDefinitionsElement, isSwaggerElement, isSecurityRequirementElement, isSecurityDefinitionsElement, isSecuritySchemeElement } from '@speclynx/apidom-ns-openapi-2';
|
|
5
|
+
import OpenAPIDocument from "../document/OpenAPIDocument.mjs";
|
|
6
|
+
import OpenAPIOperationIndex from "../document/OpenAPIOperationIndex.mjs";
|
|
7
|
+
import AssemblerError from "../errors/AssemblerError.mjs";
|
|
8
|
+
/**
|
|
9
|
+
* Assembles a standalone OpenAPI 2.0 (Swagger) document from a
|
|
10
|
+
* normalized operation element.
|
|
11
|
+
*
|
|
12
|
+
* The assembled document is a valid Swagger 2.0 specification containing
|
|
13
|
+
* only the single operation with its host, basePath, schemes, and
|
|
14
|
+
* referenced security definitions from the source document.
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
class OpenAPI2DocumentAssembler {
|
|
18
|
+
/**
|
|
19
|
+
* Assembles a standalone Swagger 2.0 document from a normalized operation.
|
|
20
|
+
*/
|
|
21
|
+
assemble(operation, document) {
|
|
22
|
+
const entry = document.parseResult.api;
|
|
23
|
+
const method = toValue(operation.meta.get('http-method'));
|
|
24
|
+
const path = toValue(operation.meta.get('path'));
|
|
25
|
+
if (typeof method !== 'string' || typeof path !== 'string') {
|
|
26
|
+
throw new AssemblerError(`Operation is missing valid "http-method" or "path" metadata. Was it produced by OpenAPIOperationExtractor?`, {
|
|
27
|
+
uri: document.uri,
|
|
28
|
+
operationId: toValue(operation.operationId)
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if (!isSwaggerElement(entry)) {
|
|
32
|
+
throw new AssemblerError(`Expected OpenAPI 2.0 document at "${document.uri}"`, {
|
|
33
|
+
uri: document.uri
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// build Swagger 2.0 document
|
|
38
|
+
const swagger = new SwaggerElement({
|
|
39
|
+
swagger: entry.swagger
|
|
40
|
+
}, {
|
|
41
|
+
classes: ['api']
|
|
42
|
+
});
|
|
43
|
+
// prettier-ignore
|
|
44
|
+
{
|
|
45
|
+
if (isElement(entry.info)) swagger.info = entry.info;
|
|
46
|
+
if (isElement(entry.host)) swagger.host = entry.host;
|
|
47
|
+
if (isElement(entry.basePath)) swagger.basePath = entry.basePath;
|
|
48
|
+
if (isElement(entry.schemes)) swagger.schemes = entry.schemes;
|
|
49
|
+
if (isElement(entry.consumes)) swagger.consumes = entry.consumes;
|
|
50
|
+
if (isElement(entry.produces)) swagger.produces = entry.produces;
|
|
51
|
+
if (isElement(entry.tags)) swagger.tags = entry.tags;
|
|
52
|
+
if (isElement(entry.externalDocs)) swagger.externalDocs = entry.externalDocs;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// build paths with single operation
|
|
56
|
+
const pathItem = new PathItemElement();
|
|
57
|
+
const paths = new PathsElement();
|
|
58
|
+
pathItem.set(method, operation);
|
|
59
|
+
paths.set(path, pathItem);
|
|
60
|
+
swagger.paths = paths;
|
|
61
|
+
|
|
62
|
+
// include only referenced security definitions
|
|
63
|
+
const securityDefinitions = this.#extractReferencedSecurityDefinitions(operation, entry);
|
|
64
|
+
if (securityDefinitions.length > 0) {
|
|
65
|
+
swagger.securityDefinitions = securityDefinitions;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// wrap in ParseResultElement and return as OpenAPIDocument
|
|
69
|
+
const parseResult = new ParseResultElement([swagger]);
|
|
70
|
+
const operationIndex = new OpenAPIOperationIndex();
|
|
71
|
+
const operationId = toValue(operation.operationId);
|
|
72
|
+
if (typeof operationId === 'string' && operationId.length > 0) {
|
|
73
|
+
operationIndex.set(operationId, compile(['paths', path, method]));
|
|
74
|
+
}
|
|
75
|
+
return new OpenAPIDocument(document.uri, parseResult, operationIndex);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Extracts only the security definitions referenced by the operation's
|
|
80
|
+
* security requirements.
|
|
81
|
+
*/
|
|
82
|
+
#extractReferencedSecurityDefinitions(operation, entry) {
|
|
83
|
+
const securityDefinitions = new SecurityDefinitionsElement();
|
|
84
|
+
if (!isArrayElement(operation.security)) return securityDefinitions;
|
|
85
|
+
if (!isSecurityDefinitionsElement(entry.securityDefinitions)) return securityDefinitions;
|
|
86
|
+
|
|
87
|
+
// collect referenced names of Security Definitions
|
|
88
|
+
const referencedNames = new Set();
|
|
89
|
+
for (const securityRequirement of operation.security) {
|
|
90
|
+
if (!isSecurityRequirementElement(securityRequirement)) continue;
|
|
91
|
+
securityRequirement.forEach((_value, keyElement) => {
|
|
92
|
+
referencedNames.add(toValue(keyElement));
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (referencedNames.size === 0) return securityDefinitions;
|
|
96
|
+
for (const name of referencedNames) {
|
|
97
|
+
const securityScheme = entry.securityDefinitions.get(name);
|
|
98
|
+
if (!isSecuritySchemeElement(securityScheme)) continue;
|
|
99
|
+
securityDefinitions.set(name, securityScheme);
|
|
100
|
+
}
|
|
101
|
+
return securityDefinitions;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export default OpenAPI2DocumentAssembler;
|
|
@@ -0,0 +1,110 @@
|
|
|
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 _apidomJsonPointer = require("@speclynx/apidom-json-pointer");
|
|
11
|
+
var _apidomNsOpenapi = require("@speclynx/apidom-ns-openapi-3-0");
|
|
12
|
+
var _OpenAPIDocument = _interopRequireDefault(require("../document/OpenAPIDocument.cjs"));
|
|
13
|
+
var _OpenAPIOperationIndex = _interopRequireDefault(require("../document/OpenAPIOperationIndex.cjs"));
|
|
14
|
+
var _AssemblerError = _interopRequireDefault(require("../errors/AssemblerError.cjs"));
|
|
15
|
+
/**
|
|
16
|
+
* Assembles a standalone OpenAPI 3.0 document from a
|
|
17
|
+
* normalized operation element.
|
|
18
|
+
*
|
|
19
|
+
* The assembled document is a valid OpenAPI 3.0 specification containing
|
|
20
|
+
* only the single operation with its servers, and referenced security
|
|
21
|
+
* schemes from the source document's components.
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
class OpenAPI30DocumentAssembler {
|
|
25
|
+
/**
|
|
26
|
+
* Assembles a standalone OpenAPI 3.0 document from a normalized operation.
|
|
27
|
+
*/
|
|
28
|
+
assemble(operation, document) {
|
|
29
|
+
const entry = document.parseResult.api;
|
|
30
|
+
const method = (0, _apidomCore.toValue)(operation.meta.get('http-method'));
|
|
31
|
+
const path = (0, _apidomCore.toValue)(operation.meta.get('path'));
|
|
32
|
+
if (typeof method !== 'string' || typeof path !== 'string') {
|
|
33
|
+
throw new _AssemblerError.default(`Operation is missing valid "http-method" or "path" metadata. Was it produced by OpenAPIOperationExtractor?`, {
|
|
34
|
+
uri: document.uri,
|
|
35
|
+
operationId: (0, _apidomCore.toValue)(operation.operationId)
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (!(0, _apidomNsOpenapi.isOpenApi3_0Element)(entry)) {
|
|
39
|
+
throw new _AssemblerError.default(`Expected OpenAPI 3.0 document at "${document.uri}"`, {
|
|
40
|
+
uri: document.uri,
|
|
41
|
+
operationId: (0, _apidomCore.toValue)(operation.operationId)
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// build OpenAPI 3.0 document
|
|
46
|
+
const openapi = new _apidomNsOpenapi.OpenApi3_0Element({
|
|
47
|
+
openapi: entry.openapi
|
|
48
|
+
}, {
|
|
49
|
+
classes: ['api']
|
|
50
|
+
});
|
|
51
|
+
// prettier-ignore
|
|
52
|
+
{
|
|
53
|
+
if ((0, _apidomDatamodel.isElement)(entry.info)) openapi.info = entry.info;
|
|
54
|
+
if ((0, _apidomDatamodel.isElement)(entry.tags)) openapi.tags = entry.tags;
|
|
55
|
+
if ((0, _apidomDatamodel.isElement)(entry.externalDocs)) openapi.externalDocs = entry.externalDocs;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// build paths with single operation
|
|
59
|
+
const pathItem = new _apidomNsOpenapi.PathItemElement();
|
|
60
|
+
const paths = new _apidomNsOpenapi.PathsElement();
|
|
61
|
+
pathItem.set(method, operation);
|
|
62
|
+
paths.set(path, pathItem);
|
|
63
|
+
openapi.paths = paths;
|
|
64
|
+
|
|
65
|
+
// include only referenced security schemes in components
|
|
66
|
+
const securitySchemes = this.#extractReferencedSecuritySchemes(operation, entry);
|
|
67
|
+
if (securitySchemes.length > 0) {
|
|
68
|
+
const components = new _apidomNsOpenapi.ComponentsElement();
|
|
69
|
+
components.securitySchemes = securitySchemes;
|
|
70
|
+
openapi.components = components;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// wrap in ParseResultElement and return as OpenAPIDocument
|
|
74
|
+
const parseResult = new _apidomDatamodel.ParseResultElement([openapi]);
|
|
75
|
+
const operationIndex = new _OpenAPIOperationIndex.default();
|
|
76
|
+
const operationId = (0, _apidomCore.toValue)(operation.operationId);
|
|
77
|
+
if (typeof operationId === 'string' && operationId.length > 0) {
|
|
78
|
+
operationIndex.set(operationId, (0, _apidomJsonPointer.compile)(['paths', path, method]));
|
|
79
|
+
}
|
|
80
|
+
return new _OpenAPIDocument.default(document.uri, parseResult, operationIndex);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Extracts only the security schemes referenced by the operation's
|
|
85
|
+
* security requirements.
|
|
86
|
+
*/
|
|
87
|
+
#extractReferencedSecuritySchemes(operation, entry) {
|
|
88
|
+
const securitySchemes = new _apidomDatamodel.ObjectElement();
|
|
89
|
+
if (!(0, _apidomDatamodel.isArrayElement)(operation.security)) return securitySchemes;
|
|
90
|
+
if (entry.components === undefined) return securitySchemes;
|
|
91
|
+
if (entry.components.securitySchemes === undefined) return securitySchemes;
|
|
92
|
+
|
|
93
|
+
// collect referenced names of security schemes
|
|
94
|
+
const referencedNames = new Set();
|
|
95
|
+
for (const securityRequirement of operation.security) {
|
|
96
|
+
if (!(0, _apidomNsOpenapi.isSecurityRequirementElement)(securityRequirement)) continue;
|
|
97
|
+
securityRequirement.forEach((_value, keyElement) => {
|
|
98
|
+
referencedNames.add((0, _apidomCore.toValue)(keyElement));
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (referencedNames.size === 0) return securitySchemes;
|
|
102
|
+
for (const name of referencedNames) {
|
|
103
|
+
const securityScheme = entry.components.securitySchemes.get(name);
|
|
104
|
+
if (!(0, _apidomNsOpenapi.isSecuritySchemeElement)(securityScheme)) continue;
|
|
105
|
+
securitySchemes.set(name, securityScheme);
|
|
106
|
+
}
|
|
107
|
+
return securitySchemes;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
var _default = exports.default = OpenAPI30DocumentAssembler;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { toValue } from '@speclynx/apidom-core';
|
|
2
|
+
import { isArrayElement, isElement, ObjectElement, ParseResultElement } from '@speclynx/apidom-datamodel';
|
|
3
|
+
import { compile } from '@speclynx/apidom-json-pointer';
|
|
4
|
+
import { OpenApi3_0Element, ComponentsElement, PathsElement, PathItemElement, isOpenApi3_0Element, isSecurityRequirementElement, isSecuritySchemeElement } from '@speclynx/apidom-ns-openapi-3-0';
|
|
5
|
+
import OpenAPIDocument from "../document/OpenAPIDocument.mjs";
|
|
6
|
+
import OpenAPIOperationIndex from "../document/OpenAPIOperationIndex.mjs";
|
|
7
|
+
import AssemblerError from "../errors/AssemblerError.mjs";
|
|
8
|
+
/**
|
|
9
|
+
* Assembles a standalone OpenAPI 3.0 document from a
|
|
10
|
+
* normalized operation element.
|
|
11
|
+
*
|
|
12
|
+
* The assembled document is a valid OpenAPI 3.0 specification containing
|
|
13
|
+
* only the single operation with its servers, and referenced security
|
|
14
|
+
* schemes from the source document's components.
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
class OpenAPI30DocumentAssembler {
|
|
18
|
+
/**
|
|
19
|
+
* Assembles a standalone OpenAPI 3.0 document from a normalized operation.
|
|
20
|
+
*/
|
|
21
|
+
assemble(operation, document) {
|
|
22
|
+
const entry = document.parseResult.api;
|
|
23
|
+
const method = toValue(operation.meta.get('http-method'));
|
|
24
|
+
const path = toValue(operation.meta.get('path'));
|
|
25
|
+
if (typeof method !== 'string' || typeof path !== 'string') {
|
|
26
|
+
throw new AssemblerError(`Operation is missing valid "http-method" or "path" metadata. Was it produced by OpenAPIOperationExtractor?`, {
|
|
27
|
+
uri: document.uri,
|
|
28
|
+
operationId: toValue(operation.operationId)
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if (!isOpenApi3_0Element(entry)) {
|
|
32
|
+
throw new AssemblerError(`Expected OpenAPI 3.0 document at "${document.uri}"`, {
|
|
33
|
+
uri: document.uri,
|
|
34
|
+
operationId: toValue(operation.operationId)
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// build OpenAPI 3.0 document
|
|
39
|
+
const openapi = new OpenApi3_0Element({
|
|
40
|
+
openapi: entry.openapi
|
|
41
|
+
}, {
|
|
42
|
+
classes: ['api']
|
|
43
|
+
});
|
|
44
|
+
// prettier-ignore
|
|
45
|
+
{
|
|
46
|
+
if (isElement(entry.info)) openapi.info = entry.info;
|
|
47
|
+
if (isElement(entry.tags)) openapi.tags = entry.tags;
|
|
48
|
+
if (isElement(entry.externalDocs)) openapi.externalDocs = entry.externalDocs;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// build paths with single operation
|
|
52
|
+
const pathItem = new PathItemElement();
|
|
53
|
+
const paths = new PathsElement();
|
|
54
|
+
pathItem.set(method, operation);
|
|
55
|
+
paths.set(path, pathItem);
|
|
56
|
+
openapi.paths = paths;
|
|
57
|
+
|
|
58
|
+
// include only referenced security schemes in components
|
|
59
|
+
const securitySchemes = this.#extractReferencedSecuritySchemes(operation, entry);
|
|
60
|
+
if (securitySchemes.length > 0) {
|
|
61
|
+
const components = new ComponentsElement();
|
|
62
|
+
components.securitySchemes = securitySchemes;
|
|
63
|
+
openapi.components = components;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// wrap in ParseResultElement and return as OpenAPIDocument
|
|
67
|
+
const parseResult = new ParseResultElement([openapi]);
|
|
68
|
+
const operationIndex = new OpenAPIOperationIndex();
|
|
69
|
+
const operationId = toValue(operation.operationId);
|
|
70
|
+
if (typeof operationId === 'string' && operationId.length > 0) {
|
|
71
|
+
operationIndex.set(operationId, compile(['paths', path, method]));
|
|
72
|
+
}
|
|
73
|
+
return new OpenAPIDocument(document.uri, parseResult, operationIndex);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Extracts only the security schemes referenced by the operation's
|
|
78
|
+
* security requirements.
|
|
79
|
+
*/
|
|
80
|
+
#extractReferencedSecuritySchemes(operation, entry) {
|
|
81
|
+
const securitySchemes = new ObjectElement();
|
|
82
|
+
if (!isArrayElement(operation.security)) return securitySchemes;
|
|
83
|
+
if (entry.components === undefined) return securitySchemes;
|
|
84
|
+
if (entry.components.securitySchemes === undefined) return securitySchemes;
|
|
85
|
+
|
|
86
|
+
// collect referenced names of security schemes
|
|
87
|
+
const referencedNames = new Set();
|
|
88
|
+
for (const securityRequirement of operation.security) {
|
|
89
|
+
if (!isSecurityRequirementElement(securityRequirement)) continue;
|
|
90
|
+
securityRequirement.forEach((_value, keyElement) => {
|
|
91
|
+
referencedNames.add(toValue(keyElement));
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (referencedNames.size === 0) return securitySchemes;
|
|
95
|
+
for (const name of referencedNames) {
|
|
96
|
+
const securityScheme = entry.components.securitySchemes.get(name);
|
|
97
|
+
if (!isSecuritySchemeElement(securityScheme)) continue;
|
|
98
|
+
securitySchemes.set(name, securityScheme);
|
|
99
|
+
}
|
|
100
|
+
return securitySchemes;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
export default OpenAPI30DocumentAssembler;
|
|
@@ -0,0 +1,111 @@
|
|
|
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 _apidomJsonPointer = require("@speclynx/apidom-json-pointer");
|
|
11
|
+
var _apidomNsOpenapi = require("@speclynx/apidom-ns-openapi-3-1");
|
|
12
|
+
var _OpenAPIDocument = _interopRequireDefault(require("../document/OpenAPIDocument.cjs"));
|
|
13
|
+
var _OpenAPIOperationIndex = _interopRequireDefault(require("../document/OpenAPIOperationIndex.cjs"));
|
|
14
|
+
var _AssemblerError = _interopRequireDefault(require("../errors/AssemblerError.cjs"));
|
|
15
|
+
/**
|
|
16
|
+
* Assembles a standalone OpenAPI 3.1 document from a
|
|
17
|
+
* normalized operation element.
|
|
18
|
+
*
|
|
19
|
+
* The assembled document is a valid OpenAPI 3.1 specification containing
|
|
20
|
+
* only the single operation with its servers, and referenced security
|
|
21
|
+
* schemes from the source document's components.
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
class OpenAPI31DocumentAssembler {
|
|
25
|
+
/**
|
|
26
|
+
* Assembles a standalone OpenAPI 3.1 document from a normalized operation.
|
|
27
|
+
*/
|
|
28
|
+
assemble(operation, document) {
|
|
29
|
+
const entry = document.parseResult.api;
|
|
30
|
+
const method = (0, _apidomCore.toValue)(operation.meta.get('http-method'));
|
|
31
|
+
const path = (0, _apidomCore.toValue)(operation.meta.get('path'));
|
|
32
|
+
if (typeof method !== 'string' || typeof path !== 'string') {
|
|
33
|
+
throw new _AssemblerError.default(`Operation is missing valid "http-method" or "path" metadata. Was it produced by OpenAPIOperationExtractor?`, {
|
|
34
|
+
uri: document.uri,
|
|
35
|
+
operationId: (0, _apidomCore.toValue)(operation.operationId)
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (!(0, _apidomNsOpenapi.isOpenApi3_1Element)(entry)) {
|
|
39
|
+
throw new _AssemblerError.default(`Expected OpenAPI 3.1 document at "${document.uri}"`, {
|
|
40
|
+
uri: document.uri,
|
|
41
|
+
operationId: (0, _apidomCore.toValue)(operation.operationId)
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// build OpenAPI 3.1 document
|
|
46
|
+
const openapi = new _apidomNsOpenapi.OpenApi3_1Element({
|
|
47
|
+
openapi: entry.openapi
|
|
48
|
+
}, {
|
|
49
|
+
classes: ['api']
|
|
50
|
+
});
|
|
51
|
+
// prettier-ignore
|
|
52
|
+
{
|
|
53
|
+
if ((0, _apidomDatamodel.isElement)(entry.info)) openapi.info = entry.info;
|
|
54
|
+
if ((0, _apidomDatamodel.isElement)(entry.tags)) openapi.tags = entry.tags;
|
|
55
|
+
if ((0, _apidomDatamodel.isElement)(entry.externalDocs)) openapi.externalDocs = entry.externalDocs;
|
|
56
|
+
if ((0, _apidomDatamodel.isElement)(entry.jsonSchemaDialect)) openapi.jsonSchemaDialect = entry.jsonSchemaDialect;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// build paths with single operation
|
|
60
|
+
const pathItem = new _apidomNsOpenapi.PathItemElement();
|
|
61
|
+
const paths = new _apidomNsOpenapi.PathsElement();
|
|
62
|
+
pathItem.set(method, operation);
|
|
63
|
+
paths.set(path, pathItem);
|
|
64
|
+
openapi.paths = paths;
|
|
65
|
+
|
|
66
|
+
// include only referenced security schemes in components
|
|
67
|
+
const securitySchemes = this.#extractReferencedSecuritySchemes(operation, entry);
|
|
68
|
+
if (securitySchemes.length > 0) {
|
|
69
|
+
const components = new _apidomNsOpenapi.ComponentsElement();
|
|
70
|
+
components.securitySchemes = securitySchemes;
|
|
71
|
+
openapi.components = components;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// wrap in ParseResultElement and return as OpenAPIDocument
|
|
75
|
+
const parseResult = new _apidomDatamodel.ParseResultElement([openapi]);
|
|
76
|
+
const operationIndex = new _OpenAPIOperationIndex.default();
|
|
77
|
+
const operationId = (0, _apidomCore.toValue)(operation.operationId);
|
|
78
|
+
if (typeof operationId === 'string' && operationId.length > 0) {
|
|
79
|
+
operationIndex.set(operationId, (0, _apidomJsonPointer.compile)(['paths', path, method]));
|
|
80
|
+
}
|
|
81
|
+
return new _OpenAPIDocument.default(document.uri, parseResult, operationIndex);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Extracts only the security schemes referenced by the operation's
|
|
86
|
+
* security requirements.
|
|
87
|
+
*/
|
|
88
|
+
#extractReferencedSecuritySchemes(operation, entry) {
|
|
89
|
+
const securitySchemes = new _apidomDatamodel.ObjectElement();
|
|
90
|
+
if (!(0, _apidomDatamodel.isArrayElement)(operation.security)) return securitySchemes;
|
|
91
|
+
if (entry.components === undefined) return securitySchemes;
|
|
92
|
+
if (entry.components.securitySchemes === undefined) return securitySchemes;
|
|
93
|
+
|
|
94
|
+
// collect referenced names of security schemes
|
|
95
|
+
const referencedNames = new Set();
|
|
96
|
+
for (const securityRequirement of operation.security) {
|
|
97
|
+
if (!(0, _apidomNsOpenapi.isSecurityRequirementElement)(securityRequirement)) continue;
|
|
98
|
+
securityRequirement.forEach((_value, keyElement) => {
|
|
99
|
+
referencedNames.add((0, _apidomCore.toValue)(keyElement));
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
if (referencedNames.size === 0) return securitySchemes;
|
|
103
|
+
for (const name of referencedNames) {
|
|
104
|
+
const securityScheme = entry.components.securitySchemes.get(name);
|
|
105
|
+
if (!(0, _apidomNsOpenapi.isSecuritySchemeElement)(securityScheme)) continue;
|
|
106
|
+
securitySchemes.set(name, securityScheme);
|
|
107
|
+
}
|
|
108
|
+
return securitySchemes;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
var _default = exports.default = OpenAPI31DocumentAssembler;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { toValue } from '@speclynx/apidom-core';
|
|
2
|
+
import { isArrayElement, isElement, ObjectElement, ParseResultElement } from '@speclynx/apidom-datamodel';
|
|
3
|
+
import { compile } from '@speclynx/apidom-json-pointer';
|
|
4
|
+
import { OpenApi3_1Element, ComponentsElement, PathsElement, PathItemElement, isOpenApi3_1Element, isSecurityRequirementElement, isSecuritySchemeElement } from '@speclynx/apidom-ns-openapi-3-1';
|
|
5
|
+
import OpenAPIDocument from "../document/OpenAPIDocument.mjs";
|
|
6
|
+
import OpenAPIOperationIndex from "../document/OpenAPIOperationIndex.mjs";
|
|
7
|
+
import AssemblerError from "../errors/AssemblerError.mjs";
|
|
8
|
+
/**
|
|
9
|
+
* Assembles a standalone OpenAPI 3.1 document from a
|
|
10
|
+
* normalized operation element.
|
|
11
|
+
*
|
|
12
|
+
* The assembled document is a valid OpenAPI 3.1 specification containing
|
|
13
|
+
* only the single operation with its servers, and referenced security
|
|
14
|
+
* schemes from the source document's components.
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
class OpenAPI31DocumentAssembler {
|
|
18
|
+
/**
|
|
19
|
+
* Assembles a standalone OpenAPI 3.1 document from a normalized operation.
|
|
20
|
+
*/
|
|
21
|
+
assemble(operation, document) {
|
|
22
|
+
const entry = document.parseResult.api;
|
|
23
|
+
const method = toValue(operation.meta.get('http-method'));
|
|
24
|
+
const path = toValue(operation.meta.get('path'));
|
|
25
|
+
if (typeof method !== 'string' || typeof path !== 'string') {
|
|
26
|
+
throw new AssemblerError(`Operation is missing valid "http-method" or "path" metadata. Was it produced by OpenAPIOperationExtractor?`, {
|
|
27
|
+
uri: document.uri,
|
|
28
|
+
operationId: toValue(operation.operationId)
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if (!isOpenApi3_1Element(entry)) {
|
|
32
|
+
throw new AssemblerError(`Expected OpenAPI 3.1 document at "${document.uri}"`, {
|
|
33
|
+
uri: document.uri,
|
|
34
|
+
operationId: toValue(operation.operationId)
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// build OpenAPI 3.1 document
|
|
39
|
+
const openapi = new OpenApi3_1Element({
|
|
40
|
+
openapi: entry.openapi
|
|
41
|
+
}, {
|
|
42
|
+
classes: ['api']
|
|
43
|
+
});
|
|
44
|
+
// prettier-ignore
|
|
45
|
+
{
|
|
46
|
+
if (isElement(entry.info)) openapi.info = entry.info;
|
|
47
|
+
if (isElement(entry.tags)) openapi.tags = entry.tags;
|
|
48
|
+
if (isElement(entry.externalDocs)) openapi.externalDocs = entry.externalDocs;
|
|
49
|
+
if (isElement(entry.jsonSchemaDialect)) openapi.jsonSchemaDialect = entry.jsonSchemaDialect;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// build paths with single operation
|
|
53
|
+
const pathItem = new PathItemElement();
|
|
54
|
+
const paths = new PathsElement();
|
|
55
|
+
pathItem.set(method, operation);
|
|
56
|
+
paths.set(path, pathItem);
|
|
57
|
+
openapi.paths = paths;
|
|
58
|
+
|
|
59
|
+
// include only referenced security schemes in components
|
|
60
|
+
const securitySchemes = this.#extractReferencedSecuritySchemes(operation, entry);
|
|
61
|
+
if (securitySchemes.length > 0) {
|
|
62
|
+
const components = new ComponentsElement();
|
|
63
|
+
components.securitySchemes = securitySchemes;
|
|
64
|
+
openapi.components = components;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// wrap in ParseResultElement and return as OpenAPIDocument
|
|
68
|
+
const parseResult = new ParseResultElement([openapi]);
|
|
69
|
+
const operationIndex = new OpenAPIOperationIndex();
|
|
70
|
+
const operationId = toValue(operation.operationId);
|
|
71
|
+
if (typeof operationId === 'string' && operationId.length > 0) {
|
|
72
|
+
operationIndex.set(operationId, compile(['paths', path, method]));
|
|
73
|
+
}
|
|
74
|
+
return new OpenAPIDocument(document.uri, parseResult, operationIndex);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Extracts only the security schemes referenced by the operation's
|
|
79
|
+
* security requirements.
|
|
80
|
+
*/
|
|
81
|
+
#extractReferencedSecuritySchemes(operation, entry) {
|
|
82
|
+
const securitySchemes = new ObjectElement();
|
|
83
|
+
if (!isArrayElement(operation.security)) return securitySchemes;
|
|
84
|
+
if (entry.components === undefined) return securitySchemes;
|
|
85
|
+
if (entry.components.securitySchemes === undefined) return securitySchemes;
|
|
86
|
+
|
|
87
|
+
// collect referenced names of security schemes
|
|
88
|
+
const referencedNames = new Set();
|
|
89
|
+
for (const securityRequirement of operation.security) {
|
|
90
|
+
if (!isSecurityRequirementElement(securityRequirement)) continue;
|
|
91
|
+
securityRequirement.forEach((_value, keyElement) => {
|
|
92
|
+
referencedNames.add(toValue(keyElement));
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (referencedNames.size === 0) return securitySchemes;
|
|
96
|
+
for (const name of referencedNames) {
|
|
97
|
+
const securityScheme = entry.components.securitySchemes.get(name);
|
|
98
|
+
if (!isSecuritySchemeElement(securityScheme)) continue;
|
|
99
|
+
securitySchemes.set(name, securityScheme);
|
|
100
|
+
}
|
|
101
|
+
return securitySchemes;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export default OpenAPI31DocumentAssembler;
|