Azure / typespec-azure

About TypeSpec Azure Libraries
https://azure.github.io/typespec-azure/
MIT License
11 stars 36 forks source link

[TCGC] Need a way to remove operation from TCGC #964

Open live1206 opened 3 months ago

live1206 commented 3 months ago

Clear and concise description of the problem

For .NET SDK, we have requirement to remove certain operations, such as Operations.list should always be removed as duplicated within resource manager. Right now, the best approach we have is below, details

@armResourceOperations
interface Employees {
  get is ArmResourceRead<Employee>;
}

@@access(Employees.get, Access.internal, "csharp");

But this operation still exists, .NET SDK need to handle it specifically. Is it possible to remove this operation from TCGC result? for instance,

@@access(Employees.get, Access.never, "csharp");

Or can we have a new decorator to remove an operation in TCGC?

Checklist

live1206 commented 3 months ago

cc @tadelesh @m-nash @ArcturusZhang

m-nash commented 2 months ago

The original design goal for this was we would have an @scope decorator which simply modified the scope of any given item.

I would imagine we could do @@scope(Service.op, "~csharp"). Meaning the operation applies to everything but csharp.

live1206 commented 1 month ago

If we handle this in .NET generator directly, the usage calculation in TCGC will miss this part and end into inaccurate usage. So, would like to still handle this in TCGC despite this requirement is only for .NET. Potentially, it could benefit the other languages.

Normally, a decorator could be applied to Type, to avoid the over complexity only apply it to Operation as needed now.

usage:

# "~" means exclude the target operation from the defined scope
@scope("~csharp")
op nameInService: void;

@scope("java")
op nameInService: void;

validation:

effect: the operation along with everything inside(we have validation to ensure everything inside is not referenced outside this operation) will be removed from the excluded language scopes, and the usage should be calculated correctly based on this.

live1206 commented 1 month ago

Found https://github.com/Azure/typespec-azure-pr/issues/2732 regarding scope of decorators in TCGC. I think the proposal of @scope decorator is identical to @exclude and @include with scopes, just need to extend the entity from Model to Operation | Model. And now @exclude and @include are deprecated, because we think they can be replaced by @usage and @access. So, don't feel like adding a new @scope decorator will be the approach we would take.

Another option raise from @ArcturusZhang is to use @convenientAPI, TCGC has taken care of the Model usage. .NET SDK mgmt generator just needs to omit the operation if InputOperation.GenerateConvenienceMethod is false, same behavior as DPG

live1206 commented 1 month ago

Found Azure/typespec-azure-pr#2732 regarding scope of decorators in TCGC. I think the proposal of @scope decorator is identical to @exclude and @include with scopes, just need to extend the entity from Model to Operation | Model. And now @exclude and @include are deprecated, because we think they can be replaced by @usage and @access. So, don't feel like adding a new @scope decorator will be the approach we would take.

Another option raise from @ArcturusZhang is to use @convenientAPI, TCGC has taken care of the Model usage. .NET SDK mgmt generator just needs to omit the operation if InputOperation.GenerateConvenienceMethod is false, same behavior as DPG

After clarification with @m-nash, the negation language scope is not implemented, but not abandoned. The reason we need a new @scope decorator and it can't be replaced by the existing deprecated @include is because we can't define the behavior of @include or @exclude decorator with negation scope.

iscai-msft commented 1 month ago

@live1206 would you be able to contribute a design and implementation for this? Thanks!

live1206 commented 1 month ago

@live1206 would you be able to contribute a design and implementation for this? Thanks!

Sure, will add more details with what I have been doing.