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

Commitffa595a

Browse files
authored
Merge pull request#750 from snowe2010/optimize-runOpenApi
optimize /runOpenApi to allow pre-dereferencing OpenAPI Spec
2 parents4f80cae +275cf68 commitffa595a

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
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: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ import {
1212
isFile,
1313
}from"./util";
1414
import{badRequest}from"../../common/error";
15-
import{safeJsonParse}from"../../common/util";
1615
import{OpenAPI,OpenAPIV2,OpenAPIV3}from"openapi-types";
1716
import_from"lodash";
1817
import{fetch}from"../../common/fetch";
19-
import{RequestInit,Response}from"node-fetch";
18+
import{RequestInit}from"node-fetch";
2019

2120
constdataSourceConfig={
2221
type:"dataSource",
@@ -50,30 +49,42 @@ interface ActionDataType {
5049
[key:string]:any;
5150
}
5251

52+
asyncfunctiongetDefinitions(
53+
spec:OpenAPI.Document|MultiOpenApiSpecItem[],
54+
openApiSpecDereferenced?:OpenAPI.Document,
55+
):Promise<{def:OpenAPI.Document;id:string}[]>{
56+
if(openApiSpecDereferenced){
57+
return[{
58+
def:openApiSpecDereferenced,
59+
id:"",
60+
}]
61+
}else{
62+
constspecList=Array.isArray(spec) ?spec :[{ spec,id:""}];
63+
returnawaitPromise.all(
64+
specList.map(async({id, spec})=>{
65+
constdeRefedSpec=awaitSwaggerParser.dereference(spec);
66+
return{
67+
def:deRefedSpec,
68+
id,
69+
};
70+
})
71+
);
72+
}
73+
}
74+
5375
exportasyncfunctionrunOpenApi(
5476
actionData:ActionDataType,
5577
dataSourceConfig:DataSourceDataType,
5678
spec:OpenAPI.Document|MultiOpenApiSpecItem[],
57-
defaultHeaders?:Record<string,string>
79+
defaultHeaders?:Record<string,string>,
80+
openApiSpecDereferenced?:OpenAPI.Document,
5881
){
59-
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-
);
6982
const{ actionName, ...otherActionData}=actionData;
7083
const{ serverURL}=dataSourceConfig;
7184

72-
letdefinition:OpenAPI.Document|undefined;
73-
letoperation;
74-
letrealOperationId;
85+
letoperation,realOperationId,definition:OpenAPI.Document|undefined;
7586

76-
for(const{id, def}ofdefinitions){
87+
for(const{id, def}ofawaitgetDefinitions(spec,openApiSpecDereferenced)){
7788
constret=findOperation(actionName,def,id);
7889
if(ret){
7990
definition=def;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp