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

New spread support #2653

Merged
merged 13 commits into from
Jul 17, 2024
Merged

New spread support #2653

merged 13 commits into from
Jul 17, 2024

Conversation

qiaozha
Copy link
Member

@qiaozha qiaozha commented Jul 9, 2024

fixes #2414

In typespec, we have two kinds of spread.

  1. the spread of model
model Foo {
   prop1: string;
   prop2: boolean;
}
op test(...Foo): void;
  1. the spread of alias
alias Foo = {
   prop1: string;
   prop2: boolean;
};
op test(...Foo): void;

Previously, we have decided that we will treat spread of a alias as a payload flatten in this pr #2020 (comment) and spread of a model is not a payload flatten.

With payload flatten, the method signature would look like

export function test(prop1: string, prop2: boolean): void;

Without payload flatten, the method signature would be:

export function test(body: {prop1: string, prop2: boolean}): void;

And because alias was treated as anonymous model, we used to call getEffectivePayloadType from typespec compiler to try to get a valid payload type whenever possible, our previous spread condition becomes we flatten payload for anonymous model. it has a potential draw back which is we don't know if this model is defined as anonymous or become anonymous because of alias spread.

In Azure/typespec-azure#1043, we found that this kind of difference is too complex for customer to understand the client side behavior differently per on model or alias. we have decided to change that spread of a model is also a payload flatten.

In this PR, we have

  1. integrate with the new spread behavior from tcgc, see [tcgc] new spread behavior typespec-azure#886 (comment) for more details.
  2. mitigate the unnecessary flatten in our own test cases.

now spread is spread, anonymous model is anonymous model.

@qiaozha qiaozha marked this pull request as ready for review July 11, 2024 06:02
Copy link
Member

@joheredi joheredi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go with this fix to unblock moving the latest TCGC. In the meantime I'll setup some infrastructure so that we can move to using TCGC types in a more organized and smooth way

@qiaozha qiaozha merged commit f425e4a into Azure:main Jul 17, 2024
14 checks passed
@qiaozha qiaozha deleted the new-spread-support branch July 17, 2024 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Method signature (alias / spread) Implementation
3 participants