From b56cf39f2d022edc41d9c048f72f1d3535e6dc41 Mon Sep 17 00:00:00 2001 From: Allen Zhang Date: Tue, 26 Mar 2024 12:54:53 -0700 Subject: [PATCH 1/9] initial checkin --- .../reference/data-types.md | 36 ++++++------ eng/feeds/arm/employee.tsp | 23 ++++---- .../arm-scenarios/extension-resource/main.tsp | 15 +++-- .../arm-scenarios/location-resource/main.tsp | 15 +++-- .../arm-scenarios/nobody-action/main.tsp | 15 +++-- .../arm-scenarios/proxy/main.tsp | 15 +++-- .../arm-scenarios/singleton/main.tsp | 15 +++-- .../arm-scenarios/tenant/main.tsp | 15 +++-- .../arm-scenarios/tracked/main.tsp | 15 +++-- .../arm-scenarios/virtual-resource/main.tsp | 15 +++-- .../typespec-azure-core/src/decorators.ts | 55 ++++++++++++------- .../samples/arm.tsp | 15 +++-- .../lib/models.tsp | 25 +++++---- .../lib/private-links.tsp | 19 ++++--- .../lib/responses.tsp | 2 +- 15 files changed, 173 insertions(+), 122 deletions(-) diff --git a/docs/libraries/azure-resource-manager/reference/data-types.md b/docs/libraries/azure-resource-manager/reference/data-types.md index 3dee2d81bc..1798546fbd 100644 --- a/docs/libraries/azure-resource-manager/reference/data-types.md +++ b/docs/libraries/azure-resource-manager/reference/data-types.md @@ -1106,12 +1106,20 @@ The type of identity to use. enum Azure.ResourceManager.KeyEncryptionIdentity ``` +### `Versions` {#Azure.ResourceManager.Versions} + +Supported versions of Azure.ResourceManager building blocks. + +```typespec +enum Azure.ResourceManager.Versions +``` + ### `PrivateEndpointConnectionProvisioningState` {#Azure.ResourceManager.PrivateEndpointConnectionProvisioningState} The provisioning state of the connection ```typespec -enum Azure.ResourceManager.PrivateEndpointConnectionProvisioningState +union Azure.ResourceManager.PrivateEndpointConnectionProvisioningState ``` ### `PrivateEndpointServiceConnectionStatus` {#Azure.ResourceManager.PrivateEndpointServiceConnectionStatus} @@ -1119,38 +1127,30 @@ enum Azure.ResourceManager.PrivateEndpointConnectionProvisioningState The private endpoint connection status ```typespec -enum Azure.ResourceManager.PrivateEndpointServiceConnectionStatus +union Azure.ResourceManager.PrivateEndpointServiceConnectionStatus ``` ### `ResourceProvisioningState` {#Azure.ResourceManager.ResourceProvisioningState} -Standard terminal provisioning state of resource type. You can spread into your +Standard terminal provisioning state of resource type. You can include in your custom provision state to avoid duplication and ensure consistency ```typespec -enum Azure.ResourceManager.ResourceProvisioningState +union Azure.ResourceManager.ResourceProvisioningState ``` #### Examples ```typespec -enum FooProvisioningState { - ...ResourceProvisioningState, // include standard provisioning states - starting, - started, - stopping, - stopped, +union FooProvisioningState { + ResourceProvisioningState, // include standard provisioning states + starting: "starting", + started: "started", + stopping: "stopping", + stopped: "stopped", } ``` -### `Versions` {#Azure.ResourceManager.Versions} - -Supported versions of Azure.ResourceManager building blocks. - -```typespec -enum Azure.ResourceManager.Versions -``` - ### `ResourceIdentifier` {#Azure.ResourceManager.ResourceIdentifier} A type definition that refers the id to an Azure Resource Manager resource. diff --git a/eng/feeds/arm/employee.tsp b/eng/feeds/arm/employee.tsp index 4a9265c812..074aff0472 100644 --- a/eng/feeds/arm/employee.tsp +++ b/eng/feeds/arm/employee.tsp @@ -39,20 +39,23 @@ model EmployeeProperties { /** The resource provisioning state. */ @lroStatus -enum ProvisioningState { - ...ResourceProvisioningState, +union ProvisioningState { + ResourceProvisioningState, - /** The resource is being provisioned. */ - Provisioning, + /** The resource is being provisioned */ + Provisioning: "Provisioning", - /** The resource is being updated. */ - Updating, + /** The resource is updating */ + Updating: "Updating", - /** The resource is being deleted. */ - Deleting, + /** The resource is being deleted */ + Deleting: "Deleting", - /** The resource provisioning request has been accepted. */ - Accepted, + /** The resource create request has been accepted */ + Accepted: "Accepted", + + /** modelAsString=true */ + string, } interface Operations extends Azure.ResourceManager.Operations {} diff --git a/packages/samples/specs/resource-manager/arm-scenarios/extension-resource/main.tsp b/packages/samples/specs/resource-manager/arm-scenarios/extension-resource/main.tsp index 3621a7512b..11f07b1290 100644 --- a/packages/samples/specs/resource-manager/arm-scenarios/extension-resource/main.tsp +++ b/packages/samples/specs/resource-manager/arm-scenarios/extension-resource/main.tsp @@ -49,20 +49,23 @@ model RoleAssignmentProperties { /** The provisioning state of a resource. */ @lroStatus -enum ProvisioningState { - ...ResourceProvisioningState, +union ProvisioningState { + ResourceProvisioningState, /** The resource is being provisioned */ - Provisioning, + Provisioning: "Provisioning", /** The resource is updating */ - Updating, + Updating: "Updating", /** The resource is being deleted */ - Deleting, + Deleting: "Deleting", /** The resource create request has been accepted */ - Accepted, + Accepted: "Accepted", + + /** modelAsString=true */ + string, } interface Operations extends Azure.ResourceManager.Operations {} diff --git a/packages/samples/specs/resource-manager/arm-scenarios/location-resource/main.tsp b/packages/samples/specs/resource-manager/arm-scenarios/location-resource/main.tsp index cbf9bcc446..24461abce2 100644 --- a/packages/samples/specs/resource-manager/arm-scenarios/location-resource/main.tsp +++ b/packages/samples/specs/resource-manager/arm-scenarios/location-resource/main.tsp @@ -56,20 +56,23 @@ model EmployeeProperties { /** The provisioning state of a resource. */ @lroStatus -enum ProvisioningState { - ...ResourceProvisioningState, +union ProvisioningState { + ResourceProvisioningState, /** The resource is being provisioned */ - Provisioning, + Provisioning: "Provisioning", /** The resource is updating */ - Updating, + Updating: "Updating", /** The resource is being deleted */ - Deleting, + Deleting: "Deleting", /** The resource create request has been accepted */ - Accepted, + Accepted: "Accepted", + + /** modelAsString=true */ + string, } interface Operations extends Azure.ResourceManager.Operations {} diff --git a/packages/samples/specs/resource-manager/arm-scenarios/nobody-action/main.tsp b/packages/samples/specs/resource-manager/arm-scenarios/nobody-action/main.tsp index 4215ac6f9c..33bc8fc52d 100644 --- a/packages/samples/specs/resource-manager/arm-scenarios/nobody-action/main.tsp +++ b/packages/samples/specs/resource-manager/arm-scenarios/nobody-action/main.tsp @@ -55,20 +55,23 @@ model EmployeeProperties { /** The provisioning state of a resource. */ @lroStatus -enum ProvisioningState { - ...ResourceProvisioningState, +union ProvisioningState { + ResourceProvisioningState, /** The resource is being provisioned */ - Provisioning, + Provisioning: "Provisioning", /** The resource is updating */ - Updating, + Updating: "Updating", /** The resource is being deleted */ - Deleting, + Deleting: "Deleting", /** The resource create request has been accepted */ - Accepted, + Accepted: "Accepted", + + /** modelAsString=true */ + string, } interface Operations extends Azure.ResourceManager.Operations {} diff --git a/packages/samples/specs/resource-manager/arm-scenarios/proxy/main.tsp b/packages/samples/specs/resource-manager/arm-scenarios/proxy/main.tsp index c33ed47cdc..69bb483401 100644 --- a/packages/samples/specs/resource-manager/arm-scenarios/proxy/main.tsp +++ b/packages/samples/specs/resource-manager/arm-scenarios/proxy/main.tsp @@ -57,20 +57,23 @@ model EmployeeProperties { /** The provisioning state of a resource. */ @lroStatus -enum ProvisioningState { - ...ResourceProvisioningState, +union ProvisioningState { + ResourceProvisioningState, /** The resource is being provisioned */ - Provisioning, + Provisioning: "Provisioning", /** The resource is updating */ - Updating, + Updating: "Updating", /** The resource is being deleted */ - Deleting, + Deleting: "Deleting", /** The resource create request has been accepted */ - Accepted, + Accepted: "Accepted", + + /** modelAsString=true */ + string, } interface Operations extends Azure.ResourceManager.Operations {} diff --git a/packages/samples/specs/resource-manager/arm-scenarios/singleton/main.tsp b/packages/samples/specs/resource-manager/arm-scenarios/singleton/main.tsp index eb1d6abaa8..e395cd17d7 100644 --- a/packages/samples/specs/resource-manager/arm-scenarios/singleton/main.tsp +++ b/packages/samples/specs/resource-manager/arm-scenarios/singleton/main.tsp @@ -55,20 +55,23 @@ model EmployeeProperties { /** The provisioning state of a resource. */ @lroStatus -enum ProvisioningState { - ...ResourceProvisioningState, +union ProvisioningState { + ResourceProvisioningState, /** The resource is being provisioned */ - Provisioning, + Provisioning: "Provisioning", /** The resource is updating */ - Updating, + Updating: "Updating", /** The resource is being deleted */ - Deleting, + Deleting: "Deleting", /** The resource create request has been accepted */ - Accepted, + Accepted: "Accepted", + + /** modelAsString=true */ + string, } interface Operations extends Azure.ResourceManager.Operations {} diff --git a/packages/samples/specs/resource-manager/arm-scenarios/tenant/main.tsp b/packages/samples/specs/resource-manager/arm-scenarios/tenant/main.tsp index 7f4eb9dd9c..b9d3eac510 100644 --- a/packages/samples/specs/resource-manager/arm-scenarios/tenant/main.tsp +++ b/packages/samples/specs/resource-manager/arm-scenarios/tenant/main.tsp @@ -56,20 +56,23 @@ model EmployeeProperties { /** The provisioning state of a resource. */ @lroStatus -enum ProvisioningState { - ...ResourceProvisioningState, +union ProvisioningState { + ResourceProvisioningState, /** The resource is being provisioned */ - Provisioning, + Provisioning: "Provisioning", /** The resource is updating */ - Updating, + Updating: "Updating", /** The resource is being deleted */ - Deleting, + Deleting: "Deleting", /** The resource create request has been accepted */ - Accepted, + Accepted: "Accepted", + + /** modelAsString=true */ + string, } interface Operations extends Azure.ResourceManager.Operations {} diff --git a/packages/samples/specs/resource-manager/arm-scenarios/tracked/main.tsp b/packages/samples/specs/resource-manager/arm-scenarios/tracked/main.tsp index 702bf5eb54..7faa81df32 100644 --- a/packages/samples/specs/resource-manager/arm-scenarios/tracked/main.tsp +++ b/packages/samples/specs/resource-manager/arm-scenarios/tracked/main.tsp @@ -55,20 +55,23 @@ model EmployeeProperties { /** The provisioning state of a resource. */ @lroStatus -enum ProvisioningState { - ...ResourceProvisioningState, +union ProvisioningState { + ResourceProvisioningState, /** The resource is being provisioned */ - Provisioning, + Provisioning: "Provisioning", /** The resource is updating */ - Updating, + Updating: "Updating", /** The resource is being deleted */ - Deleting, + Deleting: "Deleting", /** The resource create request has been accepted */ - Accepted, + Accepted: "Accepted", + + /** modelAsString=true */ + string, } interface Operations extends Azure.ResourceManager.Operations {} diff --git a/packages/samples/specs/resource-manager/arm-scenarios/virtual-resource/main.tsp b/packages/samples/specs/resource-manager/arm-scenarios/virtual-resource/main.tsp index 1c7b16001c..846a9fa335 100644 --- a/packages/samples/specs/resource-manager/arm-scenarios/virtual-resource/main.tsp +++ b/packages/samples/specs/resource-manager/arm-scenarios/virtual-resource/main.tsp @@ -86,20 +86,23 @@ model EmployeeProperties { /** The provisioning state of a resource. */ @lroStatus -enum ProvisioningState { - ...ResourceProvisioningState, +union ProvisioningState { + ResourceProvisioningState, /** The resource is being provisioned */ - Provisioning, + Provisioning: "Provisioning", /** The resource is updating */ - Updating, + Updating: "Updating", /** The resource is being deleted */ - Deleting, + Deleting: "Deleting", /** The resource create request has been accepted */ - Accepted, + Accepted: "Accepted", + + /** modelAsString=true */ + string, } interface Operations extends Azure.ResourceManager.Operations {} diff --git a/packages/typespec-azure-core/src/decorators.ts b/packages/typespec-azure-core/src/decorators.ts index 2ea6e27cc0..b1e1e2a696 100644 --- a/packages/typespec-azure-core/src/decorators.ts +++ b/packages/typespec-azure-core/src/decorators.ts @@ -5,6 +5,7 @@ import { createDiagnosticCollector, DecoratorContext, Diagnostic, + DiagnosticCollector, Enum, EnumMember, getKnownValues, @@ -309,31 +310,21 @@ function storeLroState( } } -export function extractLroStates( +function extractLroStatesFromUnion( program: Program, - entity: Type -): [LongRunningStates | undefined, readonly Diagnostic[]] { - const result: PartialLongRunningStates = { - states: [], - succeededState: [], - failedState: [], - canceledState: [], - }; - const diagnostics = createDiagnosticCollector(); - if (entity.kind === "ModelProperty") { - // Call the function recursively on the property type - return extractLroStates(program, entity.type); - } else if (entity.kind === "Enum") { - for (const member of entity.members.values()) { - storeLroState(program, result, member.name, member); - } - } else if (entity.kind === "Union") { + entity: Type, + lroStateResult: PartialLongRunningStates, + diagnostics: DiagnosticCollector +) { + if (entity.kind === "Union") { for (const variant of entity.variants.values()) { const option = variant.type; if (option.kind === "Enum") { for (const member of option.members.values()) { - storeLroState(program, result, member.name, member); + storeLroState(program, lroStateResult, member.name, member); } + } else if (option.kind === "Union") { + extractLroStatesFromUnion(program, option, lroStateResult, diagnostics); } else if (option.kind === "Scalar" && option.name === "string") { // Ignore string marking this union as open. continue; @@ -350,9 +341,33 @@ export function extractLroStates( return diagnostics.wrap(undefined); } else { - storeLroState(program, result, option.value, variant); + storeLroState(program, lroStateResult, option.value, variant); } } + } + return; +} + +export function extractLroStates( + program: Program, + entity: Type +): [LongRunningStates | undefined, readonly Diagnostic[]] { + const result: PartialLongRunningStates = { + states: [], + succeededState: [], + failedState: [], + canceledState: [], + }; + const diagnostics = createDiagnosticCollector(); + if (entity.kind === "ModelProperty") { + // Call the function recursively on the property type + return extractLroStates(program, entity.type); + } else if (entity.kind === "Enum") { + for (const member of entity.members.values()) { + storeLroState(program, result, member.name, member); + } + } else if (entity.kind === "Union") { + extractLroStatesFromUnion(program, entity, result, diagnostics); } else { diagnostics.add( createDiagnostic({ diff --git a/packages/typespec-azure-playground-website/samples/arm.tsp b/packages/typespec-azure-playground-website/samples/arm.tsp index 6d731f75dc..35deda3416 100644 --- a/packages/typespec-azure-playground-website/samples/arm.tsp +++ b/packages/typespec-azure-playground-website/samples/arm.tsp @@ -55,20 +55,23 @@ model EmployeeProperties { /** The provisioning state of a resource. */ @lroStatus -enum ProvisioningState { - ...ResourceProvisioningState, +union ProvisioningState { + ResourceProvisioningState, /** The resource is being provisioned */ - Provisioning, + Provisioning: "Provisioning", /** The resource is updating */ - Updating, + Updating: "Updating", /** The resource is being deleted */ - Deleting, + Deleting: "Deleting", /** The resource create request has been accepted */ - Accepted, + Accepted: "Accepted", + + /** modelAsString=true */ + string, } /** Employee move request */ diff --git a/packages/typespec-azure-resource-manager/lib/models.tsp b/packages/typespec-azure-resource-manager/lib/models.tsp index 73cd9da3d6..d347148baa 100644 --- a/packages/typespec-azure-resource-manager/lib/models.tsp +++ b/packages/typespec-azure-resource-manager/lib/models.tsp @@ -126,32 +126,35 @@ model ResourceIdentifierAllowedResource { } /** - * Standard terminal provisioning state of resource type. You can spread into your + * Standard terminal provisioning state of resource type. You can include in your * custom provision state to avoid duplication and ensure consistency * * @example * * ```typespec - * enum FooProvisioningState { - * ...ResourceProvisioningState, // include standard provisioning states - * starting, - * started, - * stopping, - * stopped, + * union FooProvisioningState { + * ResourceProvisioningState, // include standard provisioning states + * starting: "starting", + * started: "started", + * stopping: "stopping", + * stopped: "stopped", * } * ``` */ @doc("The provisioning state of a resource type.") @Azure.Core.lroStatus -enum ResourceProvisioningState { +union ResourceProvisioningState { @doc("Resource has been created.") - Succeeded, + Succeeded: "Succeeded", @doc("Resource creation failed.") - Failed, + Failed: "Failed", @doc("Resource creation was canceled.") - Canceled, + Canceled: "Canceled", + + @doc("modelAsString=true") + string, } /** diff --git a/packages/typespec-azure-resource-manager/lib/private-links.tsp b/packages/typespec-azure-resource-manager/lib/private-links.tsp index 1548fdb41e..bd6bd2ae53 100644 --- a/packages/typespec-azure-resource-manager/lib/private-links.tsp +++ b/packages/typespec-azure-resource-manager/lib/private-links.tsp @@ -96,26 +96,29 @@ model PrivateLinkServiceConnectionState { } /** The provisioning state of the connection */ -enum PrivateEndpointConnectionProvisioningState { - ...ResourceProvisioningState, +union PrivateEndpointConnectionProvisioningState { + ResourceProvisioningState, /** Connection is being created */ - Creating, + Creating: "Creating", /** Connection is being deleted */ - Deleting, + Deleting: "Deleting", } /** The private endpoint connection status */ -enum PrivateEndpointServiceConnectionStatus { +union PrivateEndpointServiceConnectionStatus { /** Connectionaiting for approval or rejection */ - Pending, + Pending: "Pending", /** Connection approved */ - Approved, + Approved: "Approved", /** Connection Rejected */ - Rejected, + Rejected: "Rejected", + + /** modelAsString=true */ + string, } model PrivateLinkResource extends Azure.ResourceManager.Foundations.ProxyResourceBase { diff --git a/packages/typespec-azure-resource-manager/lib/responses.tsp b/packages/typespec-azure-resource-manager/lib/responses.tsp index b326199466..25e1dbd28b 100644 --- a/packages/typespec-azure-resource-manager/lib/responses.tsp +++ b/packages/typespec-azure-resource-manager/lib/responses.tsp @@ -88,7 +88,7 @@ model ArmAcceptedLroResponse< */ model ArmOperationStatus< Properties extends {} = never, - StatusValues extends TypeSpec.Reflection.Enum | TypeSpec.Reflection.Union = ResourceProvisioningState + StatusValues extends TypeSpec.Reflection.Union = ResourceProvisioningState > is ArmResourceBase { /** RP-specific properties for the operationStatus resource, only appears when operation ended with Succeeded status */ @visibility("read") From 2728082e5e343a13eb98ecb271af8baf6c060cb0 Mon Sep 17 00:00:00 2001 From: Allen Zhang Date: Tue, 26 Mar 2024 12:59:05 -0700 Subject: [PATCH 2/9] add changelog --- .../azhang_ProvisioningStateToUnion-2024-2-26-12-58-44.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .chronus/changes/azhang_ProvisioningStateToUnion-2024-2-26-12-58-44.md diff --git a/.chronus/changes/azhang_ProvisioningStateToUnion-2024-2-26-12-58-44.md b/.chronus/changes/azhang_ProvisioningStateToUnion-2024-2-26-12-58-44.md new file mode 100644 index 0000000000..ada72db119 --- /dev/null +++ b/.chronus/changes/azhang_ProvisioningStateToUnion-2024-2-26-12-58-44.md @@ -0,0 +1,8 @@ +--- +changeKind: breaking +packages: + - "@azure-tools/typespec-azure-core" + - "@azure-tools/typespec-azure-resource-manager" +--- + +Switching ProvisioningState from enum to Open union \ No newline at end of file From 9c645a6cda3e576a800d13585d89307f31dcddba Mon Sep 17 00:00:00 2001 From: Allen Zhang Date: Mon, 15 Apr 2024 13:32:07 -0700 Subject: [PATCH 3/9] update doc --- .../reference/data-types.md | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/docs/libraries/azure-resource-manager/reference/data-types.md b/docs/libraries/azure-resource-manager/reference/data-types.md index ae2d28cd59..af22649b86 100644 --- a/docs/libraries/azure-resource-manager/reference/data-types.md +++ b/docs/libraries/azure-resource-manager/reference/data-types.md @@ -1126,23 +1126,15 @@ union Azure.ResourceManager.ResourceProvisioningState #### Examples ```typespec -enum FooProvisioningState { - ...ResourceProvisioningState, // include standard provisioning states - starting, - started, - stopping, - stopped, +union FooProvisioningState { + ResourceProvisioningState, // include standard provisioning states + starting: "starting", + started: "started", + stopping: "stopping", + stopped: "stopped", } ``` -### `Versions` {#Azure.ResourceManager.Versions} - -Supported versions of Azure.ResourceManager building blocks. - -```typespec -enum Azure.ResourceManager.Versions -``` - ## Azure.ResourceManager.CommonTypes ### `Versions` {#Azure.ResourceManager.CommonTypes.Versions} From 293ac2f86c1ecb3ee3b707bb3c0d20691a4c0ab5 Mon Sep 17 00:00:00 2001 From: Allen Zhang Date: Mon, 15 Apr 2024 14:51:20 -0700 Subject: [PATCH 4/9] Remove comment --- eng/feeds/arm/employee.tsp | 1 - .../resource-manager/arm-scenarios/extension-resource/main.tsp | 1 - .../resource-manager/arm-scenarios/location-resource/main.tsp | 1 - .../specs/resource-manager/arm-scenarios/nobody-action/main.tsp | 1 - .../samples/specs/resource-manager/arm-scenarios/proxy/main.tsp | 1 - .../specs/resource-manager/arm-scenarios/singleton/main.tsp | 1 - .../samples/specs/resource-manager/arm-scenarios/tenant/main.tsp | 1 - .../specs/resource-manager/arm-scenarios/tracked/main.tsp | 1 - .../resource-manager/arm-scenarios/virtual-resource/main.tsp | 1 - packages/typespec-azure-resource-manager/lib/private-links.tsp | 1 - 10 files changed, 10 deletions(-) diff --git a/eng/feeds/arm/employee.tsp b/eng/feeds/arm/employee.tsp index 074aff0472..568727bdff 100644 --- a/eng/feeds/arm/employee.tsp +++ b/eng/feeds/arm/employee.tsp @@ -54,7 +54,6 @@ union ProvisioningState { /** The resource create request has been accepted */ Accepted: "Accepted", - /** modelAsString=true */ string, } diff --git a/packages/samples/specs/resource-manager/arm-scenarios/extension-resource/main.tsp b/packages/samples/specs/resource-manager/arm-scenarios/extension-resource/main.tsp index 11f07b1290..1fe07efefa 100644 --- a/packages/samples/specs/resource-manager/arm-scenarios/extension-resource/main.tsp +++ b/packages/samples/specs/resource-manager/arm-scenarios/extension-resource/main.tsp @@ -64,7 +64,6 @@ union ProvisioningState { /** The resource create request has been accepted */ Accepted: "Accepted", - /** modelAsString=true */ string, } diff --git a/packages/samples/specs/resource-manager/arm-scenarios/location-resource/main.tsp b/packages/samples/specs/resource-manager/arm-scenarios/location-resource/main.tsp index 24461abce2..69beeaddb7 100644 --- a/packages/samples/specs/resource-manager/arm-scenarios/location-resource/main.tsp +++ b/packages/samples/specs/resource-manager/arm-scenarios/location-resource/main.tsp @@ -71,7 +71,6 @@ union ProvisioningState { /** The resource create request has been accepted */ Accepted: "Accepted", - /** modelAsString=true */ string, } diff --git a/packages/samples/specs/resource-manager/arm-scenarios/nobody-action/main.tsp b/packages/samples/specs/resource-manager/arm-scenarios/nobody-action/main.tsp index 33bc8fc52d..0d744c82f8 100644 --- a/packages/samples/specs/resource-manager/arm-scenarios/nobody-action/main.tsp +++ b/packages/samples/specs/resource-manager/arm-scenarios/nobody-action/main.tsp @@ -70,7 +70,6 @@ union ProvisioningState { /** The resource create request has been accepted */ Accepted: "Accepted", - /** modelAsString=true */ string, } diff --git a/packages/samples/specs/resource-manager/arm-scenarios/proxy/main.tsp b/packages/samples/specs/resource-manager/arm-scenarios/proxy/main.tsp index 69bb483401..3605761a17 100644 --- a/packages/samples/specs/resource-manager/arm-scenarios/proxy/main.tsp +++ b/packages/samples/specs/resource-manager/arm-scenarios/proxy/main.tsp @@ -72,7 +72,6 @@ union ProvisioningState { /** The resource create request has been accepted */ Accepted: "Accepted", - /** modelAsString=true */ string, } diff --git a/packages/samples/specs/resource-manager/arm-scenarios/singleton/main.tsp b/packages/samples/specs/resource-manager/arm-scenarios/singleton/main.tsp index e395cd17d7..586f382a0c 100644 --- a/packages/samples/specs/resource-manager/arm-scenarios/singleton/main.tsp +++ b/packages/samples/specs/resource-manager/arm-scenarios/singleton/main.tsp @@ -70,7 +70,6 @@ union ProvisioningState { /** The resource create request has been accepted */ Accepted: "Accepted", - /** modelAsString=true */ string, } diff --git a/packages/samples/specs/resource-manager/arm-scenarios/tenant/main.tsp b/packages/samples/specs/resource-manager/arm-scenarios/tenant/main.tsp index b9d3eac510..2a531becbd 100644 --- a/packages/samples/specs/resource-manager/arm-scenarios/tenant/main.tsp +++ b/packages/samples/specs/resource-manager/arm-scenarios/tenant/main.tsp @@ -71,7 +71,6 @@ union ProvisioningState { /** The resource create request has been accepted */ Accepted: "Accepted", - /** modelAsString=true */ string, } diff --git a/packages/samples/specs/resource-manager/arm-scenarios/tracked/main.tsp b/packages/samples/specs/resource-manager/arm-scenarios/tracked/main.tsp index 7faa81df32..a008280c9f 100644 --- a/packages/samples/specs/resource-manager/arm-scenarios/tracked/main.tsp +++ b/packages/samples/specs/resource-manager/arm-scenarios/tracked/main.tsp @@ -70,7 +70,6 @@ union ProvisioningState { /** The resource create request has been accepted */ Accepted: "Accepted", - /** modelAsString=true */ string, } diff --git a/packages/samples/specs/resource-manager/arm-scenarios/virtual-resource/main.tsp b/packages/samples/specs/resource-manager/arm-scenarios/virtual-resource/main.tsp index 846a9fa335..5cceb0278e 100644 --- a/packages/samples/specs/resource-manager/arm-scenarios/virtual-resource/main.tsp +++ b/packages/samples/specs/resource-manager/arm-scenarios/virtual-resource/main.tsp @@ -101,7 +101,6 @@ union ProvisioningState { /** The resource create request has been accepted */ Accepted: "Accepted", - /** modelAsString=true */ string, } diff --git a/packages/typespec-azure-resource-manager/lib/private-links.tsp b/packages/typespec-azure-resource-manager/lib/private-links.tsp index 9076c19ea5..1bf17a3007 100644 --- a/packages/typespec-azure-resource-manager/lib/private-links.tsp +++ b/packages/typespec-azure-resource-manager/lib/private-links.tsp @@ -117,7 +117,6 @@ union PrivateEndpointServiceConnectionStatus { /** Connection Rejected */ Rejected: "Rejected", - /** modelAsString=true */ string, } From 9bcdabada654c31e0bc1f05496b7f8685231f472 Mon Sep 17 00:00:00 2001 From: Allen Zhang Date: Tue, 16 Apr 2024 08:50:25 -0700 Subject: [PATCH 5/9] Fix @doc --- packages/typespec-azure-resource-manager/lib/models.tsp | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/typespec-azure-resource-manager/lib/models.tsp b/packages/typespec-azure-resource-manager/lib/models.tsp index 7667c23e76..f502e7f2b4 100644 --- a/packages/typespec-azure-resource-manager/lib/models.tsp +++ b/packages/typespec-azure-resource-manager/lib/models.tsp @@ -126,7 +126,6 @@ union ResourceProvisioningState { @doc("Resource creation was canceled.") Canceled: "Canceled", - @doc("modelAsString=true") string, } From 24ef2615562ae614a3f4b7614468fc7e5a8d1872 Mon Sep 17 00:00:00 2001 From: Allen Zhang Date: Tue, 16 Apr 2024 08:53:10 -0700 Subject: [PATCH 6/9] Update doc --- .../reference/data-types.md | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/docs/libraries/azure-resource-manager/reference/data-types.md b/docs/libraries/azure-resource-manager/reference/data-types.md index a8f09ea348..59bc33e138 100644 --- a/docs/libraries/azure-resource-manager/reference/data-types.md +++ b/docs/libraries/azure-resource-manager/reference/data-types.md @@ -1074,65 +1074,65 @@ model Azure.ResourceManager.TrackedResource | ----------- | ------------ | ----------- | | properties? | `Properties` | | -### `PrivateEndpointConnectionProvisioningState` {#Azure.ResourceManager.PrivateEndpointConnectionProvisioningState} +### `Versions` {#Azure.ResourceManager.Versions} -The provisioning state of the connection +Supported versions of Azure.ResourceManager building blocks. ```typespec -union Azure.ResourceManager.PrivateEndpointConnectionProvisioningState +enum Azure.ResourceManager.Versions ``` -### `PrivateEndpointServiceConnectionStatus` {#Azure.ResourceManager.PrivateEndpointServiceConnectionStatus} +### `InfrastructureEncryption` {#Azure.ResourceManager.InfrastructureEncryption} -The private endpoint connection status +(Optional) Discouraged to include in resource definition. Only needed where it is possible to disable platform (AKA infrastructure) encryption. Azure SQL TDE is an example of this. Values are enabled and disabled. ```typespec -union Azure.ResourceManager.PrivateEndpointServiceConnectionStatus +union Azure.ResourceManager.InfrastructureEncryption ``` -### `ResourceProvisioningState` {#Azure.ResourceManager.ResourceProvisioningState} +### `KeyEncryptionKeyIdentity` {#Azure.ResourceManager.KeyEncryptionKeyIdentity} -Standard terminal provisioning state of resource type. You can include in your -custom provision state to avoid duplication and ensure consistency +The type of identity to use. ```typespec -union Azure.ResourceManager.ResourceProvisioningState +union Azure.ResourceManager.KeyEncryptionKeyIdentity ``` -#### Examples +### `PrivateEndpointConnectionProvisioningState` {#Azure.ResourceManager.PrivateEndpointConnectionProvisioningState} + +The provisioning state of the connection ```typespec -enum FooProvisioningState { - ...ResourceProvisioningState, // include standard provisioning states - starting, - started, - stopping, - stopped, -} +union Azure.ResourceManager.PrivateEndpointConnectionProvisioningState ``` -### `Versions` {#Azure.ResourceManager.Versions} +### `PrivateEndpointServiceConnectionStatus` {#Azure.ResourceManager.PrivateEndpointServiceConnectionStatus} -Supported versions of Azure.ResourceManager building blocks. +The private endpoint connection status ```typespec -enum Azure.ResourceManager.Versions +union Azure.ResourceManager.PrivateEndpointServiceConnectionStatus ``` -### `InfrastructureEncryption` {#Azure.ResourceManager.InfrastructureEncryption} +### `ResourceProvisioningState` {#Azure.ResourceManager.ResourceProvisioningState} -(Optional) Discouraged to include in resource definition. Only needed where it is possible to disable platform (AKA infrastructure) encryption. Azure SQL TDE is an example of this. Values are enabled and disabled. +Standard terminal provisioning state of resource type. You can include in your +custom provision state to avoid duplication and ensure consistency ```typespec -union Azure.ResourceManager.InfrastructureEncryption +union Azure.ResourceManager.ResourceProvisioningState ``` -### `KeyEncryptionKeyIdentity` {#Azure.ResourceManager.KeyEncryptionKeyIdentity} - -The type of identity to use. +#### Examples ```typespec -union Azure.ResourceManager.KeyEncryptionKeyIdentity +union FooProvisioningState { + ResourceProvisioningState, // include standard provisioning states + starting: "starting", + started: "started", + stopping: "stopping", + stopped: "stopped", +} ``` ## Azure.ResourceManager.CommonTypes From 7e2fd2ac8bef697a05ceffc21698db53c6b21266 Mon Sep 17 00:00:00 2001 From: Allen Zhang Date: Tue, 16 Apr 2024 09:16:03 -0700 Subject: [PATCH 7/9] Fixing test pass --- .../test/lro-metadata.test.ts | 285 ++++++++++++++++++ 1 file changed, 285 insertions(+) diff --git a/packages/typespec-azure-resource-manager/test/lro-metadata.test.ts b/packages/typespec-azure-resource-manager/test/lro-metadata.test.ts index 1be5e2a456..6f0284a352 100644 --- a/packages/typespec-azure-resource-manager/test/lro-metadata.test.ts +++ b/packages/typespec-azure-resource-manager/test/lro-metadata.test.ts @@ -310,4 +310,289 @@ describe("typespec-azure-resource-manager: ARM LRO Tests", () => { deepStrictEqual(metadata.finalResultPath, undefined); deepStrictEqual(metadata.finalStateVia, "location"); }); + + it("Returns correct metadata for Async CreateOrUpdate with union type ProvisioningState", 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") + union ResourceState { + Succeeded: "Succeeded", + Canceled: "Canceled", + Failed: "Failed", + string + } + + @doc("The widget properties") + model WidgetProperties { + @doc("I am a simple Resource Identifier") + simpleArmId: ResourceIdentifier; + + @doc("The provisioning State") + provisioningState: ResourceState; + } + + @doc("Foo resource") + model Widget is TrackedResource { + @doc("Widget name") + @key("widgetName") + @segment("widgets") + @path + name: string; + } + @armResourceOperations(Widget) + interface Widgets { + get is ArmResourceRead; + createOrUpdate is ArmResourceCreateOrReplaceAsync; + update is ArmResourcePatchSync; + delete is ArmResourceDeleteSync; + listByResourceGroup is ArmResourceListByParent; + listBySubscription is ArmListBySubscription; + } + + `, + "createOrUpdate" + ); + ok(metadata); + deepStrictEqual((metadata.finalResult as Model)?.name, "Widget"); + deepStrictEqual((metadata.finalEnvelopeResult as Model)?.name, "Widget"); + deepStrictEqual(metadata.finalResultPath, undefined); + deepStrictEqual(metadata.finalStateVia, "original-uri"); + }); + + it("Returns correct metadata for Async CreateOrUpdate with final location, with union type ProvisioningState", 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") + union ResourceState { + Succeeded: "Succeeded", + Canceled: "Canceled", + Failed: "Failed" + } + + @doc("The widget properties") + model WidgetProperties { + @doc("I am a simple Resource Identifier") + simpleArmId: ResourceIdentifier; + + @doc("The provisioning State") + provisioningState: ResourceState; + } + + @doc("Foo resource") + model Widget is TrackedResource { + @doc("Widget name") + @key("widgetName") + @segment("widgets") + @path + name: string; + } + @armResourceOperations(Widget) + interface Widgets { + get is ArmResourceRead; + createOrUpdate is ArmResourceCreateOrReplaceAsync, + ArmCombinedLroHeaders< + ArmOperationStatus, + Widget, + string, + string + > + >; + update is ArmResourcePatchSync; + delete is ArmResourceDeleteSync; + listByResourceGroup is ArmResourceListByParent; + listBySubscription is ArmListBySubscription; + } + + `, + "createOrUpdate" + ); + ok(metadata); + deepStrictEqual((metadata.finalResult as Model)?.name, "Widget"); + deepStrictEqual((metadata.finalEnvelopeResult as Model)?.name, "Widget"); + deepStrictEqual(metadata.finalResultPath, undefined); + deepStrictEqual(metadata.finalStateVia, "location"); + }); + + it("Returns correct metadata for Async Update with union type ProvisioningState", 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") + union ResourceState { + Succeeded: "Succeeded", + Canceled: "Canceled", + Failed: "Failed" + } + + @doc("The widget properties") + model WidgetProperties { + @doc("I am a simple Resource Identifier") + simpleArmId: ResourceIdentifier; + + @doc("The provisioning State") + provisioningState: ResourceState; + } + + @doc("Foo resource") + model Widget is TrackedResource { + @doc("Widget name") + @key("widgetName") + @segment("widgets") + @path + name: string; + } + @armResourceOperations(Widget) + interface Widgets { + get is ArmResourceRead; + createOrUpdate is ArmResourceCreateOrReplaceAsync; + update is ArmResourcePatchAsync; + delete is ArmResourceDeleteSync; + listByResourceGroup is ArmResourceListByParent; + listBySubscription is ArmListBySubscription; + } + `, + "update" + ); + ok(metadata); + deepStrictEqual((metadata.finalResult as Model)?.name, "Widget"); + deepStrictEqual((metadata.finalEnvelopeResult as Model)?.name, "Widget"); + deepStrictEqual(metadata.finalResultPath, undefined); + deepStrictEqual(metadata.finalStateVia, "location"); + }); + + it("Returns correct metadata for Async Delete with union type ProvisioningState", 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") + union ResourceState { + Succeeded: "Succeeded", + Canceled: "Canceled", + Failed: "Failed" + } + + @doc("The widget properties") + model WidgetProperties { + @doc("I am a simple Resource Identifier") + simpleArmId: ResourceIdentifier; + + @doc("The provisioning State") + provisioningState: ResourceState; + } + + @doc("Foo resource") + model Widget is TrackedResource { + @doc("Widget name") + @key("widgetName") + @segment("widgets") + @path + name: string; + } + @armResourceOperations(Widget) + interface Widgets { + get is ArmResourceRead; + createOrUpdate is ArmResourceCreateOrReplaceAsync; + update is ArmResourcePatchSync; + delete is ArmResourceDeleteAsync; + listByResourceGroup is ArmResourceListByParent; + listBySubscription is ArmListBySubscription; + } + `, + "delete" + ); + ok(metadata); + deepStrictEqual(metadata.finalResult, "void"); + deepStrictEqual(metadata.finalEnvelopeResult, "void"); + deepStrictEqual(metadata.finalResultPath, undefined); + deepStrictEqual(metadata.finalStateVia, "location"); + }); + + it("Returns correct metadata for Async action with union type ProvisioningState", 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") + union ResourceState { + Succeeded: "Succeeded", + Canceled: "Canceled", + Failed: "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 { + @doc("Widget name") + @key("widgetName") + @segment("widgets") + @path + name: string; + } + + @armResourceOperations(Widget) + interface Widgets { + get is ArmResourceRead; + createOrUpdate is ArmResourceCreateOrReplaceAsync; + update is ArmResourcePatchSync; + delete is ArmResourceDeleteSync; + doStuff is ArmResourceActionAsync; + listByResourceGroup is ArmResourceListByParent; + listBySubscription is ArmListBySubscription; + } + `, + "doStuff" + ); + ok(metadata); + deepStrictEqual((metadata.finalResult as Model)?.name, "ResultModel"); + deepStrictEqual((metadata.finalEnvelopeResult as Model)?.name, "ResultModel"); + deepStrictEqual(metadata.finalResultPath, undefined); + deepStrictEqual(metadata.finalStateVia, "location"); + }); }); From 56cfcd484d73c4398d942d6c16ae86c3508da7a4 Mon Sep 17 00:00:00 2001 From: Allen Zhang Date: Tue, 16 Apr 2024 14:37:48 -0700 Subject: [PATCH 8/9] Fixing test and doc --- .../azure-resource-manager/step05.md | 22 ++++++++++++++----- eng/feeds/arm-canonical/employee.tsp | 14 +++++++----- .../test/decorators.test.ts | 4 ++++ 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/docs/getstarted/azure-resource-manager/step05.md b/docs/getstarted/azure-resource-manager/step05.md index e15746921b..54a22476a6 100644 --- a/docs/getstarted/azure-resource-manager/step05.md +++ b/docs/getstarted/azure-resource-manager/step05.md @@ -39,12 +39,22 @@ namespace Microsoft.ContosoProviderHub; interface Operations extends Azure.ResourceManager.Operations {} @lroStatus -enum ProvisioningState { - ...ResourceProvisioningState, - Provisioning, - Updating, - Deleting, - Accepted, +union ProvisioningState { + ResourceProvisioningState, + + /** The resource is being provisioned. */ + Provisioning: "Provisioning", + + /** The resource is being updated. */ + Updating: "Updating", + + /** The resource is being deleted. */ + Deleting: "Deleting", + + /** The resource provisioning request has been accepted. */ + Accepted: "Accepted", + + string, } @doc("The properties of UserResource") diff --git a/eng/feeds/arm-canonical/employee.tsp b/eng/feeds/arm-canonical/employee.tsp index 4a9265c812..2ec68b456a 100644 --- a/eng/feeds/arm-canonical/employee.tsp +++ b/eng/feeds/arm-canonical/employee.tsp @@ -39,20 +39,22 @@ model EmployeeProperties { /** The resource provisioning state. */ @lroStatus -enum ProvisioningState { - ...ResourceProvisioningState, +union ProvisioningState { + ResourceProvisioningState, /** The resource is being provisioned. */ - Provisioning, + Provisioning: "Provisioning", /** The resource is being updated. */ - Updating, + Updating: "Updating", /** The resource is being deleted. */ - Deleting, + Deleting: "Deleting", /** The resource provisioning request has been accepted. */ - Accepted, + Accepted: "Accepted", + + string, } interface Operations extends Azure.ResourceManager.Operations {} diff --git a/packages/typespec-azure-core/test/decorators.test.ts b/packages/typespec-azure-core/test/decorators.test.ts index b169403675..b2d09cc928 100644 --- a/packages/typespec-azure-core/test/decorators.test.ts +++ b/packages/typespec-azure-core/test/decorators.test.ts @@ -323,6 +323,10 @@ describe("typespec-azure-core: decorators", () => { code: "@azure-tools/typespec-azure-core/lro-status-union-non-string", message: "Union contains non-string value type Scalar.", }, + { + code: "@azure-tools/typespec-azure-core/lro-status-missing", + message: "Terminal long-running operation states are missing: Failed.", + }, ]); }); From fe9c37cc379c49fca000c927285a5eb053d342ad Mon Sep 17 00:00:00 2001 From: Allen Zhang Date: Wed, 17 Apr 2024 15:37:58 -0700 Subject: [PATCH 9/9] adding a mixed union test case --- .../test/lro-metadata.test.ts | 67 ++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/packages/typespec-azure-resource-manager/test/lro-metadata.test.ts b/packages/typespec-azure-resource-manager/test/lro-metadata.test.ts index 6f0284a352..27780cdda0 100644 --- a/packages/typespec-azure-resource-manager/test/lro-metadata.test.ts +++ b/packages/typespec-azure-resource-manager/test/lro-metadata.test.ts @@ -1,6 +1,6 @@ import { LroMetadata, getLroMetadata } from "@azure-tools/typespec-azure-core"; import { Diagnostic, Model } from "@typespec/compiler"; -import { BasicTestRunner } from "@typespec/compiler/testing"; +import { BasicTestRunner, expectDiagnosticEmpty } from "@typespec/compiler/testing"; import { HttpOperation, RouteResolutionOptions, getAllHttpServices } from "@typespec/http"; import { deepStrictEqual, ok } from "assert"; import { describe, it } from "vitest"; @@ -595,4 +595,69 @@ describe("typespec-azure-resource-manager: ARM LRO Tests", () => { deepStrictEqual(metadata.finalResultPath, undefined); deepStrictEqual(metadata.finalStateVia, "location"); }); + + it("Returns correct metadata for Async CreateOrUpdate with final location, with mixed union type ProvisioningState", async () => { + const [metadata, _diag, _runner] = await getLroMetadataFor( + ` + @armProviderNamespace + @useDependency(Azure.ResourceManager.Versions.v1_0_Preview_1) + @useDependency(Azure.Core.Versions.v1_0_Preview_1) + namespace Microsoft.Test; + + interface Operations extends Azure.ResourceManager.Operations {} + + @doc("The state of the resource") + union BaseState { + Succeeded: "Succeeded", + } + + enum BaseState2 { + Failed, + } + + @doc("The state of the resource") + @Azure.Core.lroStatus + union ResourceState { + BaseState, + BaseState2, + Canceled: "Canceled", + } + + @doc("The widget properties") + model WidgetProperties { + @doc("The provisioning State") + provisioningState: ResourceState; + } + + @doc("Foo resource") + model Widget is TrackedResource { + @doc("Widget name") + @key("widgetName") + @segment("widgets") + @path + name: string; + } + @armResourceOperations(Widget) + interface Widgets { + createOrUpdate is ArmResourceCreateOrReplaceAsync, + ArmCombinedLroHeaders< + ArmOperationStatus, + Widget, + string, + string + > + >; + } + + `, + "createOrUpdate" + ); + ok(metadata); + expectDiagnosticEmpty(_diag); + deepStrictEqual((metadata.finalResult as Model)?.name, "Widget"); + deepStrictEqual((metadata.finalEnvelopeResult as Model)?.name, "Widget"); + deepStrictEqual(metadata.finalResultPath, undefined); + deepStrictEqual(metadata.finalStateVia, "location"); + }); });