Skip to content
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

[TCGC] api-version parameter should not be onClient===true if the server is non-versioned #1391

Open
Tracked by #2920
haolingdong-msft opened this issue Aug 19, 2024 · 10 comments
Labels
lib:tcgc Issues for @azure-tools/typespec-client-generator-core library

Comments

@haolingdong-msft
Copy link
Member

haolingdong-msft commented Aug 19, 2024

Case:
https://github.com/Azure/cadl-ranch/blob/main/packages/cadl-ranch-specs/http/server/versions/not-versioned/main.tsp#L33

This is a non-versioned client, and I think the api-version should not be on client, but TCGC mark it as onClient.
TCGC output:
image

Seems a bug in TCGC?

@iscai-msft
Copy link
Contributor

Our current behavior is that we will always elevate api-version onto the client. It does make sense that versioning corresponds to setting api versioning on clients, but I do think we should talk about this in scrum on weds. Adding that to the agenda list

@haolingdong-msft
Copy link
Member Author

haolingdong-msft commented Sep 4, 2024

Sure, let's have discussion how the generated sdk should look like for non-versioned clients, I think we should not add api-version to the client parameter, otnerwise it is not non-versioned client.
For Java, if it is a non-versioned client, we will not add api-version parameter to the client. How about other languages? What is your generated code look like for this cadl-ranch case: https://github.com/Azure/cadl-ranch/blob/main/packages/cadl-ranch-specs/http/server/versions/not-versioned/main.tsp#L33
/cc @iscai-msft @tadelesh @archerzz @chunyu3 @qiaozha @MaryGao

@archerzz
Copy link
Member

archerzz commented Sep 4, 2024

C# doesn't check onClient. C# emitter will pass the api-version method parameter to the generator. And generator will check if there is already a client parameter api-version. If so, the method parameter will be suppressed: https://github.com/Azure/autorest.csharp/blob/bb1c49bfd05512775ed080679152e5cad1f64211/src/AutoRest.CSharp/Common/Generation/Writers/RequestWriterHelpers.cs#L291-L301

What's onClient for? Does it indicate that the query parameter already exists on client level?

@haolingdong-msft
Copy link
Member Author

Hi @archerzz , from my understanding, onClient is used to decide whether the parameter should be on client or not. And emitter is expected to use this value to decide whether to put the parameter on client. This is also related with Izzy's latest pr as well, which adds client parameters to the client initialization object. Those parameters will also have onClient==true on SdkHttpOperation.

@haolingdong-msft
Copy link
Member Author

haolingdong-msft commented Sep 5, 2024

Summary on 9/5 meeting:

  1. TCGC will mark onClient as false for api-version in non-versioned clients.
  2. (TBD) what should we set for isApiVersion flag on the non-versioned client's api-version parameter?

@archerzz
Copy link
Member

archerzz commented Sep 5, 2024

Another proposal: just delete onClient, because where you get SdkParameter should already tell you.

@haolingdong-msft
Copy link
Member Author

Another proposal: just delete onClient, because where you get SdkParameter should already tell you.

Hi @mingzhe, Personally I think these logics you mentioned on calculating onClient value should be better to put to TCGC, and emitters only need to rely on onClient value. Add @tadelesh and @iscai-msft for more comments as well.

@iscai-msft
Copy link
Contributor

iscai-msft commented Sep 5, 2024

@archerzz that is a good point, where we might no longer need onClient. I'm going to open another issue about this, and see what can be done. Thanks!

@chunyu3
Copy link
Member

chunyu3 commented Sep 9, 2024

I think we should keep onClient flag. When we do @clientInitialization to bump a parameter from operation to client. .NET need to know if the client parameter is exactly the client parameter or it is a parameter which is bumped from operation. Current we use onClient flag in the parameter of an operation to identify that this operation parameter is bumped to client.

@haolingdong-msft
Copy link
Member Author

haolingdong-msft commented Sep 9, 2024

Hi @iscai-msft, I would agree with @chunyu3 , I think checking onClient is the most straightforward and easiest way, though one can also argue that emitter could check whether the parameter is in SdkClientType.initialization.properties or not to determine if it's onClient. Both ways are workable, personally I would prefer the easier way which is to use onClient, and I think most language emitters are doing so already or planning to do so. Removing onClient would cause breaking changes to those emitters. To me, we(TCGC) should avoid breaking changs unless we have sufficient reasons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib:tcgc Issues for @azure-tools/typespec-client-generator-core library
Projects
None yet
Development

No branches or pull requests

4 participants