Skip to content

Commit

Permalink
🐛 fix: fix openapi requestBody
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Dec 15, 2023
1 parent 12bac99 commit 4385080
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ export const createGatewayOnEdgeRuntime = (options: EdgeRuntimeGatewayOptions =
} catch (error) {
const { errorType, body } = error as GatewayErrorResponse;

if (!errorType) {
const err = error as Error;
console.error(err.stack);
return createErrorResponse(PluginErrorType.PluginGatewayError, {
stack: err.stack,
});
}
return createErrorResponse(errorType, body);
}
};
Expand Down
11 changes: 7 additions & 4 deletions src/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
pluginMetaSchema,
pluginRequestPayloadSchema,
} from '@lobehub/chat-plugin-sdk';
import { OPENAPI_REQUEST_BODY_KEY } from '@lobehub/chat-plugin-sdk/openapi';
// @ts-ignore
import SwaggerClient from 'swagger-client';

Expand Down Expand Up @@ -181,7 +182,7 @@ export class Gateway {
message: '[plugin] plugin manifest is invalid',
});

console.log(`[${identifier}] plugin manifest:`, manifest);
// console.log(`[${identifier}] plugin manifest:`, manifest);

// ========== 6. 校验是否按照 manifest 包含了 settings 配置 ========== //

Expand Down Expand Up @@ -281,7 +282,7 @@ export class Gateway {
};

// 根据 settings 中的每个属性来构建 authorizations 对象
for (const [key, value] of Object.entries(settings)) {
for (const [key, value] of Object.entries(settings || {})) {
// 处理 API Key 和 Bearer Token
authorizations[key] = value as string;

Expand Down Expand Up @@ -316,10 +317,11 @@ export class Gateway {
});
}

const parameters = JSON.parse(args || '{}');
const requestParams = JSON.parse(args || '{}');
const { [OPENAPI_REQUEST_BODY_KEY]: requestBody, ...parameters } = requestParams;

try {
const res = await client.execute({ operationId: apiName, parameters });
const res = await client.execute({ operationId: apiName, parameters, requestBody });

return this.createSuccessResponse(res.text);
} catch (error) {
Expand All @@ -335,6 +337,7 @@ export class Gateway {
'[plugin] there are problem with sending openapi request, please contact with LobeHub Team',
openapi: manifest.openapi,
parameters,
requestBody,
});
}

Expand Down
1 change: 0 additions & 1 deletion src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export const createGatewayOnNodeRuntime = (options: NodeRuntimeGatewayOptions =

res.send(data);
} catch (error) {
console.error(error);
const { errorType, body } = error as GatewayErrorResponse;

res
Expand Down

0 comments on commit 4385080

Please sign in to comment.