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] spread behavior change #1388

Merged
merged 15 commits into from
Aug 22, 2024
Merged

[tcgc] spread behavior change #1388

merged 15 commits into from
Aug 22, 2024

Conversation

tadelesh
Copy link
Member

@tadelesh tadelesh commented Aug 16, 2024

use original model for body parameter in SdkServiceOperation if it is from a simple spread.

simple spread means spread model without any @header, @query or @path property and the spread model is the only source of http body.

examples,

op test(...Model): void;

op test(@header h: string, @query q: string, ...Model): void;

these two operation will have Model as body parameter.

op test(...A): void;
model A {
  @query
  q: string;
  prop: string;
}

this operation will have an anonymous model with only prop property and generated name TestRequest as body parameter.

resolve: #1132

cc: @ArcturusZhang @joheredi

MIGRATION GUIDE

In previous version, we could easily judge if a body type is spread by:

function isSpreadBody(bodyParam: SdkBodyParameter | undefined): boolean {
    return bodyParam?.type.kind === "model" && (bodyParam?.type.usage & UsageFlags.Spread) > 0
}

Now, since the spread model could also be used by other operations, you need to change to the following judgement:

function isSpreadBody(bodyParam: SdkBodyParameter | undefined): boolean {
    return bodyParam?.type.kind === "model" && bodyParam.type !== bodyParam.correspondingMethodParams[0]?.type;
}

@microsoft-github-policy-service microsoft-github-policy-service bot added the lib:tcgc Issues for @azure-tools/typespec-client-generator-core library label Aug 16, 2024
@azure-sdk
Copy link
Collaborator

azure-sdk commented Aug 16, 2024

All changed packages have been documented.

  • @azure-tools/typespec-client-generator-core
Show changes

@azure-tools/typespec-client-generator-core - feature ✏️

use original model for spread if it is from a simple spread

@azure-sdk
Copy link
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 📚 Next docs

@tadelesh
Copy link
Member Author

@ArcturusZhang @joheredi please review and check if it could satisfy your language's requirement, thanks.

@ArcturusZhang
Copy link
Member

Do we have a dev version so that we could see if this change could meet our requirement?
The code here LGTM

@tadelesh
Copy link
Member Author

Do we have a dev version so that we could see if this change could meet our requirement? The code here LGTM

before this pr merge, you could use the ci build artifact. after merge, you could use the dev version.

@tadelesh
Copy link
Member Author

@ArcturusZhang have you tried this in .net emitter? if all behavior is good, could you approve this pr?

@tadelesh tadelesh added this pull request to the merge queue Aug 22, 2024
Merged via the queue into main with commit 2b1320b Aug 22, 2024
22 checks passed
@tadelesh tadelesh deleted the spread_model branch August 22, 2024 06:50
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

Successfully merging this pull request may close these issues.

[TCGC] - use original model for simple spread instead of creating a new anonymous model
6 participants