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

Fix #1048 Allow void in final result for Azure-AsyncOperation header #1166

Merged
merged 4 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
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
markcowl marked this conversation as resolved.
Show resolved Hide resolved
> {
/** A link to the status monitor */
@header("Azure-AsyncOperation")
Expand Down
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
Loading