Skip to content

Commit ed4f40b

Browse files
committed
Pull definition logic into a new function
1 parent d1e6f92 commit ed4f40b

File tree

1 file changed

+21
-19
lines changed
  • server/node-service/src/plugins/openApi

1 file changed

+21
-19
lines changed

server/node-service/src/plugins/openApi/index.ts

+21-19
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@ interface ActionDataType {
5050
[key: string]: any;
5151
}
5252

53-
export async function runOpenApi(
54-
actionData: ActionDataType,
55-
dataSourceConfig: DataSourceDataType,
53+
async function getDefinitions(
5654
spec: OpenAPI.Document | MultiOpenApiSpecItem[],
57-
defaultHeaders?: Record<string, string>,
5855
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(
6565
specList.map(async ({id, spec}) => {
6666
const deRefedSpec = await SwaggerParser.dereference(spec);
6767
return {
@@ -70,20 +70,22 @@ export async function runOpenApi(
7070
};
7171
})
7272
);
73-
} else {
74-
definitions = [{
75-
def: openApiSpecDereferenced,
76-
id: "",
77-
}]
7873
}
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+
) {
7983
const { actionName, ...otherActionData } = actionData;
8084
const { serverURL } = dataSourceConfig;
8185

82-
let definition: OpenAPI.Document | undefined;
83-
let operation;
84-
let realOperationId;
86+
let operation, realOperationId, definition: OpenAPI.Document | undefined;
8587

86-
for (const { id, def } of definitions) {
88+
for (const {id, def} of await getDefinitions(spec, openApiSpecDereferenced)) {
8789
const ret = findOperation(actionName, def, id);
8890
if (ret) {
8991
definition = def;

0 commit comments

Comments
 (0)