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] switch ... to always mean spreading, regardless of model or alias #772

Closed
4 tasks done
iscai-msft opened this issue May 2, 2024 · 2 comments · Fixed by #886
Closed
4 tasks done

[tcgc] switch ... to always mean spreading, regardless of model or alias #772

iscai-msft opened this issue May 2, 2024 · 2 comments · Fixed by #886
Assignees
Labels
feature New feature or request lib:tcgc Issues for @azure-tools/typespec-client-generator-core library

Comments

@iscai-msft
Copy link
Contributor

iscai-msft commented May 2, 2024

This issue is blocked by #771

Clear and concise description of the problem

Right now, tcgc has ...MyModel maintain the logical grouping, but ...MyAlias spread out the parameters. This is because there is a lack of support for op(MyModel) language definitions, and because we want to regroup models spread in azure core templates.

However, this behavior is often confusing and has led to a lot of back and forth. After talking with the TypeSpec team, we want to change the default, because eventually with more language support, ...MyModel should mean spread. The TypeSpec team will also modify the spreading currently done in Azure.Core templates (#771). If we implement this change concurrently with the Azure.Core changes, emitters shouldn't really see any code changes

Checklist

  • Follow our Code of Conduct
  • Check that this issue is about the Azure libraries for typespec. For feature request in the typespec language or core libraries file it in the TypeSpec repo
  • Read the docs.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
@iscai-msft iscai-msft added the lib:tcgc Issues for @azure-tools/typespec-client-generator-core library label May 2, 2024
@iscai-msft iscai-msft self-assigned this May 2, 2024
@tadelesh tadelesh assigned tadelesh and unassigned iscai-msft May 15, 2024
@tadelesh tadelesh added the feature New feature or request label Jun 11, 2024
@iscai-msft
Copy link
Contributor Author

closing because we're documenting this change in #1043

@tadelesh
Copy link
Member

reopen since this is only for tcgc change.

@tadelesh tadelesh reopened this Jun 25, 2024
github-merge-queue bot pushed a commit that referenced this issue Jul 2, 2024
resolve: #772

several cases related with spread:

1.
```
op test(a: string, b: string, c: string): void;
```
2.
```
model Test {
  prop: string
}
op test(...Test): void;
```
3.
```
op test(@Body body: {prop: string}): void;
```

4.
```
model Test {
  prop: string
}
op test(@Body body: {...Test}): void;
```

tcgc will do http body spread for 1 and 2, not for 3 and 4. and for http
body model, 1, 2 will have a model `TestRequest` with spread usage and
internal access.


**Adoption guideline for emitters:**

For emitters that have already adopted `getAllOperations`, if an
operation has spread parameters:
1. The parameters of `SdkServiceMethod` are spread.
2. The body parameter of `SdkServiceOperation` is an anonymous model
with `Usage.Spread` usage and `Access.Internal` access. And the
`correspondingMethodParams` of the body will be list of the parameters
of `SdkServiceMethod`.
3. Emitters could rely on the above info to generate clients' code.

For emitters that have not adopted `getAllOperations`, emitters need to
do:
1. Use `getHttpOperationWithCache` to prevent different body type
resolving for spread cases.
2. Refer this code:
https://github.com/Azure/typespec-azure/blob/5d77ba3e93521735a84051b4037c6f55e0a8a00a/packages/typespec-client-generator-core/src/types.ts#L1311-L1325
to change emitter's logic of handling operations with spread parameters.
3. When call `getClientType` from the body type of operation with
spread, the return model will be an anonymous model with `Usage.Spread`
usage and `Access.Internal` access. DO NOT CALL
`getEffectivePayloadType` for body type if it is from spread.

---------

Co-authored-by: iscai-msft <[email protected]>
Co-authored-by: iscai-msft <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request lib:tcgc Issues for @azure-tools/typespec-client-generator-core library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants