From 7b8843441b251e34ccdbcdd8a8b3babae1848f26 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 2 Jul 2024 11:19:14 -0700 Subject: [PATCH 1/6] Arm common --- .../lib/common-types/commontypes.private.decorators.tsp | 2 +- .../src/commontypes.private.decorators.ts | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/typespec-azure-resource-manager/lib/common-types/commontypes.private.decorators.tsp b/packages/typespec-azure-resource-manager/lib/common-types/commontypes.private.decorators.tsp index 889a7ec8e1..08b099598a 100644 --- a/packages/typespec-azure-resource-manager/lib/common-types/commontypes.private.decorators.tsp +++ b/packages/typespec-azure-resource-manager/lib/common-types/commontypes.private.decorators.tsp @@ -19,7 +19,7 @@ alias ArmCommonTypeVersionSpec = { * @param referenceFile Reference file */ extern dec armCommonDefinition( - target: Model, + target: Model | Enum | Union, definitionName?: valueof string, version?: valueof EnumMember | ArmCommonTypeVersionSpec | string, referenceFile?: valueof string diff --git a/packages/typespec-azure-resource-manager/src/commontypes.private.decorators.ts b/packages/typespec-azure-resource-manager/src/commontypes.private.decorators.ts index 326a380203..1b3f40c384 100644 --- a/packages/typespec-azure-resource-manager/src/commontypes.private.decorators.ts +++ b/packages/typespec-azure-resource-manager/src/commontypes.private.decorators.ts @@ -5,6 +5,7 @@ import { Model, ModelProperty, Program, + Union, } from "@typespec/compiler"; import { ArmStateKeys } from "./state.js"; @@ -18,7 +19,7 @@ function getArmTypesPath(program: Program): string { function storeCommonTypeRecord( context: DecoratorContext, - entity: Model | ModelProperty, + entity: Model | ModelProperty | Enum | Union, kind: "definitions" | "parameters", name: string, version?: string | EnumValue | ArmCommonTypeVersionSpec, @@ -69,7 +70,7 @@ export interface ArmCommonTypeRecords { export function getCommonTypeRecords( program: Program, - entity: Model | ModelProperty + entity: Model | ModelProperty | Enum | Union ): ArmCommonTypeRecords { return program.stateMap(ArmStateKeys.armCommonDefinitions).get(entity) ?? { records: {} }; } @@ -114,14 +115,14 @@ export function $armCommonParameter( */ export function $armCommonDefinition( context: DecoratorContext, - entity: Model, + entity: Model | Enum | Union, definitionName?: string, version?: string | EnumValue | ArmCommonTypeVersionSpec, referenceFile?: string ): void { // Use the name of the model type if not specified if (!definitionName) { - definitionName = entity.name; + definitionName = entity.name!; } storeCommonTypeRecord(context, entity, "definitions", definitionName, version, referenceFile); From 6c8a023d25890f4e671fecadf7edfdfed6da26a9 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 2 Jul 2024 12:25:35 -0700 Subject: [PATCH 2/6] Add annotations --- .../lib/common-types/managed-identity-ref.tsp | 11 +++++++++++ .../lib/common-types/private-links-ref.tsp | 12 ++++++++++++ .../lib/common-types/types-ref.tsp | 2 ++ 3 files changed, 25 insertions(+) diff --git a/packages/typespec-azure-resource-manager/lib/common-types/managed-identity-ref.tsp b/packages/typespec-azure-resource-manager/lib/common-types/managed-identity-ref.tsp index c839d489ed..12e9962ff3 100644 --- a/packages/typespec-azure-resource-manager/lib/common-types/managed-identity-ref.tsp +++ b/packages/typespec-azure-resource-manager/lib/common-types/managed-identity-ref.tsp @@ -77,3 +77,14 @@ namespace Azure.ResourceManager.CommonTypes; Azure.ResourceManager.CommonTypes.Versions.v5, "managedidentity.json" ); + +@@armCommonDefinition(ManagedServiceIdentityType, + "ManagedServiceIdentityType", + Azure.ResourceManager.CommonTypes.Versions.v3, + "managedidentity.json" +); +@@armCommonDefinition(SystemAssignedServiceIdentityType, + "SystemAssignedServiceIdentityType", + Azure.ResourceManager.CommonTypes.Versions.v3, + "managedidentity.json" +); diff --git a/packages/typespec-azure-resource-manager/lib/common-types/private-links-ref.tsp b/packages/typespec-azure-resource-manager/lib/common-types/private-links-ref.tsp index 2fca19e18d..d878f0e926 100644 --- a/packages/typespec-azure-resource-manager/lib/common-types/private-links-ref.tsp +++ b/packages/typespec-azure-resource-manager/lib/common-types/private-links-ref.tsp @@ -141,6 +141,18 @@ namespace Azure.ResourceManager.CommonTypes; "privatelinks.json" ); +@@armCommonDefinition(PrivateEndpointServiceConnectionStatus, + "PrivateEndpointServiceConnectionStatus", + Azure.ResourceManager.CommonTypes.Versions.v3, + "privatelinks.json" +); + +@@armCommonDefinition(PrivateEndpointConnectionProvisioningState, + "PrivateEndpointConnectionProvisioningState", + Azure.ResourceManager.CommonTypes.Versions.v3, + "privatelinks.json" +); + /** PrivateEndpointConnectionParameter */ @@CommonTypes.Private.armCommonParameter(PrivateEndpointConnectionParameter.name, "PrivateEndpointConnectionName", diff --git a/packages/typespec-azure-resource-manager/lib/common-types/types-ref.tsp b/packages/typespec-azure-resource-manager/lib/common-types/types-ref.tsp index 09cadfb7ba..810d1d00d4 100644 --- a/packages/typespec-azure-resource-manager/lib/common-types/types-ref.tsp +++ b/packages/typespec-azure-resource-manager/lib/common-types/types-ref.tsp @@ -280,6 +280,8 @@ namespace Azure.ResourceManager.CommonTypes; Azure.ResourceManager.CommonTypes.Versions.v5 ); +@@armCommonDefinition(SkuTier, "SkuTier", Azure.ResourceManager.CommonTypes.Versions.v3); + // -- Parameters /** ApiVersionParameter */ @@armCommonParameter(ApiVersionParameter.apiVersion, From 8ee2cd03da36f3e9b91e78396ee924347720d7a2 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 2 Jul 2024 13:37:36 -0700 Subject: [PATCH 3/6] Create arm-common-def-enum-union-2024-6-2-19-28-7.md --- .../changes/arm-common-def-enum-union-2024-6-2-19-28-7.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .chronus/changes/arm-common-def-enum-union-2024-6-2-19-28-7.md diff --git a/.chronus/changes/arm-common-def-enum-union-2024-6-2-19-28-7.md b/.chronus/changes/arm-common-def-enum-union-2024-6-2-19-28-7.md new file mode 100644 index 0000000000..1e0eb19a21 --- /dev/null +++ b/.chronus/changes/arm-common-def-enum-union-2024-6-2-19-28-7.md @@ -0,0 +1,8 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: feature +packages: + - "@azure-tools/typespec-azure-resource-manager" +--- + +Link CommonTypes enums and unions to the swagger common types From 5a0a7480284d134b5676db4e667864e515a41daa Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 2 Jul 2024 13:40:44 -0700 Subject: [PATCH 4/6] fix --- packages/typespec-autorest/src/openapi.ts | 8 +++++++- .../typespec-azure-resource-manager/src/common-types.ts | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/typespec-autorest/src/openapi.ts b/packages/typespec-autorest/src/openapi.ts index df257b3d38..d9b59387bc 100644 --- a/packages/typespec-autorest/src/openapi.ts +++ b/packages/typespec-autorest/src/openapi.ts @@ -858,7 +858,13 @@ export async function getOpenAPIForService( }; } - if (isArmCommonType(type) && (type.kind === "Model" || type.kind === "ModelProperty")) { + if ( + isArmCommonType(type) && + (type.kind === "Model" || + type.kind === "ModelProperty" || + type.kind === "Enum" || + type.kind === "Union") + ) { const ref = getArmCommonTypeOpenAPIRef(program, type, { version: context.version, service: context.service, diff --git a/packages/typespec-azure-resource-manager/src/common-types.ts b/packages/typespec-azure-resource-manager/src/common-types.ts index f0cb277c79..71e3463b9d 100644 --- a/packages/typespec-azure-resource-manager/src/common-types.ts +++ b/packages/typespec-azure-resource-manager/src/common-types.ts @@ -10,6 +10,7 @@ import { Program, Service, Type, + Union, isTypeSpecValueTypeOf, } from "@typespec/compiler"; import { $useDependency, getVersion } from "@typespec/versioning"; @@ -134,7 +135,7 @@ export function getArmCommonTypesVersion( */ export function getArmCommonTypeOpenAPIRef( program: Program, - entity: Model | ModelProperty, + entity: Model | ModelProperty | Enum | Union, params: ArmCommonTypesResolutionOptions ): string | undefined { const [record, diagnostics] = findArmCommonTypeRecord(program, entity, params); @@ -161,7 +162,7 @@ export interface ArmCommonTypesResolutionOptions { export function findArmCommonTypeRecord( program: Program, - entity: Model | ModelProperty, + entity: Model | ModelProperty | Enum | Union, params: ArmCommonTypesResolutionOptions ): [ArmCommonTypeRecord | undefined, readonly Diagnostic[]] { const { records, defaultKey } = getCommonTypeRecords(program, entity); From c2454619653a10520af73c28f9a822fd8dd79110 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 2 Jul 2024 13:51:36 -0700 Subject: [PATCH 5/6] Fix --- .../lib/common-types/managed-identity-ref.tsp | 20 +++++++++++++++++++ .../lib/common-types/private-links-ref.tsp | 18 +++++++++++++++++ .../lib/common-types/types-ref.tsp | 2 ++ .../src/common-types.ts | 2 +- 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/packages/typespec-azure-resource-manager/lib/common-types/managed-identity-ref.tsp b/packages/typespec-azure-resource-manager/lib/common-types/managed-identity-ref.tsp index 12e9962ff3..0612711d62 100644 --- a/packages/typespec-azure-resource-manager/lib/common-types/managed-identity-ref.tsp +++ b/packages/typespec-azure-resource-manager/lib/common-types/managed-identity-ref.tsp @@ -83,8 +83,28 @@ namespace Azure.ResourceManager.CommonTypes; Azure.ResourceManager.CommonTypes.Versions.v3, "managedidentity.json" ); +@@armCommonDefinition(ManagedServiceIdentityType, + "ManagedServiceIdentityType", + Azure.ResourceManager.CommonTypes.Versions.v4, + "managedidentity.json" +); +@@armCommonDefinition(ManagedServiceIdentityType, + "ManagedServiceIdentityType", + Azure.ResourceManager.CommonTypes.Versions.v5, + "managedidentity.json" +); @@armCommonDefinition(SystemAssignedServiceIdentityType, "SystemAssignedServiceIdentityType", Azure.ResourceManager.CommonTypes.Versions.v3, "managedidentity.json" ); +@@armCommonDefinition(SystemAssignedServiceIdentityType, + "SystemAssignedServiceIdentityType", + Azure.ResourceManager.CommonTypes.Versions.v4, + "managedidentity.json" +); +@@armCommonDefinition(SystemAssignedServiceIdentityType, + "SystemAssignedServiceIdentityType", + Azure.ResourceManager.CommonTypes.Versions.v5, + "managedidentity.json" +); diff --git a/packages/typespec-azure-resource-manager/lib/common-types/private-links-ref.tsp b/packages/typespec-azure-resource-manager/lib/common-types/private-links-ref.tsp index d878f0e926..5a0e0e2b69 100644 --- a/packages/typespec-azure-resource-manager/lib/common-types/private-links-ref.tsp +++ b/packages/typespec-azure-resource-manager/lib/common-types/private-links-ref.tsp @@ -141,17 +141,35 @@ namespace Azure.ResourceManager.CommonTypes; "privatelinks.json" ); +// PrivateEndpointServiceConnectionStatus @@armCommonDefinition(PrivateEndpointServiceConnectionStatus, "PrivateEndpointServiceConnectionStatus", Azure.ResourceManager.CommonTypes.Versions.v3, "privatelinks.json" ); +@@armCommonDefinition(PrivateEndpointServiceConnectionStatus, + "PrivateEndpointServiceConnectionStatus", + Azure.ResourceManager.CommonTypes.Versions.v4 +); +@@armCommonDefinition(PrivateEndpointServiceConnectionStatus, + "PrivateEndpointServiceConnectionStatus", + Azure.ResourceManager.CommonTypes.Versions.v5 +); +// PrivateEndpointServiceConnectionStatus @@armCommonDefinition(PrivateEndpointConnectionProvisioningState, "PrivateEndpointConnectionProvisioningState", Azure.ResourceManager.CommonTypes.Versions.v3, "privatelinks.json" ); +@@armCommonDefinition(PrivateEndpointConnectionProvisioningState, + "PrivateEndpointConnectionProvisioningState", + Azure.ResourceManager.CommonTypes.Versions.v4 +); +@@armCommonDefinition(PrivateEndpointConnectionProvisioningState, + "PrivateEndpointConnectionProvisioningState", + Azure.ResourceManager.CommonTypes.Versions.v5 +); /** PrivateEndpointConnectionParameter */ @@CommonTypes.Private.armCommonParameter(PrivateEndpointConnectionParameter.name, diff --git a/packages/typespec-azure-resource-manager/lib/common-types/types-ref.tsp b/packages/typespec-azure-resource-manager/lib/common-types/types-ref.tsp index 810d1d00d4..0eaa20db2d 100644 --- a/packages/typespec-azure-resource-manager/lib/common-types/types-ref.tsp +++ b/packages/typespec-azure-resource-manager/lib/common-types/types-ref.tsp @@ -281,6 +281,8 @@ namespace Azure.ResourceManager.CommonTypes; ); @@armCommonDefinition(SkuTier, "SkuTier", Azure.ResourceManager.CommonTypes.Versions.v3); +@@armCommonDefinition(SkuTier, "SkuTier", Azure.ResourceManager.CommonTypes.Versions.v4); +@@armCommonDefinition(SkuTier, "SkuTier", Azure.ResourceManager.CommonTypes.Versions.v5); // -- Parameters /** ApiVersionParameter */ diff --git a/packages/typespec-azure-resource-manager/src/common-types.ts b/packages/typespec-azure-resource-manager/src/common-types.ts index 71e3463b9d..5b0deb562d 100644 --- a/packages/typespec-azure-resource-manager/src/common-types.ts +++ b/packages/typespec-azure-resource-manager/src/common-types.ts @@ -70,7 +70,7 @@ export function getArmCommonTypesVersionFromString( */ export function isArmCommonType(entity: Type): boolean { const commonDecorators = ["$armCommonDefinition", "$armCommonParameter"]; - if (isTypeSpecValueTypeOf(entity, ["Model", "ModelProperty"])) { + if (isTypeSpecValueTypeOf(entity, ["Model", "ModelProperty", "Enum", "Union"])) { return commonDecorators.some((commonDecorator) => entity.decorators.some((d) => d.decorator.name === commonDecorator) ); From 0d3ed3beda61d529506bb49366cd6a16c455c11e Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 2 Jul 2024 13:57:46 -0700 Subject: [PATCH 6/6] Create arm-common-def-enum-union-2024-6-2-20-54-54.md --- .../arm-common-def-enum-union-2024-6-2-20-54-54.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .chronus/changes/arm-common-def-enum-union-2024-6-2-20-54-54.md diff --git a/.chronus/changes/arm-common-def-enum-union-2024-6-2-20-54-54.md b/.chronus/changes/arm-common-def-enum-union-2024-6-2-20-54-54.md new file mode 100644 index 0000000000..1a0714f5c9 --- /dev/null +++ b/.chronus/changes/arm-common-def-enum-union-2024-6-2-20-54-54.md @@ -0,0 +1,8 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: feature +packages: + - "@azure-tools/typespec-autorest" +--- + +Resolve Arm Common Definitions for enums and unions as well