How to use the same custom decorator between custom emitters? #3528
-
TypeSpec has built-in, unnamespaced decorators like
What I've TriedWhen I do:
I get:
If I name one of the decorators differently, like
without any issues. However, I'd like to use the same custom decorator invocation for all my custom emitters, just like I can with built in decorators like Additional ContextI create custom unnamespaced decorators using the following 3 steps, inspired by what I've seen in https://github.com/tjprescott/typespec-pydantic, but without namespacing:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
A few things:
With this in mind you should most likely create a common.tsp file/library where you define those decorators. And this is what you import in your spec. Then each emitter can retrieve the data saved by the decorator and treat it however it sees fit. |
Beta Was this translation helpful? Give feedback.
-
Just to make a pedantic point that is not at all germane but documenting it in case it helps others in the future... TypeSpec's decorators aren't un-namespaced, they're in the TypeSpec namespace. It's just that every source file has an implicit |
Beta Was this translation helpful? Give feedback.
A few things:
@minvalue
is the decorator and its implementation are in the compiler. Emitters do not change the implementation of the decorator they can just consume thegetMinValue
function to retrieve the data set by the decorator.With this in mind you should most likely create a common.tsp file/library where you define those decorators. And this is what you import in…