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

Introduce more usages to describe things related with the states of LRO #1887

Merged
merged 25 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d05e51f
remove the workaround since #311 is resolved
ArcturusZhang Nov 19, 2024
c0d712e
Create remove-lro-workaround-2024-10-19-9-4-1.md
ArcturusZhang Nov 20, 2024
8d8fd8c
format
ArcturusZhang Nov 20, 2024
1af0eed
Merge branch 'main' into remove-lro-workaround
ArcturusZhang Nov 20, 2024
83cf322
add some test cases
ArcturusZhang Nov 20, 2024
3edd23b
update test cases
ArcturusZhang Nov 20, 2024
de2c7ba
update changelog
ArcturusZhang Nov 20, 2024
9f98fcf
update test cases
ArcturusZhang Nov 20, 2024
fbe44b2
add a new test case
ArcturusZhang Nov 20, 2024
a19783c
format
ArcturusZhang Nov 20, 2024
01e3093
add more test case
ArcturusZhang Nov 20, 2024
2a0e7ee
update test case to represent more info from the issue
ArcturusZhang Nov 20, 2024
65738a6
refine
ArcturusZhang Nov 20, 2024
99e7840
Merge branch 'main' into remove-lro-workaround
ArcturusZhang Nov 25, 2024
8eea71d
add new usage
ArcturusZhang Nov 26, 2024
0d44a8f
add new test cases
ArcturusZhang Nov 26, 2024
c88c704
Merge branch 'main' into remove-lro-workaround
ArcturusZhang Nov 26, 2024
bb81da3
fix test issues
ArcturusZhang Nov 26, 2024
1f53696
update changelog
ArcturusZhang Nov 26, 2024
286b14e
Merge branch 'main' into remove-lro-workaround
ArcturusZhang Nov 28, 2024
4d7efce
update changelog
ArcturusZhang Nov 29, 2024
0859904
Merge remote-tracking branch 'origin/main' into remove-lro-workaround
ArcturusZhang Nov 29, 2024
413839e
Merge branch 'main' into remove-lro-workaround
ArcturusZhang Dec 3, 2024
3c471d3
Merge branch 'main' into remove-lro-workaround
ArcturusZhang Dec 3, 2024
cec462c
Merge branch 'main' into remove-lro-workaround
ArcturusZhang Dec 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .chronus/changes/remove-lro-workaround-2024-10-19-9-4-1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: feature
packages:
- "@azure-tools/typespec-client-generator-core"
---

1. Introduce new usage: `LroInitial`, `LroPolling`, `LroFinalEnvelope`.
2. usage and access now properly propagate on polling model, final result and final envelop result of `lroMetadata`.
6 changes: 6 additions & 0 deletions packages/typespec-client-generator-core/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,12 @@ export enum UsageFlags {
Xml = 1 << 9,
// Set when type is used for exception output.
Exception = 1 << 10,
// Set when type is used as LRO initial response.
LroInitial = 1 << 11,
// Set when type is used as LRO polling response.
LroPolling = 1 << 12,
// Set when type is used as LRO final envelop response.
LroFinalEnvelope = 1 << 13,
}

interface SdkExampleBase {
Expand Down
50 changes: 30 additions & 20 deletions packages/typespec-client-generator-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,7 @@ function updateTypesFromOperation(
diagnostics.pipe(updateUsageOrAccess(context, access, sdkType));
}

const lroMetaData = getLroMetadata(program, operation);
for (const response of httpOperation.responses) {
for (const innerResponse of response.responses) {
if (innerResponse.body?.type && !isNeverOrVoidType(innerResponse.body.type)) {
Expand All @@ -1607,6 +1608,9 @@ function updateTypesFromOperation(
if (generateConvenient) {
if (response.statusCodes === "*" || isErrorModel(context.program, body)) {
diagnostics.pipe(updateUsageOrAccess(context, UsageFlags.Exception, sdkType));
} else if (lroMetaData !== undefined) {
// when the operation is an lro, the response should be its initial response.
diagnostics.pipe(updateUsageOrAccess(context, UsageFlags.LroInitial, sdkType));
} else {
diagnostics.pipe(updateUsageOrAccess(context, UsageFlags.Output, sdkType));
}
Expand Down Expand Up @@ -1634,29 +1638,35 @@ function updateTypesFromOperation(
}
}
}
const lroMetaData = getLroMetadata(program, operation);

if (lroMetaData && generateConvenient) {
if (lroMetaData.finalResult !== undefined && lroMetaData.finalResult !== "void") {
const sdkType = diagnostics.pipe(
getClientTypeWithDiagnostics(context, lroMetaData.finalResult, operation),
);
diagnostics.pipe(updateUsageOrAccess(context, UsageFlags.Output, sdkType));
const access = getAccessOverride(context, operation) ?? "public";
diagnostics.pipe(updateUsageOrAccess(context, access, sdkType));

if (!context.arm) {
// TODO: currently skipping adding of envelopeResult due to arm error
// https://github.com/Azure/typespec-azure/issues/311
const sdkType = diagnostics.pipe(
getClientTypeWithDiagnostics(context, lroMetaData.envelopeResult, operation),
);
diagnostics.pipe(updateUsageOrAccess(context, UsageFlags.Output, sdkType));
const access = getAccessOverride(context, operation) ?? "public";
diagnostics.pipe(updateUsageOrAccess(context, access, sdkType));
}
}
// the final result will be normal output usage.
updateUsageOrAccessForLroComponent(lroMetaData.finalResult, UsageFlags.Output);

// the final envelope result will have LroFinalEnvelope.
updateUsageOrAccessForLroComponent(
lroMetaData.finalEnvelopeResult,
UsageFlags.LroFinalEnvelope,
);

// the polling model will have LroPolling.
updateUsageOrAccessForLroComponent(
lroMetaData.pollingInfo.responseModel,
UsageFlags.LroPolling,
);
}
return diagnostics.wrap(undefined);

function updateUsageOrAccessForLroComponent(
model: Model | "void" | undefined,
usage: UsageFlags,
) {
if (model === undefined || model === "void") return;
const sdkType = diagnostics.pipe(getClientTypeWithDiagnostics(context, model, operation));
diagnostics.pipe(updateUsageOrAccess(context, usage, sdkType));
const access = getAccessOverride(context, operation) ?? "public";
diagnostics.pipe(updateUsageOrAccess(context, access, sdkType));
}
}

function updateAccessOverride(context: TCGCContext): [void, readonly Diagnostic[]] {
Expand Down
Loading
Loading