-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: allow custom decorator name for error messages #3625
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,12 @@ describe('ClassDecoratorFactory', () => { | |
| return ClassDecoratorFactory.createDecorator('test', spec); | ||
| } | ||
|
|
||
| function testDecorator(spec: object): ClassDecorator { | ||
| return ClassDecoratorFactory.createDecorator('test', spec, { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same question here,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first argument is the key for the metadata, it can be |
||
| decoratorName: '@test', | ||
| }); | ||
| } | ||
|
|
||
| const xSpec = {x: 1}; | ||
| @classDecorator(xSpec) | ||
| class BaseController {} | ||
|
|
@@ -116,9 +122,18 @@ describe('ClassDecoratorFactory', () => { | |
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| class MyController {} | ||
| }).to.throw( | ||
| /Decorator cannot be applied more than once on class MyController/, | ||
| /ClassDecorator cannot be applied more than once on class MyController/, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 to provide a meaningful default name when no |
||
| ); | ||
| }); | ||
|
|
||
| it('throws with decoratorName if applied more than once on the target', () => { | ||
| expect(() => { | ||
| @testDecorator({x: 1}) | ||
| @testDecorator({y: 2}) | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| class MyController {} | ||
| }).to.throw(/@test cannot be applied more than once on class MyController/); | ||
| }); | ||
| }); | ||
|
|
||
| describe('ClassDecoratorFactory for primitive types', () => { | ||
|
|
@@ -690,7 +705,9 @@ describe('MethodParameterDecoratorFactory with invalid decorations', () => { | |
| * @param spec | ||
| */ | ||
| function methodParameterDecorator(spec: object): MethodDecorator { | ||
| return MethodParameterDecoratorFactory.createDecorator('test', spec); | ||
| return MethodParameterDecoratorFactory.createDecorator('test', spec, { | ||
| decoratorName: '@param', | ||
| }); | ||
| } | ||
|
|
||
| it('reports error if the # of decorations exceeeds the # of params', () => { | ||
|
|
@@ -703,7 +720,7 @@ describe('MethodParameterDecoratorFactory with invalid decorations', () => { | |
| myMethod(a: string, b: number) {} | ||
| } | ||
| }).to.throw( | ||
| /The decorator is used more than 2 time\(s\) on MyController\.prototype\.myMethod\(\)/, | ||
| /@param is used more than 2 time\(s\) on MyController\.prototype\.myMethod\(\)/, | ||
| ); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@raymondfeng why do we need provide the decorator name in the
options? it could be inferred from theAUTHORIZATION_METHOD_KEYright?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the decorator name
@authorizecannot be inferred fromAUTHORIZATION_METHOD_KEY, which can be a free-form string.