-
Notifications
You must be signed in to change notification settings - Fork 245
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
Usage decorator (Input/Output/InputOutput) #4486
Comments
Current usage logic in TCGC:
Propagation logic:
One thing left is TCGC does not support override usage on operation, see issue here: Azure/typespec-azure#1301. |
Some challenges of access calculation:
|
This is a subset of the problem that input vs output might be protocol dependent and visibility dependent. This makes it probably quite hard to use |
Another thing is scope, different language's client needs different usage override. |
how does that work? wouldn't a model only be used as input or outpur or both regardless of the client? |
yeah. different usage for different client seems weird. and it seems all current usage in azure spec is wrong use case. the only scenario i could image is setting usage for model not referenced by any operation to generate them and different client need different orphan model. |
ok for the sake of this proposal I'll assume this one isn't maybe a real need as it might just make things incompehensible when combine with protocol/visibility |
Other uses case
Concern with this for now:
|
Input and Output in TypeSpec
Various emitters and protocol would benefit from a way to differentiate between input and output.
Things to take into account:
function resolveUsages(container: Namespace | Interface | Operation): UsageTracker;
Single marker for input or output
In this case we could use
in
/out
keyword which would result in a clean syntax.It makes it quite simple to figure out that we have some incompatible reference here
It might become a bit more tricky when referenced from
inout
types. Do we automatically infer that properties, union variants that reference an input only or output only type should be omitted.This now bleeds right into the visibility design where we expect properties/union variants to be explicitly annotated.
We could also consider that an error. i.e. you can only reference type of the same usage kind(input only from input only, output only from output only and input/output from both).
This is however quite limiting when working with visibility and render this incompatible.
So why not just use visibility
Input/Output still differ from visibility. Input could have many different visibility(create, update, etc.)
Pass a protocol to a
@usage
decoratorLet suppose we have the following operations
We could define the following:
This looks a lot like visibility
This now looks awefully similar to visibility but with more limitation. Visibility is able to specify different kind for input or output (create, update,etc.).
So now if we take the example above and we just want to make password available in create
Now this is a bit tedious I need to specify things twice. We should be able to map visibility to input or output so those get applied automatically which would allow the following.
And then why do we not have
@visibility
on the model itselfAt this point this just really feels like a more limited syntax/syntactic sugar for setting all the input vs output visibilities
Input/Output as a global flag and visibility to control protocol specificness
So this comes to the last option which is to keep visibility as the protocol specific decider and having
in
/out
/inout
keyword or@usage
decorator but something that applies in all cases.Taking the example above
With the code above we either wouldn't be able to validate which defeats a little the point of having those modifier or we'd need to duplicate things and have visibility just be a way to be more precise for a protocol
How does this work with protocol agnostic emitters
One of the thing this could ideally solve is having the ability to mark
readonly
,writeonly
in json schema for example.In the case of using a global switch this seems quite straight forward,
in
/out
can map toreadonly
,writeonly
.In the case of some protocol specific switch json schema would need to be able to choose which protocol to generate the schema from(or use the default value as the protocol was optional). This feels inline with the fact that it should probably also respect visibility(e.g. if generating json schema for models of an http service)
keyword vs decorator
I think a general thing we want for typespec is have the ability to use some decorator to specify some syntax sugar like
@default
or@optional
, etc. So i believe it would be safer to start with a decorator and move to a syntax later if it is widely used. There is 2 options:The first one would be a cleaner syntax specially if it doesn't take a protocol
The text was updated successfully, but these errors were encountered: