Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd1e6f92

Browse files
committed
Optimize the runOpenApi plugin
allow passing in an already dereferenced OpenAPI Document for pluginsthat have large openapi specs like github. This takes the runtime forGithub from over 10s to ~1s on an M1 Max.Adjust the github plugin to use this new capability by dereferencing onplugin initialization, passing the derefed document to the runOpenApifunction.
1 parent4f80cae commitd1e6f92

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

‎server/node-service/src/plugins/github/index.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { OpenAPIV3, OpenAPI } from "openapi-types";
55
import{ConfigToType,DataSourcePlugin}from"lowcoder-sdk/dataSource";
66
import{runOpenApi}from"../openApi";
77
import{parseOpenApi,ParseOpenApiOptions}from"../openApi/parse";
8+
importSwaggerParserfrom"@apidevtools/swagger-parser";
89

910
constspec=readYaml(path.join(__dirname,"./github.spec.yaml"));
1011

@@ -34,6 +35,7 @@ const parseOptions: ParseOpenApiOptions = {
3435
return_.upperFirst(operation.operationId||"");
3536
},
3637
};
38+
constdeRefedSpec=SwaggerParser.dereference(spec);
3739

3840
typeDataSourceConfigType=ConfigToType<typeofdataSourceConfig>;
3941

@@ -55,13 +57,13 @@ const gitHubPlugin: DataSourcePlugin<any, DataSourceConfigType> = {
5557
actions,
5658
};
5759
},
58-
run:function(actionData,dataSourceConfig):Promise<any>{
60+
run:asyncfunction(actionData,dataSourceConfig,ctx):Promise<any>{
5961
construnApiDsConfig={
6062
url:"",
6163
serverURL:"https://api.github.com",
6264
dynamicParamsConfig:dataSourceConfig,
6365
};
64-
returnrunOpenApi(actionData,runApiDsConfig,specasOpenAPIV3.Document);
66+
returnrunOpenApi(actionData,runApiDsConfig,specasOpenAPIV3.Document,undefined,awaitdeRefedSpec);
6567
},
6668
};
6769

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,28 @@ export async function runOpenApi(
5454
actionData:ActionDataType,
5555
dataSourceConfig:DataSourceDataType,
5656
spec:OpenAPI.Document|MultiOpenApiSpecItem[],
57-
defaultHeaders?:Record<string,string>
57+
defaultHeaders?:Record<string,string>,
58+
openApiSpecDereferenced?:OpenAPI.Document,
5859
){
5960
constspecList=Array.isArray(spec) ?spec :[{ spec,id:""}];
60-
constdefinitions=awaitPromise.all(
61-
specList.map(async({ id, spec})=>{
62-
constdeRefedSpec=awaitSwaggerParser.dereference(spec);
63-
return{
64-
def:deRefedSpec,
65-
id,
66-
};
67-
})
68-
);
61+
letdefinitions;
62+
63+
if(!openApiSpecDereferenced){
64+
definitions=awaitPromise.all(
65+
specList.map(async({id, spec})=>{
66+
constdeRefedSpec=awaitSwaggerParser.dereference(spec);
67+
return{
68+
def:deRefedSpec,
69+
id,
70+
};
71+
})
72+
);
73+
}else{
74+
definitions=[{
75+
def:openApiSpecDereferenced,
76+
id:"",
77+
}]
78+
}
6979
const{ actionName, ...otherActionData}=actionData;
7080
const{ serverURL}=dataSourceConfig;
7181

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp