Skip to content

Conversation

@raymondfeng
Copy link
Contributor

@raymondfeng raymondfeng commented Aug 30, 2019

Extracted and improved from #3617

Checklist

👉 Read and sign the CLA (Contributor License Agreement) 👈

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

👉 Check out how to submit a PR 👈

@raymondfeng raymondfeng force-pushed the improve-metadata-debugging branch from 801cbc1 to 9f61b6e Compare August 30, 2019 15:51
@raymondfeng raymondfeng changed the title feat(metadata): allow custom decorator name for error messages feat: allow custom decorator name for error messages Aug 30, 2019
return AuthorizeMethodDecoratorFactory.createDecorator(
AUTHORIZATION_METHOD_KEY,
spec,
{decoratorName: '@authorize'},
Copy link
Contributor

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 the AUTHORIZATION_METHOD_KEY right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the decorator name @authorize cannot be inferred from AUTHORIZATION_METHOD_KEY, which can be a free-form string.

}

function testDecorator(spec: object): ClassDecorator {
return ClassDecoratorFactory.createDecorator('test', spec, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question here, test and @test seems duplicate, and what would happen if they are different?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first argument is the key for the metadata, it can be test or test.key, or other unique strings. The second one is for the decorator function name.

Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

class MyController {}
}).to.throw(
/Decorator cannot be applied more than once on class MyController/,
/ClassDecorator cannot be applied more than once on class MyController/,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to provide a meaningful default name when no decoratorName metadata was supplied.

@bajtos bajtos added developer-experience Issues affecting ease of use and overall experience of LB users IoC/Context @loopback/context: Dependency Injection, Inversion of Control labels Sep 2, 2019
Copy link
Contributor

@jannyHou jannyHou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM

@raymondfeng raymondfeng merged commit de335d3 into master Sep 3, 2019
@raymondfeng raymondfeng deleted the improve-metadata-debugging branch September 3, 2019 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

developer-experience Issues affecting ease of use and overall experience of LB users IoC/Context @loopback/context: Dependency Injection, Inversion of Control

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants