Skip to content

Commit

Permalink
Fix #1048 Allow void in final result for Azure-AsyncOperation header (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
markcowl authored Jul 16, 2024
1 parent 45b425f commit 8d69144
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .chronus/changes/async-header-result-2024-6-15-23-4-6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: fix
packages:
- "@azure-tools/typespec-azure-resource-manager"
---

Fix #1048 Allow void in final result for Azure-AsyncOperation header
6 changes: 6 additions & 0 deletions packages/typespec-autorest/test/lro.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ describe("typespec-autorest: Long-running Operations", () => {
delete is ArmResourceDeleteWithoutOkAsync<Widget>;
restart is ArmResourceActionAsync<Widget, void, never>;
munge is ArmResourceActionAsync<Widget, void, Widget>;
alter is ArmResourceActionAsync<Widget, void, void, LroHeaders=ArmAsyncOperationHeader<FinalResult = void>>;
listByResourceGroup is ArmResourceListByParent<Widget>;
listBySubscription is ArmListBySubscription<Widget>;
}
Expand Down Expand Up @@ -162,6 +163,11 @@ describe("typespec-autorest: Long-running Operations", () => {
"final-state-via": "location",
"final-state-schema": "#/definitions/Widget",
});
const alterPath = `${itemPath}/alter`;
deepStrictEqual(openapi.paths[alterPath].post["x-ms-long-running-operation"], true);
deepStrictEqual(openapi.paths[alterPath].post["x-ms-long-running-operation-options"], {
"final-state-via": "azure-async-operation",
});
});
it("Uses final-state-via: location when location is provided for ARM PUT", async () => {
const openapi = await openApiFor(
Expand Down
2 changes: 1 addition & 1 deletion packages/typespec-azure-resource-manager/lib/responses.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ model ArmOperationStatus<
model ArmAsyncOperationHeader<
StatusMonitor extends {} = ArmOperationStatus,
UrlValue extends string = string,
FinalResult extends {} = never
FinalResult extends {} | void = never
> {
/** A link to the status monitor */
@header("Azure-AsyncOperation")
Expand Down
65 changes: 65 additions & 0 deletions packages/typespec-azure-resource-manager/test/lro-metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,71 @@ describe("typespec-azure-resource-manager: ARM LRO Tests", () => {
deepStrictEqual(metadata.finalResultPath, undefined);
deepStrictEqual(metadata.finalStateVia, "location");
});
it("Returns correct metadata for Async action with void return type", async () => {
const [metadata, _diag, _runner] = await getLroMetadataFor(
`
@armProviderNamespace
@useDependency(Azure.ResourceManager.Versions.v1_0_Preview_1)
namespace Microsoft.Test;
interface Operations extends Azure.ResourceManager.Operations {}
@doc("The state of the resource")
enum ResourceState {
Succeeded,
Canceled,
Failed
}
@doc("The widget properties")
model WidgetProperties {
@doc("I am a simple Resource Identifier")
simpleArmId: ResourceIdentifier;
@doc("The provisioning State")
provisioningState: ResourceState;
}
@doc("The result of the post request")
model ResultModel {
@doc("The result message")
message: string;
}
@doc("The request of the post request")
model RequestModel {
@doc("The request message")
message: string;
}
@doc("Foo resource")
model Widget is TrackedResource<WidgetProperties> {
@doc("Widget name")
@key("widgetName")
@segment("widgets")
@path
name: string;
}
@armResourceOperations(Widget)
interface Widgets {
get is ArmResourceRead<Widget>;
createOrUpdate is ArmResourceCreateOrReplaceAsync<Widget>;
update is ArmResourcePatchSync<Widget, WidgetProperties>;
delete is ArmResourceDeleteSync<Widget>;
doStuff is ArmResourceActionAsync<Widget, RequestModel, void, LroHeaders=ArmAsyncOperationHeader<FinalResult = void>>;
listByResourceGroup is ArmResourceListByParent<Widget>;
listBySubscription is ArmListBySubscription<Widget>;
}
`,
"doStuff"
);
ok(metadata);
deepStrictEqual(metadata.finalResult, "void");
deepStrictEqual(metadata.finalEnvelopeResult, "void");
deepStrictEqual(metadata.finalResultPath, undefined);
deepStrictEqual(metadata.finalStateVia, "azure-async-operation");
});

it("Returns correct metadata for Async CreateOrUpdate with union type ProvisioningState", async () => {
const [metadata, _diag, _runner] = await getLroMetadataFor(
Expand Down

0 comments on commit 8d69144

Please sign in to comment.