Skip to content

Commit 3bf3ebf

Browse files
snowe2010FalkWolsky
authored and
FalkWolsky
committed
Optimize the runOpenApi plugin
allow passing in an already dereferenced OpenAPI Document for plugins that have large openapi specs like github. This takes the runtime for Github from over 10s to ~1s on an M1 Max. Adjust the github plugin to use this new capability by dereferencing on plugin initialization, passing the derefed document to the runOpenApi function.
1 parent da62927 commit 3bf3ebf

File tree

1 file changed

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

1 file changed

+21
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,27 @@ export async function runOpenApi(
7979
defaultHeaders?: Record<string, string>,
8080
openApiSpecDereferenced?: OpenAPI.Document,
8181
) {
82+
83+
const specList = Array.isArray(spec) ? spec : [{ spec, id: "" }];
84+
let definitions;
85+
86+
if (!openApiSpecDereferenced) {
87+
definitions = await Promise.all(
88+
specList.map(async ({id, spec}) => {
89+
const deRefedSpec = await SwaggerParser.dereference(spec);
90+
return {
91+
def: deRefedSpec,
92+
id,
93+
};
94+
})
95+
);
96+
} else {
97+
definitions = [{
98+
def: openApiSpecDereferenced,
99+
id: "",
100+
}]
101+
}
102+
82103
const { actionName, ...otherActionData } = actionData;
83104
const { serverURL } = dataSourceConfig;
84105

0 commit comments

Comments
 (0)