Skip to content

Commit 33cf34b

Browse files
author
FalkWolsky
committed
Postman Echo as Data Source
1 parent e57b10f commit 33cf34b

File tree

6 files changed

+706
-0
lines changed

6 files changed

+706
-0
lines changed

server/node-service/src/controllers/plugins.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export async function listPlugins(req: Request, res: Response) {
1717
export async function runPluginQuery(req: Request, res: Response) {
1818
const { pluginName, dsl, context, dataSourceConfig } = req.body;
1919
const ctx = pluginServices.getPluginContext(req);
20+
21+
22+
console.log("pluginName: ", pluginName, "dsl: ", dsl, "context: ", context, "dataSourceConfig: ", dataSourceConfig, "ctx: ", ctx);
23+
2024
const result = await pluginServices.runPluginQuery(
2125
pluginName,
2226
dsl,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import didPlugin from "./did";
3434
import bigQueryPlugin from "./bigQuery";
3535
import appConfigPlugin from "./appconfig";
3636
import tursoPlugin from "./turso";
37+
import postmanEchoPlugin from "./postmanEcho";
3738

3839
let plugins: (DataSourcePlugin | DataSourcePluginFactory)[] = [
3940
s3Plugin,
@@ -71,6 +72,7 @@ let plugins: (DataSourcePlugin | DataSourcePluginFactory)[] = [
7172
bigQueryPlugin,
7273
appConfigPlugin,
7374
tursoPlugin,
75+
postmanEchoPlugin,
7476
];
7577

7678
try {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ export async function runOpenApi(
8282
const { actionName, ...otherActionData } = actionData;
8383
const { serverURL } = dataSourceConfig;
8484

85+
86+
8587
let operation, realOperationId, definition: OpenAPI.Document | undefined;
8688

8789
for (const {id, def} of await getDefinitions(spec, openApiSpecDereferenced)) {
@@ -114,6 +116,7 @@ export async function runOpenApi(
114116
try {
115117
const { parameters, requestBody } = normalizeParams(otherActionData, operation, isOas3Spec);
116118
let securities = extractSecurityParams(dataSourceConfig, definition);
119+
117120
const response = await SwaggerClient.execute({
118121
spec: definition,
119122
operationId: realOperationId,
@@ -122,6 +125,7 @@ export async function runOpenApi(
122125
securities,
123126
responseContentType: "application/json",
124127
userFetch: async (url: string, req: RequestInit) => {
128+
console.log("req", req);
125129
return fetch(url, req);
126130
},
127131
requestInterceptor: (req: any) => {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { readYaml } from "../../common/util";
2+
import _ from "lodash";
3+
import path from "path";
4+
import { OpenAPIV3, OpenAPI } from "openapi-types";
5+
import { ConfigToType, DataSourcePlugin } from "lowcoder-sdk/dataSource";
6+
import { runOpenApi } from "../openApi";
7+
import { parseOpenApi, ParseOpenApiOptions } from "../openApi/parse";
8+
9+
import spec from './postmanEcho.spec.json';
10+
11+
12+
const dataSourceConfig = {
13+
type: "dataSource",
14+
params: []
15+
} as const;
16+
17+
const parseOptions: ParseOpenApiOptions = {
18+
actionLabel: (method: string, path: string, operation: OpenAPI.Operation) => {
19+
return _.upperFirst(operation.summary ? operation.summary : operation.operationId || "");
20+
},
21+
};
22+
23+
type DataSourceConfigType = ConfigToType<typeof dataSourceConfig>;
24+
25+
const postmanEchoPlugin: DataSourcePlugin<any, DataSourceConfigType> = {
26+
id: "postmanEcho",
27+
name: "Postman Echo",
28+
icon: "postmanEcho.svg",
29+
category: "api",
30+
dataSourceConfig,
31+
queryConfig: async () => {
32+
const { actions, categories } = await parseOpenApi(spec as unknown as OpenAPI.Document, parseOptions);
33+
return {
34+
type: "query",
35+
label: "Action",
36+
categories: {
37+
label: "Resources",
38+
items: categories,
39+
},
40+
actions,
41+
};
42+
},
43+
run: function (actionData, dataSourceConfig): Promise<any> {
44+
const runApiDsConfig = {
45+
url: "",
46+
serverURL: "",
47+
dynamicParamsConfig: dataSourceConfig,
48+
};
49+
return runOpenApi(actionData, runApiDsConfig, spec as OpenAPIV3.Document);
50+
},
51+
};
52+
53+
export default postmanEchoPlugin;

0 commit comments

Comments
 (0)