Skip to content

Commit 7c658a2

Browse files
committed
add detail catories for openai
1 parent 7367ba7 commit 7c658a2

File tree

9 files changed

+166
-3517
lines changed

9 files changed

+166
-3517
lines changed

server/node-service/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
"openblocks-sdk": "^0.0.34",
4747
"stylis": "^4.1.3",
4848
"swagger-client": "^3.18.5",
49-
"typescript": "^4.9.3"
49+
"typescript": "^4.9.3",
50+
"yaml": "^2.2.1"
5051
},
5152
"packageManager": "yarn@3.3.1"
5253
}

server/node-service/src/common/util.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { relaxedJSONToJSON } from "openblocks-core";
2+
import yaml from "yaml";
3+
import fs from "fs";
24

35
export function toString(value: any): string {
46
if (value === undefined || value === null) {
@@ -68,3 +70,13 @@ export function toStringOrJson(value: any): any {
6870
return {};
6971
}
7072
}
73+
74+
export function readYaml<T = any>(path: string): T {
75+
try {
76+
const yamlContent = fs.readFileSync(path, "utf-8");
77+
return yaml.parse(yamlContent) as T;
78+
} catch (e) {
79+
console.info("invalid yaml:", e);
80+
return {} as T;
81+
}
82+
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
import { readYaml } from "../../common/util";
12
import _ from "lodash";
3+
import path from "path";
24
import { OpenAPIV3, OpenAPI } from "openapi-types";
35
import { ConfigToType, DataSourcePlugin } from "openblocks-sdk/dataSource";
46
import { runOpenApi } from "../openApi";
57
import { parseOpenApi, ParseOpenApiOptions } from "../openApi/parse";
6-
import spec from "./openai-spec.json";
8+
9+
const spec = readYaml(path.join(__dirname, "./openAi.yaml"));
710

811
const dataSourceConfig = {
912
type: "dataSource",
@@ -35,10 +38,14 @@ const openAiPlugin: DataSourcePlugin<any, DataSourceConfigType> = {
3538
category: "api",
3639
dataSourceConfig,
3740
queryConfig: async () => {
38-
const { actions } = await parseOpenApi(spec, parseOptions);
41+
const { actions, categories } = await parseOpenApi(spec, parseOptions);
3942
return {
4043
type: "query",
4144
label: "Action",
45+
categories: {
46+
label: "Category",
47+
items: categories,
48+
},
4249
actions,
4350
};
4451
},

0 commit comments

Comments
 (0)