From d1e6f9241129afaf5728b6c3f72755c456cc470a Mon Sep 17 00:00:00 2001 From: "Tyler B. Thrailkill" Date: Fri, 8 Mar 2024 16:10:37 -0700 Subject: [PATCH 1/4] 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. --- .../node-service/src/plugins/github/index.ts | 6 ++-- .../node-service/src/plugins/openApi/index.ts | 30 ++++++++++++------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/server/node-service/src/plugins/github/index.ts b/server/node-service/src/plugins/github/index.ts index 5df537677..3f031b65e 100644 --- a/server/node-service/src/plugins/github/index.ts +++ b/server/node-service/src/plugins/github/index.ts @@ -5,6 +5,7 @@ import { OpenAPIV3, OpenAPI } from "openapi-types"; import { ConfigToType, DataSourcePlugin } from "lowcoder-sdk/dataSource"; import { runOpenApi } from "../openApi"; import { parseOpenApi, ParseOpenApiOptions } from "../openApi/parse"; +import SwaggerParser from "@apidevtools/swagger-parser"; const spec = readYaml(path.join(__dirname, "./github.spec.yaml")); @@ -34,6 +35,7 @@ const parseOptions: ParseOpenApiOptions = { return _.upperFirst(operation.operationId || ""); }, }; +const deRefedSpec = SwaggerParser.dereference(spec); type DataSourceConfigType = ConfigToType; @@ -55,13 +57,13 @@ const gitHubPlugin: DataSourcePlugin = { actions, }; }, - run: function (actionData, dataSourceConfig): Promise { + run: async function (actionData, dataSourceConfig, ctx): Promise { const runApiDsConfig = { url: "", serverURL: "https://api.github.com", dynamicParamsConfig: dataSourceConfig, }; - return runOpenApi(actionData, runApiDsConfig, spec as OpenAPIV3.Document); + return runOpenApi(actionData, runApiDsConfig, spec as OpenAPIV3.Document, undefined, await deRefedSpec); }, }; diff --git a/server/node-service/src/plugins/openApi/index.ts b/server/node-service/src/plugins/openApi/index.ts index 27f9ed950..eaec12aac 100644 --- a/server/node-service/src/plugins/openApi/index.ts +++ b/server/node-service/src/plugins/openApi/index.ts @@ -54,18 +54,28 @@ export async function runOpenApi( actionData: ActionDataType, dataSourceConfig: DataSourceDataType, spec: OpenAPI.Document | MultiOpenApiSpecItem[], - defaultHeaders?: Record + defaultHeaders?: Record, + openApiSpecDereferenced?: OpenAPI.Document, ) { const specList = Array.isArray(spec) ? spec : [{ spec, id: "" }]; - const definitions = await Promise.all( - specList.map(async ({ id, spec }) => { - const deRefedSpec = await SwaggerParser.dereference(spec); - return { - def: deRefedSpec, - id, - }; - }) - ); + let definitions; + + if (!openApiSpecDereferenced) { + definitions = await Promise.all( + specList.map(async ({id, spec}) => { + const deRefedSpec = await SwaggerParser.dereference(spec); + return { + def: deRefedSpec, + id, + }; + }) + ); + } else { + definitions = [{ + def: openApiSpecDereferenced, + id: "", + }] + } const { actionName, ...otherActionData } = actionData; const { serverURL } = dataSourceConfig; From ed4f40be6df258dc81b5e38ec5fbdfe09deff288 Mon Sep 17 00:00:00 2001 From: "Tyler B. Thrailkill" Date: Fri, 8 Mar 2024 16:15:44 -0700 Subject: [PATCH 2/4] Pull definition logic into a new function --- .../node-service/src/plugins/openApi/index.ts | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/server/node-service/src/plugins/openApi/index.ts b/server/node-service/src/plugins/openApi/index.ts index eaec12aac..265b23b44 100644 --- a/server/node-service/src/plugins/openApi/index.ts +++ b/server/node-service/src/plugins/openApi/index.ts @@ -50,18 +50,18 @@ interface ActionDataType { [key: string]: any; } -export async function runOpenApi( - actionData: ActionDataType, - dataSourceConfig: DataSourceDataType, +async function getDefinitions( spec: OpenAPI.Document | MultiOpenApiSpecItem[], - defaultHeaders?: Record, openApiSpecDereferenced?: OpenAPI.Document, -) { - const specList = Array.isArray(spec) ? spec : [{ spec, id: "" }]; - let definitions; - - if (!openApiSpecDereferenced) { - definitions = await Promise.all( +): Promise<{ def: OpenAPI.Document; id: string }[]> { + if (openApiSpecDereferenced) { + return [{ + def: openApiSpecDereferenced, + id: "", + }] + } else { + const specList = Array.isArray(spec) ? spec : [{ spec, id: "" }]; + return await Promise.all( specList.map(async ({id, spec}) => { const deRefedSpec = await SwaggerParser.dereference(spec); return { @@ -70,20 +70,22 @@ export async function runOpenApi( }; }) ); - } else { - definitions = [{ - def: openApiSpecDereferenced, - id: "", - }] } +} + +export async function runOpenApi( + actionData: ActionDataType, + dataSourceConfig: DataSourceDataType, + spec: OpenAPI.Document | MultiOpenApiSpecItem[], + defaultHeaders?: Record, + openApiSpecDereferenced?: OpenAPI.Document, +) { const { actionName, ...otherActionData } = actionData; const { serverURL } = dataSourceConfig; - let definition: OpenAPI.Document | undefined; - let operation; - let realOperationId; + let operation, realOperationId, definition: OpenAPI.Document | undefined; - for (const { id, def } of definitions) { + for (const {id, def} of await getDefinitions(spec, openApiSpecDereferenced)) { const ret = findOperation(actionName, def, id); if (ret) { definition = def; From 275cf68eb73e80a43034e5d9a88431949cfe6f0b Mon Sep 17 00:00:00 2001 From: "Tyler B. Thrailkill" Date: Fri, 8 Mar 2024 16:16:39 -0700 Subject: [PATCH 3/4] Small amount of code cleanup --- server/node-service/src/plugins/openApi/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/node-service/src/plugins/openApi/index.ts b/server/node-service/src/plugins/openApi/index.ts index 265b23b44..c99bcc9a3 100644 --- a/server/node-service/src/plugins/openApi/index.ts +++ b/server/node-service/src/plugins/openApi/index.ts @@ -12,11 +12,10 @@ import { isFile, } from "./util"; import { badRequest } from "../../common/error"; -import { safeJsonParse } from "../../common/util"; import { OpenAPI, OpenAPIV2, OpenAPIV3 } from "openapi-types"; import _ from "lodash"; import { fetch } from "../../common/fetch"; -import { RequestInit, Response } from "node-fetch"; +import { RequestInit } from "node-fetch"; const dataSourceConfig = { type: "dataSource", From 9f0e484f6d5a557ef3d459e73f0c972e1ee109d4 Mon Sep 17 00:00:00 2001 From: liusijun Date: Mon, 11 Mar 2024 16:58:35 +0800 Subject: [PATCH 4/4] fix: complete the locale file --- client/packages/lowcoder/src/i18n/locales/zh.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/client/packages/lowcoder/src/i18n/locales/zh.ts b/client/packages/lowcoder/src/i18n/locales/zh.ts index d2e868a61..78f0fc071 100644 --- a/client/packages/lowcoder/src/i18n/locales/zh.ts +++ b/client/packages/lowcoder/src/i18n/locales/zh.ts @@ -140,7 +140,7 @@ prop: { expand: "展开", columns: "列", rowSelection: "行选择", - toolbar: "工具栏", + toolbar: "工具栏", pagination: "分页", logo: "标志", style: "样式", @@ -358,6 +358,7 @@ style: { textSize: "字体大小", textWeight: "字体粗细", "fontFamily": "字体", + "fontStyle": "字体风格", "backgroundImage": "背景图片", "backgroundImageRepeat" : "背景图片重复", "backgroundImageSize" : "背景图片大小", @@ -1086,7 +1087,7 @@ selectInput: { valueDesc: "当前选择的值", selectedIndexDesc: "当前选择的值的索引,如果未选择任何值则为-1", selectedLabelDesc: "当前选择的值的标签", -}, +}, file: { typeErrorMsg: "必须是一个带有有效文件大小单位的数字,或者是一个无单位的字节数.", fileEmptyErrorMsg: "上传失败.文件大小为空.", @@ -2327,7 +2328,7 @@ componentDoc: { event: "事件", eventName: "事件名称", eventDesc: "描述", - mehtod: "方法", + mehtod: "方法", methodUsage: "您可以通过方法与组件进行交互,并且可以在任何可以编写 JavaScript 的地方通过它们的名称调用它们.或者您可以通过事件的“控制组件”操作来调用它们.", methodName: "方法名称", methodDesc: "描述", @@ -2561,7 +2562,7 @@ componentDocExtra: { table: table, }, idSource: { - title: "用户认证提供商", + title: "用户认证提供商", form: "电子邮件", pay: "高级", enable: "启用", @@ -2723,4 +2724,4 @@ timeLine: { navStyle: "菜单风格", navItemStyle: "菜单项样式", } -}; \ No newline at end of file +};