Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrong handler name with decorator #2793

Merged
merged 1 commit into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/core/src/service/slsFunctionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ export class MidwayServerlessFunctionService extends MidwayWebRouterService {
functionMeta['functionName'] ??
webRouter?.['metadata']?.['functionName'] ??
createFunctionName(module, webRouter['methodName']);
const funcHandlerName =
functionMeta['handlerName'] ??
webRouter?.['metadata']?.['handlerName'] ??
data.funcHandlerName;
data.functionName = functionName;
data.funcHandlerName = funcHandlerName;
data.functionTriggerName = webRouter['type'];
data.functionTriggerMetadata = webRouter['metadata'];
data.functionMetadata = {
Expand All @@ -152,6 +157,11 @@ export class MidwayServerlessFunctionService extends MidwayWebRouterService {
functionMeta['functionName'] ??
webRouter?.['metadata']?.['functionName'] ??
createFunctionName(module, webRouter['methodName']);

const funcHandlerName =
functionMeta['handlerName'] ??
webRouter?.['metadata']?.['handlerName'] ??
`${controllerId}.${webRouter['methodName']}`;
// 其他类型的函数
this.checkDuplicateAndPush(prefix, {
id,
Expand All @@ -163,7 +173,7 @@ export class MidwayServerlessFunctionService extends MidwayWebRouterService {
description: '',
summary: '',
handlerName: `${controllerId}.${webRouter['methodName']}`,
funcHandlerName: `${controllerId}.${webRouter['methodName']}`,
funcHandlerName: funcHandlerName,
controllerId,
middleware: webRouter['metadata']?.['middleware'] || [],
controllerMiddleware: [],
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/service/webRouterService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export interface RouterInfo {
*/
handlerName?: string;
/**
* serverless func load key
* serverless func load key, will be override by @ServerlessTrigger and @ServerlessFunction
*/
funcHandlerName?: string;
/**
Expand Down Expand Up @@ -93,7 +93,7 @@ export interface RouterInfo {
*/
responseMetadata?: any[];
/**
* serverless function name
* serverless function name, will be override by @ServerlessTrigger and @ServerlessFunction
*/
functionName?: string;
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Inject, Provide, ServerlessTriggerType, Query, Body, ServerlessTrigger } from '../../../../../src';
import {
Inject,
Provide,
ServerlessTriggerType,
Query,
Body,
ServerlessTrigger,
ServerlessFunction
} from '../../../../../src';

@Provide()
export class HelloHttpService {
Expand All @@ -18,4 +26,14 @@ export class HelloHttpService {

}

@ServerlessTrigger(ServerlessTriggerType.HTTP, { path: '/invoke2', functionName: 'invoke2', handlerName: 'index.invoke2'})
invoke2() {}

@ServerlessFunction({ functionName: 'invoke3', handlerName: 'index.invoke3'})
@ServerlessTrigger(ServerlessTriggerType.EVENT)
invoke3(){}

@ServerlessFunction({ functionName: 'invoke4', handlerName: 'index.invoke4'})
@ServerlessTrigger(ServerlessTriggerType.EVENT, { handlerName: 'index.invoke44'})
invoke4() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,40 @@ exports[`/test/service/slsFunction.test.ts should test with function router 1`]
"summary": "",
"url": "/",
},
{
"_category": 2,
"_level": 1,
"_paramString": "",
"_pureRouter": "/invoke2",
"_weight": 1,
"controllerId": "helloHttpService",
"controllerMiddleware": [],
"description": "",
"fullUrl": "/invoke2",
"fullUrlFlattenString": "/invoke2",
"funcHandlerName": "index.invoke2",
"functionMetadata": {
"functionName": "invoke2",
},
"functionName": "invoke2",
"functionTriggerMetadata": {
"functionName": "invoke2",
"handlerName": "index.invoke2",
"method": "get",
"path": "/invoke2",
},
"functionTriggerName": "http",
"handlerName": "helloHttpService.invoke2",
"method": "invoke2",
"middleware": [],
"prefix": "/",
"requestMetadata": [],
"requestMethod": "get",
"responseMetadata": [],
"routerName": "",
"summary": "",
"url": "/invoke2",
},
{
"_category": 2,
"_level": 1,
Expand Down Expand Up @@ -259,5 +293,63 @@ exports[`/test/service/slsFunction.test.ts should test with function router 1`]
"summary": "",
"url": "",
},
{
"_category": 2,
"_level": 0,
"_paramString": "",
"_pureRouter": "",
"_weight": 0,
"controllerId": "helloHttpService",
"controllerMiddleware": [],
"description": "",
"funcHandlerName": "index.invoke3",
"functionMetadata": {
"functionName": "invoke3",
"handlerName": "index.invoke3",
},
"functionName": "invoke3",
"functionTriggerMetadata": {},
"functionTriggerName": "event",
"handlerName": "helloHttpService.invoke3",
"method": "invoke3",
"middleware": [],
"prefix": "/",
"requestMetadata": [],
"requestMethod": "",
"responseMetadata": [],
"routerName": "",
"summary": "",
"url": "",
},
{
"_category": 2,
"_level": 0,
"_paramString": "",
"_pureRouter": "",
"_weight": 0,
"controllerId": "helloHttpService",
"controllerMiddleware": [],
"description": "",
"funcHandlerName": "index.invoke4",
"functionMetadata": {
"functionName": "invoke4",
"handlerName": "index.invoke4",
},
"functionName": "invoke4",
"functionTriggerMetadata": {
"handlerName": "index.invoke44",
},
"functionTriggerName": "event",
"handlerName": "helloHttpService.invoke4",
"method": "invoke4",
"middleware": [],
"prefix": "/",
"requestMetadata": [],
"requestMethod": "",
"responseMetadata": [],
"routerName": "",
"summary": "",
"url": "",
},
]
`;