-
Notifications
You must be signed in to change notification settings - Fork 66
[TCGC] generate names for anonymous models in LRO #3611
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
75bb4dc
05156a0
a616d9c
ab676c8
1c405b7
73aa779
6eff8bb
6b69e80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| changeKind: fix | ||
| packages: | ||
| - "@azure-tools/typespec-client-generator-core" | ||
| --- | ||
|
|
||
| Generate names for anonymous models in LroMetadata. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -816,6 +816,97 @@ describe("data plane LRO templates", () => { | |
| ); | ||
| strictEqual(lroMetadata.pollingStep.responseBody, analyzeOperationModel); | ||
| }); | ||
|
|
||
| // https://github.com/Azure/typespec-azure/issues/2325 | ||
| it("LroMetadata final result anonymous model", async () => { | ||
| await runner.compileWithVersionedService(` | ||
| alias ServiceTraits = NoRepeatableRequests & | ||
| NoConditionalRequests & | ||
| NoClientRequestId; | ||
|
|
||
| alias apiOperations = Azure.Core.ResourceOperations<ServiceTraits>; | ||
|
|
||
| @doc("Create an instruction.") | ||
| @pollingOperation( | ||
| OperationProgress.getOperationResult | ||
| ) | ||
| op update is apiOperations.LongRunningResourceCreateOrUpdate<Instruction>; | ||
|
|
||
| @resource("instruction") | ||
| model Instruction { | ||
| @key | ||
| @visibility(Lifecycle.Read) | ||
| id: string; | ||
|
|
||
| @visibility(Lifecycle.Update) | ||
| instructionId: string; | ||
| } | ||
|
|
||
| @doc("Operation Status") | ||
| @lroStatus | ||
| union OperationStatusValue { | ||
|
||
| @doc("The operation is Accepted.") | ||
| Accepted: "Accepted", | ||
|
|
||
| @doc("The operation is InProgress.") | ||
| InProgress: "InProgress", | ||
|
|
||
| @doc("The operation is Succeeded.") | ||
| Succeeded: "Succeeded", | ||
|
|
||
| @doc("The operation is Failed.") | ||
| Failed: "Failed", | ||
|
|
||
| @doc("The operation is Canceled.") | ||
| Canceled: "Canceled", | ||
|
|
||
| string, | ||
| } | ||
|
|
||
| @doc("Operation Response Model") | ||
| @resource("operation") | ||
| model OperationResultQuery { | ||
| @doc("The operation status.") | ||
| @visibility(Lifecycle.Read) | ||
| status: OperationStatusValue; | ||
|
|
||
| @doc("The operation id.") | ||
| @key("operationId") | ||
| @visibility(Lifecycle.Read) | ||
| operationId: string; | ||
|
|
||
| @doc("The error message.") | ||
| @visibility(Lifecycle.Read) | ||
| errorMessage: string[]; | ||
| } | ||
|
|
||
| @doc("Get operation progress") | ||
| interface OperationProgress { | ||
| @doc("Get operation progress") | ||
| getOperationResult is apiOperations.ResourceRead<OperationResultQuery>; | ||
| } | ||
| `); | ||
| const method = runner.context.sdkPackage.clients[0].methods.find((m) => m.name === "update"); | ||
| assert.exists(method); | ||
| strictEqual(method.kind, "lro"); | ||
| const response = method.response.type; | ||
| assert.strictEqual(response?.kind, "model"); | ||
| if (!response || response.kind !== "model") { | ||
| assert.fail("Expected final response to be a model."); | ||
| } | ||
| assert.isTrue(response.isGeneratedName); | ||
| const generatedName = response.name; | ||
| assert.strictEqual("UpdateFinalResult", generatedName); | ||
| const crossLanguageId = response.crossLanguageDefinitionId; | ||
| assert.isFalse(crossLanguageId.includes("..")); | ||
| const lroMetadata = method.lroMetadata; | ||
| assert.exists(lroMetadata); | ||
| const finalResponse = lroMetadata.finalResponse; | ||
| assert.exists(finalResponse); | ||
| const finalResult = finalResponse.result; | ||
| assert.exists(finalResult); | ||
| assert.strictEqual(finalResult.name, "UpdateFinalResult"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("Arm LRO templates", () => { | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.