@@ -50,18 +50,18 @@ interface ActionDataType {
50
50
[key: string]: any;
51
51
}
52
52
53
- export async function runOpenApi(
54
- actionData: ActionDataType,
55
- dataSourceConfig: DataSourceDataType,
53
+ async function getDefinitions(
56
54
spec: OpenAPI.Document | MultiOpenApiSpecItem[],
57
- defaultHeaders?: Record<string, string>,
58
55
openApiSpecDereferenced?: OpenAPI.Document,
59
- ) {
60
- const specList = Array.isArray(spec) ? spec : [{ spec, id: "" }];
61
- let definitions;
62
-
63
- if (!openApiSpecDereferenced) {
64
- definitions = await Promise.all(
56
+ ): Promise<{ def: OpenAPI.Document; id: string }[]> {
57
+ if (openApiSpecDereferenced) {
58
+ return [{
59
+ def: openApiSpecDereferenced,
60
+ id: "",
61
+ }]
62
+ } else {
63
+ const specList = Array.isArray(spec) ? spec : [{ spec, id: "" }];
64
+ return await Promise.all(
65
65
specList.map(async ({id, spec}) => {
66
66
const deRefedSpec = await SwaggerParser.dereference(spec);
67
67
return {
@@ -70,20 +70,22 @@ export async function runOpenApi(
70
70
};
71
71
})
72
72
);
73
- } else {
74
- definitions = [{
75
- def: openApiSpecDereferenced,
76
- id: "",
77
- }]
78
73
}
74
+ }
75
+
76
+ export async function runOpenApi(
77
+ actionData: ActionDataType,
78
+ dataSourceConfig: DataSourceDataType,
79
+ spec: OpenAPI.Document | MultiOpenApiSpecItem[],
80
+ defaultHeaders?: Record<string, string>,
81
+ openApiSpecDereferenced?: OpenAPI.Document,
82
+ ) {
79
83
const { actionName, ...otherActionData } = actionData;
80
84
const { serverURL } = dataSourceConfig;
81
85
82
- let definition: OpenAPI.Document | undefined;
83
- let operation;
84
- let realOperationId;
86
+ let operation, realOperationId, definition: OpenAPI.Document | undefined;
85
87
86
- for (const { id, def } of definitions ) {
88
+ for (const {id, def} of await getDefinitions(spec, openApiSpecDereferenced) ) {
87
89
const ret = findOperation(actionName, def, id);
88
90
if (ret) {
89
91
definition = def;
0 commit comments