diff --git a/.chronus/changes/main-2024-3-24-14-31-54.md b/.chronus/changes/main-2024-3-24-14-31-54.md new file mode 100644 index 0000000000..c62e2f2e00 --- /dev/null +++ b/.chronus/changes/main-2024-3-24-14-31-54.md @@ -0,0 +1,7 @@ +--- +changeKind: feature +packages: + - "@azure-tools/typespec-azure-resource-manager" +--- + +Adding standard ExtendedLocation definition for ARM library \ No newline at end of file diff --git a/docs/libraries/azure-resource-manager/reference/data-types.md b/docs/libraries/azure-resource-manager/reference/data-types.md index 8d17db1e8b..8fb03b15bb 100644 --- a/docs/libraries/azure-resource-manager/reference/data-types.md +++ b/docs/libraries/azure-resource-manager/reference/data-types.md @@ -493,6 +493,29 @@ model Azure.ResourceManager.ErrorResponse | ------ | ------------------------------------------------------------------------------ | ----------------- | | error? | [`ErrorDetail`](./data-types.md#Azure.ResourceManager.Foundations.ErrorDetail) | The error object. | +### `ExtendedLocationProperty` {#Azure.ResourceManager.ExtendedLocationProperty} + +The standard evenlop definition of ExtendedLocation. + +```typespec +model Azure.ResourceManager.ExtendedLocationProperty +``` + +#### Examples + +```typespec +model Employee is TrackedResource { + ...ResourceNameParameter; + ...ExtendedLocationProperty; +} +``` + +#### Properties + +| Name | Type | Description | +| ---------------- | ---------------------------------------------------------------------------------------- | ----------- | +| extendedLocation | [`ExtendedLocation`](./data-types.md#Azure.ResourceManager.Foundations.ExtendedLocation) | | + ### `ExtensionResource` {#Azure.ResourceManager.ExtensionResource} Concrete extension resource types can be created by aliasing this type using a specific property type. @@ -1305,6 +1328,21 @@ model Azure.ResourceManager.Foundations.ErrorDetail | details? | `ResourceManager.Foundations.ErrorDetail[]` | The error details. | | additionalInfo? | `ResourceManager.Foundations.ErrorAdditionalInfo[]` | The error additional info. | +### `ExtendedLocation` {#Azure.ResourceManager.Foundations.ExtendedLocation} + +The complex type of the extended location. + +```typespec +model Azure.ResourceManager.Foundations.ExtendedLocation +``` + +#### Properties + +| Name | Type | Description | +| ---- | ------------------------------------------------------------------------------------------------ | ---------------------------------- | +| name | `string` | The name of the extended location. | +| type | [`ExtendedLocationType`](./data-types.md#Azure.ResourceManager.Foundations.ExtendedLocationType) | The type of the extended location. | + ### `ExtensionBaseParameters` {#Azure.ResourceManager.Foundations.ExtensionBaseParameters} The static parameters for an extension resource @@ -1844,6 +1882,14 @@ The kind of entity that created the resource. union Azure.ResourceManager.Foundations.createdByType ``` +### `ExtendedLocationType` {#Azure.ResourceManager.Foundations.ExtendedLocationType} + +The supported ExtendedLocation types. + +```typespec +union Azure.ResourceManager.Foundations.ExtendedLocationType +``` + ### `ManagedServiceIdentityType` {#Azure.ResourceManager.Foundations.ManagedServiceIdentityType} The kind of managed identity assigned to this resource. diff --git a/docs/libraries/azure-resource-manager/reference/index.mdx b/docs/libraries/azure-resource-manager/reference/index.mdx index ca04b16744..f4594f5aad 100644 --- a/docs/libraries/azure-resource-manager/reference/index.mdx +++ b/docs/libraries/azure-resource-manager/reference/index.mdx @@ -141,6 +141,7 @@ npm install --save-peer @azure-tools/typespec-azure-resource-manager - [`EncryptionConfiguration`](./data-types.md#Azure.ResourceManager.EncryptionConfiguration) - [`EntityTag`](./data-types.md#Azure.ResourceManager.EntityTag) - [`ErrorResponse`](./data-types.md#Azure.ResourceManager.ErrorResponse) +- [`ExtendedLocationProperty`](./data-types.md#Azure.ResourceManager.ExtendedLocationProperty) - [`ExtensionResource`](./data-types.md#Azure.ResourceManager.ExtensionResource) - [`KeysOf`](./data-types.md#Azure.ResourceManager.KeysOf) - [`LocationParameter`](./data-types.md#Azure.ResourceManager.LocationParameter) @@ -197,6 +198,7 @@ npm install --save-peer @azure-tools/typespec-azure-resource-manager - [`DefaultBaseParameters`](./data-types.md#Azure.ResourceManager.Foundations.DefaultBaseParameters) - [`ErrorAdditionalInfo`](./data-types.md#Azure.ResourceManager.Foundations.ErrorAdditionalInfo) - [`ErrorDetail`](./data-types.md#Azure.ResourceManager.Foundations.ErrorDetail) +- [`ExtendedLocation`](./data-types.md#Azure.ResourceManager.Foundations.ExtendedLocation) - [`ExtensionBaseParameters`](./data-types.md#Azure.ResourceManager.Foundations.ExtensionBaseParameters) - [`ExtensionResourceBase`](./data-types.md#Azure.ResourceManager.Foundations.ExtensionResourceBase) - [`ExtensionScope`](./data-types.md#Azure.ResourceManager.Foundations.ExtensionScope) diff --git a/packages/typespec-azure-resource-manager/lib/arm.foundations.tsp b/packages/typespec-azure-resource-manager/lib/arm.foundations.tsp index fc145cee3f..34194e769c 100644 --- a/packages/typespec-azure-resource-manager/lib/arm.foundations.tsp +++ b/packages/typespec-azure-resource-manager/lib/arm.foundations.tsp @@ -5,76 +5,6 @@ using Azure.ResourceManager.Private; namespace Azure.ResourceManager.Foundations; -/** - * A list of REST API operations supported by an Azure Resource Provider. It contains an URL link to get the next set of results. - */ -@armCommonDefinition("OperationListResult", Azure.ResourceManager.CommonTypes.Versions.v3) -@armCommonDefinition("OperationListResult", Azure.ResourceManager.CommonTypes.Versions.v4) -@armCommonDefinition("OperationListResult", Azure.ResourceManager.CommonTypes.Versions.v5) -@doc(""" -A list of REST API operations supported by an Azure Resource Provider. It contains an URL link to get the next set of results. -""") -model OperationListResult is Azure.Core.Page; - -/** - * Base model that defines common properties for all Azure Resource Manager resources. - */ -@doc("Common properties for all Azure Resource Manager resources.") -model ArmResource extends ArmResourceBase { - @doc("Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}") - @visibility("read") - id: string; - - @doc("The name of the resource") - @visibility("read") - name: string; - - @doc("The type of the resource. E.g. \"Microsoft.Compute/virtualMachines\" or \"Microsoft.Storage/storageAccounts\"") - @visibility("read") - type: string; - - @doc("Azure Resource Manager metadata containing createdBy and modifiedBy information.") - @visibility("read") - systemData?: SystemData; -} - -/** Base class used for type definitions */ -model ArmResourceBase {} - -/** - * The base tracked resource. - */ -@armCommonDefinition("TrackedResource", Azure.ResourceManager.CommonTypes.Versions.v3) -@armCommonDefinition("TrackedResource", Azure.ResourceManager.CommonTypes.Versions.v4) -@armCommonDefinition("TrackedResource", Azure.ResourceManager.CommonTypes.Versions.v5) -@doc("The resource model definition for an Azure Resource Manager tracked top level resource") -model TrackedResourceBase extends ArmResource { - @doc("The geo-location where the resource lives") - @visibility("read", "create") - location: string; - - ...ArmTagsProperty; -} - -/** - * The base proxy resource. - */ -@doc("The base proxy resource.") -@armCommonDefinition("ProxyResource", Azure.ResourceManager.CommonTypes.Versions.v3) -@armCommonDefinition("ProxyResource", Azure.ResourceManager.CommonTypes.Versions.v4) -@armCommonDefinition("ProxyResource", Azure.ResourceManager.CommonTypes.Versions.v5) -model ProxyResourceBase extends ArmResource {} - -/** - * The base extension resource. - */ -// Note that ProxyResource is the base definition for both kinds of resources -@doc("The base extension resource.") -@armCommonDefinition("ProxyResource", Azure.ResourceManager.CommonTypes.Versions.v3) -@armCommonDefinition("ProxyResource", Azure.ResourceManager.CommonTypes.Versions.v4) -@armCommonDefinition("ProxyResource", Azure.ResourceManager.CommonTypes.Versions.v5) -model ExtensionResourceBase extends ArmResource {} - /** * An internal enum to indicate the resource support for various path types */ @@ -95,131 +25,6 @@ enum ResourceHome { Extension, } -/** - * The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value is "user,system" - */ -@doc(""" -The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value is "user,system" -""") -union Origin { - @doc("Indicates the operation is initiated by a user.") - user: "user", - - @doc("Indicates the operation is initiated by a system.") - system: "system", - - @doc("Indicates the operation is initiated by a user or system.") - `user,system`: "user,system", - - string, -} - -/** - * Extensible enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. - */ -@doc(""" -Extensible enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. -""") -union ActionType { - @doc("Actions are for internal-only APIs.") - Internal: "Internal", - - string, -} - -/** - * Localized display information for and operation. - */ -@armCommonDefinition("OperationDisplay", Azure.ResourceManager.CommonTypes.Versions.v3) -@armCommonDefinition("OperationDisplay", Azure.ResourceManager.CommonTypes.Versions.v4) -@armCommonDefinition("OperationDisplay", Azure.ResourceManager.CommonTypes.Versions.v5) -@doc("Localized display information for and operation.") -model OperationDisplay { - @doc(""" - The localized friendly form of the resource provider name, e.g. "Microsoft Monitoring Insights" or "Microsoft Compute". - """) - provider?: string; - - @doc(""" - The localized friendly name of the resource type related to this operation. E.g. "Virtual Machines" or "Job Schedule Collections". - """) - resource?: string; - - @doc(""" - The concise, localized friendly name for the operation; suitable for dropdowns. E.g. "Create or Update Virtual Machine", "Restart Virtual Machine". - """) - operation?: string; - - @doc("The short, localized friendly description of the operation; suitable for tool tips and detailed views.") - description?: string; -} - -/** - * The current status of an async operation. - */ -@armCommonDefinition("OperationStatusResult", Azure.ResourceManager.CommonTypes.Versions.v3) -@armCommonDefinition("OperationStatusResult", Azure.ResourceManager.CommonTypes.Versions.v4) -@armCommonDefinition("OperationStatusResult", Azure.ResourceManager.CommonTypes.Versions.v5) -@doc("The current status of an async operation.") -model OperationStatusResult { - @doc("Fully qualified ID for the async operation.") - id?: string; - - @doc("Name of the async operation.") - name?: string; - - @doc("Operation status.") - status: string; - - @doc("Percent of the operation that is complete.") - @minValue(0) - @maxValue(100) - percentComplete?: int32; - - @doc("The start time of the operation.") - startTime?: utcDateTime; - - @doc("The end time of the operation.") - endTime?: utcDateTime; - - @doc("The operations list.") - operations: OperationStatusResult[]; - - @doc("If present, details of the operation error.") - error?: ErrorDetail; -} - -/** - * The error detail. - */ -@armCommonDefinition("ErrorDetail", Azure.ResourceManager.CommonTypes.Versions.v3) -@armCommonDefinition("ErrorDetail", Azure.ResourceManager.CommonTypes.Versions.v4) -@armCommonDefinition("ErrorDetail", Azure.ResourceManager.CommonTypes.Versions.v5) -@doc("The error detail.") -model ErrorDetail { - @doc("The error code.") - @visibility("read") - code?: string; - - @doc("The error message.") - @visibility("read") - message?: string; - - @doc("The error target.") - @visibility("read") - target?: string; - - @extension("x-ms-identifiers", ["message", "target"]) - @doc("The error details.") - @visibility("read") - details?: ErrorDetail[]; - - @extension("x-ms-identifiers", ["message", "target"]) - @doc("The error additional info.") - @visibility("read") - additionalInfo?: ErrorAdditionalInfo[]; -} - /** * Base parameters for a resource. * @@ -283,203 +88,6 @@ model ExtensionBaseParameters is TenantBaseParameters { ...ResourceUriParameter; } -/** - * The resource management error additional info. - */ -@armCommonDefinition("ErrorAdditionalInfo", Azure.ResourceManager.CommonTypes.Versions.v3) -@armCommonDefinition("ErrorAdditionalInfo", Azure.ResourceManager.CommonTypes.Versions.v4) -@armCommonDefinition("ErrorAdditionalInfo", Azure.ResourceManager.CommonTypes.Versions.v5) -@doc("The resource management error additional info.") -model ErrorAdditionalInfo { - @doc("The additional info type.") - @visibility("read") - type?: string; - - @doc("The additional info.") - @visibility("read") - info?: {}; -} - -/** - * Standard type definition for Azure Resource Manager Tags property. - * - * It is included in the TrackedResource template definition. - */ -@doc("The Azure Resource Manager Resource tags.") -model ArmTagsProperty { - @doc("Resource tags.") - tags?: Record; -} - -/** - * The kind of entity that created the resource. - */ -// NOTE: This is how the extensible enum is named in types.json -@doc("The kind of entity that created the resource.") -union createdByType { - @doc("The entity was created by a user.") - User: "User", - - @doc("The entity was created by an application.") - Application: "Application", - - @doc("The entity was created by a managed identity.") - ManagedIdentity: "ManagedIdentity", - - @doc("The entity was created by a key.") - Key: "Key", - - string, -} - -/** - * Metadata pertaining to creation and last modification of the resource. - */ -@armCommonDefinition("systemData", Azure.ResourceManager.CommonTypes.Versions.v3) -@armCommonDefinition("systemData", Azure.ResourceManager.CommonTypes.Versions.v4) -@armCommonDefinition("systemData", Azure.ResourceManager.CommonTypes.Versions.v5) -@doc("Metadata pertaining to creation and last modification of the resource.") -model SystemData { - @visibility("read") - @doc("The identity that created the resource.") - createdBy?: string; - - @visibility("read") - @doc("The type of identity that created the resource.") - createdByType?: createdByType; - - @visibility("read") - @doc("The type of identity that created the resource.") - createdAt?: plainDate; - - @visibility("read") - @doc("The identity that last modified the resource.") - lastModifiedBy?: string; - - @visibility("read") - @doc("The type of identity that last modified the resource.") - lastModifiedByType?: createdByType; - - @visibility("read") - @doc("The timestamp of resource last modification (UTC)") - lastModifiedAt?: plainDate; -} - -/** - * The properties of the managed service identities assigned to this resource. - */ -@armCommonDefinition( - "ManagedServiceIdentity", - { - version: Azure.ResourceManager.CommonTypes.Versions.v4, - isDefault: true, - }, - "managedidentity.json" -) -@armCommonDefinition( - "ManagedServiceIdentity", - Azure.ResourceManager.CommonTypes.Versions.v5, - "managedidentity.json" -) -@doc("The properties of the managed service identities assigned to this resource.") -model ManagedIdentityProperties { - @doc("The Active Directory tenant id of the principal.") - @visibility("read") - tenantId?: string; - - @doc("The active directory identifier of this principal.") - @visibility("read") - principalId?: string; - - @doc("The type of managed identity assigned to this resource.") - type: ManagedServiceIdentityType; - - @doc("The identities assigned to this resource by the user.") - userAssignedIdentities?: Record; -} - -/** - * The properties of the service-assigned identity associated with this resource. - */ -@armCommonDefinition( - "SystemAssignedServiceIdentity", - { - version: Azure.ResourceManager.CommonTypes.Versions.v4, - isDefault: true, - }, - "managedidentity.json" -) -@armCommonDefinition( - "SystemAssignedServiceIdentity", - Azure.ResourceManager.CommonTypes.Versions.v5, - "managedidentity.json" -) -@doc("The properties of the service-assigned identity associated with this resource.") -model ManagedSystemIdentityProperties { - @doc("The Active Directory tenant id of the principal.") - @visibility("read") - tenantId?: string; - - @doc("The active directory identifier of this principal.") - @visibility("read") - principalId?: string; - - @doc("The type of managed identity assigned to this resource.") - type: SystemAssignedServiceIdentityType; -} - -/** Alias of ManagedServiceIdentityType for back compatability. Please change to ManagedServiceIdentityType. */ -#deprecated "Please change to ManagedServiceIdentityType." -alias ManagedIdentityType = ManagedServiceIdentityType; -/** - * A managed identity assigned by the user. - */ -@doc("A managed identity assigned by the user.") -model UserAssignedIdentity { - @doc("The active directory client identifier for this principal.") - clientId?: string; - - @doc("The active directory identifier for this principal.") - principalId?: string; -} - -/** - * The kind of managed identity assigned to this resource. - */ -@doc("The kind of managed identity assigned to this resource.") -union ManagedServiceIdentityType { - @doc("No managed identity.") - None: "None", - - @doc("System assigned managed identity.") - SystemAssigned: "SystemAssigned", - - @doc("User assigned managed identity.") - UserAssigned: "UserAssigned", - - @doc("System and user assigned managed identity.") - SystemAndUserAssigned: "SystemAssigned, UserAssigned", - - string, -} - -/** Alias of SystemAssignedServiceIdentityType for back compatability. Please change to SystemAssignedServiceIdentityType. */ -alias ManagedSystemIdentityType = SystemAssignedServiceIdentityType; - -/** - * The kind of managemed identity assigned to this resource. - */ -@doc("The kind of managemed identity assigned to this resource.") -union SystemAssignedServiceIdentityType { - @doc("No managed system identity.") - None: "None", - - @doc("System assigned managed system identity.") - SystemAssigned: "SystemAssigned", - - string, -} - /** * Defines a properties type used to create named resource update models. * This type is not used directly, it is referenced by ResourceUpdateModel. @@ -558,72 +166,6 @@ model ExtensionScope */ model ResourceGroupScope is ResourceParentParameters; -/** - * Details of the resource plan. - */ -@doc("Details of the resource plan.") -@armCommonDefinition("Plan", Azure.ResourceManager.CommonTypes.Versions.v3) -@armCommonDefinition("Plan", Azure.ResourceManager.CommonTypes.Versions.v4) -@armCommonDefinition("Plan", Azure.ResourceManager.CommonTypes.Versions.v5) -model ResourcePlanType { - @doc("A user defined name of the 3rd Party Artifact that is being procured.") - name: string; - - @doc("The publisher of the 3rd Party Artifact that is being bought. E.g. NewRelic") - publisher: string; - - @doc("The 3rd Party artifact that is being procured. E.g. NewRelic. Product maps to the OfferID specified for the artifact at the time of Data Market onboarding. ") - product: string; - - @doc("A publisher provided promotion code as provisioned in Data Market for the said product/artifact.") - promotionCode?: string; - - @doc("The version of the desired product/artifact.") - version?: string; -} - -/** - * The SKU (Stock Keeping Unit) assigned to this resource. - */ -@doc("The SKU (Stock Keeping Unit) assigned to this resource.") -@armCommonDefinition("Sku", Azure.ResourceManager.CommonTypes.Versions.v3) -@armCommonDefinition("Sku", Azure.ResourceManager.CommonTypes.Versions.v4) -@armCommonDefinition("Sku", Azure.ResourceManager.CommonTypes.Versions.v5) -model ResourceSkuType { - @doc("The name of the SKU, usually a combination of letters and numbers, for example, 'P3'") - name: string; - - @doc("This field is required to be implemented by the Resource Provider if the service has more than one tier, but is not required on a PUT.") - tier?: SkuTier; - - @doc("The SKU size. When the name field is the combination of tier and some other value, this would be the standalone code.") - size?: string; - - @doc("If the service has different generations of hardware, for the same SKU, then that can be captured here.") - family?: string; - - @doc("If the SKU supports scale out/in then the capacity integer should be included. If scale out/in is not possible for the resource this may be omitted.") - capacity?: int32; -} - -/** - * Available service tiers for the SKU. - */ -@doc("Available service tiers for the SKU.") -enum SkuTier { - @doc("The Free service tier.") - Free, - - @doc("The Basic service tier.") - Basic, - - @doc("The Standard service tier.") - Standard, - - @doc("The Premium service tier.") - Premium, -} - /** * The type used for update operations of the resource. * @template Resource The type of the resource. @@ -639,102 +181,6 @@ model ProxyResourceUpdateModel< properties?: ResourceUpdateModelProperties; } -/** - * Details of a REST API operation, returned from the Resource Provider Operations API - */ -@armCommonDefinition("Operation", Azure.ResourceManager.CommonTypes.Versions.v3) -@armCommonDefinition("Operation", Azure.ResourceManager.CommonTypes.Versions.v4) -@armCommonDefinition("Operation", Azure.ResourceManager.CommonTypes.Versions.v5) -@doc("Details of a REST API operation, returned from the Resource Provider Operations API") -model Operation { - @doc(""" - The name of the operation, as per Resource-Based Access Control (RBAC). Examples: "Microsoft.Compute/virtualMachines/write", "Microsoft.Compute/virtualMachines/capture/action" - """) - @visibility("read") - name?: string; - - @doc(""" - Whether the operation applies to data-plane. This is "true" for data-plane operations and "false" for Azure Resource Manager/control-plane operations. - """) - @visibility("read") - isDataAction?: boolean; - - @doc("Localized display information for this particular operation.") - display?: OperationDisplay; - - @doc(""" - The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value is "user,system" - """) - @visibility("read") - origin?: Origin; - - @doc(""" - Extensible enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. - """) - actionType?: ActionType; -} - -/** - * The default operationId parameter type. - */ -@doc("The default operationId parameter type.") -model OperationIdParameter { - @path - @minLength(1) - @doc("The ID of an ongoing async operation.") - @armCommonParameter("OperationIdParameter", Azure.ResourceManager.CommonTypes.Versions.v3) - @armCommonParameter("OperationIdParameter", Azure.ResourceManager.CommonTypes.Versions.v4) - @armCommonParameter("OperationIdParameter", Azure.ResourceManager.CommonTypes.Versions.v5) - operationId: string; -} - -/** - * The check availability request body. - */ -@armCommonDefinition("CheckNameAvailabilityRequest", Azure.ResourceManager.CommonTypes.Versions.v3) -@armCommonDefinition("CheckNameAvailabilityRequest", Azure.ResourceManager.CommonTypes.Versions.v4) -@armCommonDefinition("CheckNameAvailabilityRequest", Azure.ResourceManager.CommonTypes.Versions.v5) -@doc("The check availability request body.") -model CheckNameAvailabilityRequest { - @doc("The name of the resource for which availability needs to be checked.") - name?: string; - - @doc("The resource type.") - type?: string; -} - -/** - * Possible reasons for a name not being available. - */ -@doc("Possible reasons for a name not being available.") -union CheckNameAvailabilityReason { - @doc("Name is invalid.") - Invalid: "Invalid", - - @doc("Name already exists.") - AlreadyExists: "AlreadyExists", - - string, -} - -/** - * The check availability result. - */ -@armCommonDefinition("CheckNameAvailabilityResponse", Azure.ResourceManager.CommonTypes.Versions.v3) -@armCommonDefinition("CheckNameAvailabilityResponse", Azure.ResourceManager.CommonTypes.Versions.v4) -@armCommonDefinition("CheckNameAvailabilityResponse", Azure.ResourceManager.CommonTypes.Versions.v5) -@doc("The check availability result.") -model CheckNameAvailabilityResponse { - @doc("Indicates if the resource name is available.") - nameAvailable?: boolean; - - @doc("The reason why the given name is not available.") - reason?: CheckNameAvailabilityReason; - - @doc("Detailed reason why the given name is not available.") - message?: string; -} - alias DefaultProviderNamespace = { @path @TypeSpec.Rest.segment("providers") diff --git a/packages/typespec-azure-resource-manager/lib/arm.tsp b/packages/typespec-azure-resource-manager/lib/arm.tsp index 4f4af70229..c45950c8cc 100644 --- a/packages/typespec-azure-resource-manager/lib/arm.tsp +++ b/packages/typespec-azure-resource-manager/lib/arm.tsp @@ -7,7 +7,12 @@ import "@azure-tools/typespec-autorest"; import "@azure-tools/typespec-azure-core"; import "./arm.foundations.tsp"; -import "./common-types.tsp"; +import "./common-types/common-types.tsp"; +import "./common-types/types.tsp"; +import "./common-types/managed-identity.tsp"; +import "./common-types/private-links.tsp"; +import "./common-types/customer-managed-keys.tsp"; +import "./common-types/extended-location.tsp"; import "./private.decorators.tsp"; import "./models.tsp"; import "./operations.tsp"; @@ -15,8 +20,6 @@ import "./decorators.tsp"; import "./interfaces.tsp"; import "./responses.tsp"; import "./parameters.tsp"; -import "./private-links.tsp"; -import "./customer-managed-keys.tsp"; using TypeSpec.Http; using TypeSpec.Rest; diff --git a/packages/typespec-azure-resource-manager/lib/common-types.tsp b/packages/typespec-azure-resource-manager/lib/common-types/common-types.tsp similarity index 100% rename from packages/typespec-azure-resource-manager/lib/common-types.tsp rename to packages/typespec-azure-resource-manager/lib/common-types/common-types.tsp diff --git a/packages/typespec-azure-resource-manager/lib/customer-managed-keys.tsp b/packages/typespec-azure-resource-manager/lib/common-types/customer-managed-keys.tsp similarity index 100% rename from packages/typespec-azure-resource-manager/lib/customer-managed-keys.tsp rename to packages/typespec-azure-resource-manager/lib/common-types/customer-managed-keys.tsp diff --git a/packages/typespec-azure-resource-manager/lib/common-types/extended-location.tsp b/packages/typespec-azure-resource-manager/lib/common-types/extended-location.tsp new file mode 100644 index 0000000000..c9a7a398d8 --- /dev/null +++ b/packages/typespec-azure-resource-manager/lib/common-types/extended-location.tsp @@ -0,0 +1,21 @@ +namespace Azure.ResourceManager.Foundations { + /** The complex type of the extended location. */ + model ExtendedLocation { + /** The name of the extended location. */ + name: string; + + /** The type of the extended location. */ + type: ExtendedLocationType; + } + + /** The supported ExtendedLocation types. */ + union ExtendedLocationType { + /** Azure Edge Zones location type */ + EdgeZone: "EdgeZone", + + /** Azure Custom Locations type */ + CustomLocation: "CustomLocation", + + string, + } +} diff --git a/packages/typespec-azure-resource-manager/lib/common-types/managed-identity.tsp b/packages/typespec-azure-resource-manager/lib/common-types/managed-identity.tsp new file mode 100644 index 0000000000..7588e3f1d0 --- /dev/null +++ b/packages/typespec-azure-resource-manager/lib/common-types/managed-identity.tsp @@ -0,0 +1,118 @@ +using Azure.ResourceManager.Private; + +namespace Azure.ResourceManager.Foundations; + +/** + * The properties of the managed service identities assigned to this resource. + */ +@armCommonDefinition( + "ManagedServiceIdentity", + { + version: Azure.ResourceManager.CommonTypes.Versions.v4, + isDefault: true, + }, + "managedidentity.json" +) +@armCommonDefinition( + "ManagedServiceIdentity", + Azure.ResourceManager.CommonTypes.Versions.v5, + "managedidentity.json" +) +@doc("The properties of the managed service identities assigned to this resource.") +model ManagedIdentityProperties { + @doc("The Active Directory tenant id of the principal.") + @visibility("read") + tenantId?: string; + + @doc("The active directory identifier of this principal.") + @visibility("read") + principalId?: string; + + @doc("The type of managed identity assigned to this resource.") + type: ManagedServiceIdentityType; + + @doc("The identities assigned to this resource by the user.") + userAssignedIdentities?: Record; +} + +/** + * The properties of the service-assigned identity associated with this resource. + */ +@armCommonDefinition( + "SystemAssignedServiceIdentity", + { + version: Azure.ResourceManager.CommonTypes.Versions.v4, + isDefault: true, + }, + "managedidentity.json" +) +@armCommonDefinition( + "SystemAssignedServiceIdentity", + Azure.ResourceManager.CommonTypes.Versions.v5, + "managedidentity.json" +) +@doc("The properties of the service-assigned identity associated with this resource.") +model ManagedSystemIdentityProperties { + @doc("The Active Directory tenant id of the principal.") + @visibility("read") + tenantId?: string; + + @doc("The active directory identifier of this principal.") + @visibility("read") + principalId?: string; + + @doc("The type of managed identity assigned to this resource.") + type: SystemAssignedServiceIdentityType; +} + +/** Alias of ManagedServiceIdentityType for back compatability. Please change to ManagedServiceIdentityType. */ +#deprecated "Please change to ManagedServiceIdentityType." +alias ManagedIdentityType = ManagedServiceIdentityType; +/** + * A managed identity assigned by the user. + */ +@doc("A managed identity assigned by the user.") +model UserAssignedIdentity { + @doc("The active directory client identifier for this principal.") + clientId?: string; + + @doc("The active directory identifier for this principal.") + principalId?: string; +} + +/** + * The kind of managed identity assigned to this resource. + */ +@doc("The kind of managed identity assigned to this resource.") +union ManagedServiceIdentityType { + @doc("No managed identity.") + None: "None", + + @doc("System assigned managed identity.") + SystemAssigned: "SystemAssigned", + + @doc("User assigned managed identity.") + UserAssigned: "UserAssigned", + + @doc("System and user assigned managed identity.") + SystemAndUserAssigned: "SystemAssigned, UserAssigned", + + string, +} + +/** Alias of SystemAssignedServiceIdentityType for back compatability. Please change to SystemAssignedServiceIdentityType. */ +alias ManagedSystemIdentityType = SystemAssignedServiceIdentityType; + +/** + * The kind of managemed identity assigned to this resource. + */ +@doc("The kind of managemed identity assigned to this resource.") +union SystemAssignedServiceIdentityType { + @doc("No managed system identity.") + None: "None", + + @doc("System assigned managed system identity.") + SystemAssigned: "SystemAssigned", + + string, +} diff --git a/packages/typespec-azure-resource-manager/lib/private-links.tsp b/packages/typespec-azure-resource-manager/lib/common-types/private-links.tsp similarity index 100% rename from packages/typespec-azure-resource-manager/lib/private-links.tsp rename to packages/typespec-azure-resource-manager/lib/common-types/private-links.tsp diff --git a/packages/typespec-azure-resource-manager/lib/common-types/types.tsp b/packages/typespec-azure-resource-manager/lib/common-types/types.tsp new file mode 100644 index 0000000000..7960176322 --- /dev/null +++ b/packages/typespec-azure-resource-manager/lib/common-types/types.tsp @@ -0,0 +1,444 @@ +using TypeSpec.Http; +using TypeSpec.OpenAPI; +using Azure.ResourceManager.Private; + +namespace Azure.ResourceManager.Foundations; + +/** Base class used for type definitions */ +model ArmResourceBase {} + +/** + * Base model that defines common properties for all Azure Resource Manager resources. + */ +@doc("Common properties for all Azure Resource Manager resources.") +model ArmResource extends ArmResourceBase { + @doc("Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}") + @visibility("read") + id: string; + + @doc("The name of the resource") + @visibility("read") + name: string; + + @doc("The type of the resource. E.g. \"Microsoft.Compute/virtualMachines\" or \"Microsoft.Storage/storageAccounts\"") + @visibility("read") + type: string; + + @doc("Azure Resource Manager metadata containing createdBy and modifiedBy information.") + @visibility("read") + systemData?: SystemData; +} + +/** + * Standard type definition for Azure Resource Manager Tags property. + * + * It is included in the TrackedResource template definition. + */ +@doc("The Azure Resource Manager Resource tags.") +model ArmTagsProperty { + @doc("Resource tags.") + tags?: Record; +} + +/** + * The base tracked resource. + */ +@armCommonDefinition("TrackedResource", Azure.ResourceManager.CommonTypes.Versions.v3) +@armCommonDefinition("TrackedResource", Azure.ResourceManager.CommonTypes.Versions.v4) +@armCommonDefinition("TrackedResource", Azure.ResourceManager.CommonTypes.Versions.v5) +@doc("The resource model definition for an Azure Resource Manager tracked top level resource") +model TrackedResourceBase extends ArmResource { + @doc("The geo-location where the resource lives") + @visibility("read", "create") + location: string; + + ...ArmTagsProperty; +} + +/** + * The base proxy resource. + */ +@doc("The base proxy resource.") +@armCommonDefinition("ProxyResource", Azure.ResourceManager.CommonTypes.Versions.v3) +@armCommonDefinition("ProxyResource", Azure.ResourceManager.CommonTypes.Versions.v4) +@armCommonDefinition("ProxyResource", Azure.ResourceManager.CommonTypes.Versions.v5) +model ProxyResourceBase extends ArmResource {} + +/** + * The base extension resource. + */ +// Note that ProxyResource is the base definition for both kinds of resources +@doc("The base extension resource.") +@armCommonDefinition("ProxyResource", Azure.ResourceManager.CommonTypes.Versions.v3) +@armCommonDefinition("ProxyResource", Azure.ResourceManager.CommonTypes.Versions.v4) +@armCommonDefinition("ProxyResource", Azure.ResourceManager.CommonTypes.Versions.v5) +model ExtensionResourceBase extends ArmResource {} + +/** + * The SKU (Stock Keeping Unit) assigned to this resource. + */ +@doc("The SKU (Stock Keeping Unit) assigned to this resource.") +@armCommonDefinition("Sku", Azure.ResourceManager.CommonTypes.Versions.v3) +@armCommonDefinition("Sku", Azure.ResourceManager.CommonTypes.Versions.v4) +@armCommonDefinition("Sku", Azure.ResourceManager.CommonTypes.Versions.v5) +model ResourceSkuType { + @doc("The name of the SKU, usually a combination of letters and numbers, for example, 'P3'") + name: string; + + @doc("This field is required to be implemented by the Resource Provider if the service has more than one tier, but is not required on a PUT.") + tier?: SkuTier; + + @doc("The SKU size. When the name field is the combination of tier and some other value, this would be the standalone code.") + size?: string; + + @doc("If the service has different generations of hardware, for the same SKU, then that can be captured here.") + family?: string; + + @doc("If the SKU supports scale out/in then the capacity integer should be included. If scale out/in is not possible for the resource this may be omitted.") + capacity?: int32; +} + +/** + * Available service tiers for the SKU. + */ +@doc("Available service tiers for the SKU.") +enum SkuTier { + @doc("The Free service tier.") + Free, + + @doc("The Basic service tier.") + Basic, + + @doc("The Standard service tier.") + Standard, + + @doc("The Premium service tier.") + Premium, +} + +/** + * A list of REST API operations supported by an Azure Resource Provider. It contains an URL link to get the next set of results. + */ +@armCommonDefinition("OperationListResult", Azure.ResourceManager.CommonTypes.Versions.v3) +@armCommonDefinition("OperationListResult", Azure.ResourceManager.CommonTypes.Versions.v4) +@armCommonDefinition("OperationListResult", Azure.ResourceManager.CommonTypes.Versions.v5) +@doc(""" +A list of REST API operations supported by an Azure Resource Provider. It contains an URL link to get the next set of results. +""") +model OperationListResult is Azure.Core.Page; + +/** + * Details of a REST API operation, returned from the Resource Provider Operations API + */ +@armCommonDefinition("Operation", Azure.ResourceManager.CommonTypes.Versions.v3) +@armCommonDefinition("Operation", Azure.ResourceManager.CommonTypes.Versions.v4) +@armCommonDefinition("Operation", Azure.ResourceManager.CommonTypes.Versions.v5) +@doc("Details of a REST API operation, returned from the Resource Provider Operations API") +model Operation { + @doc(""" + The name of the operation, as per Resource-Based Access Control (RBAC). Examples: "Microsoft.Compute/virtualMachines/write", "Microsoft.Compute/virtualMachines/capture/action" + """) + @visibility("read") + name?: string; + + @doc(""" + Whether the operation applies to data-plane. This is "true" for data-plane operations and "false" for Azure Resource Manager/control-plane operations. + """) + @visibility("read") + isDataAction?: boolean; + + @doc("Localized display information for this particular operation.") + display?: OperationDisplay; + + @doc(""" + The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value is "user,system" + """) + @visibility("read") + origin?: Origin; + + @doc(""" + Extensible enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. + """) + actionType?: ActionType; +} + +/** + * Localized display information for and operation. + */ +@armCommonDefinition("OperationDisplay", Azure.ResourceManager.CommonTypes.Versions.v3) +@armCommonDefinition("OperationDisplay", Azure.ResourceManager.CommonTypes.Versions.v4) +@armCommonDefinition("OperationDisplay", Azure.ResourceManager.CommonTypes.Versions.v5) +@doc("Localized display information for and operation.") +model OperationDisplay { + @doc(""" + The localized friendly form of the resource provider name, e.g. "Microsoft Monitoring Insights" or "Microsoft Compute". + """) + provider?: string; + + @doc(""" + The localized friendly name of the resource type related to this operation. E.g. "Virtual Machines" or "Job Schedule Collections". + """) + resource?: string; + + @doc(""" + The concise, localized friendly name for the operation; suitable for dropdowns. E.g. "Create or Update Virtual Machine", "Restart Virtual Machine". + """) + operation?: string; + + @doc("The short, localized friendly description of the operation; suitable for tool tips and detailed views.") + description?: string; +} + +/** + * The current status of an async operation. + */ +@armCommonDefinition("OperationStatusResult", Azure.ResourceManager.CommonTypes.Versions.v3) +@armCommonDefinition("OperationStatusResult", Azure.ResourceManager.CommonTypes.Versions.v4) +@armCommonDefinition("OperationStatusResult", Azure.ResourceManager.CommonTypes.Versions.v5) +@doc("The current status of an async operation.") +model OperationStatusResult { + @doc("Fully qualified ID for the async operation.") + id?: string; + + @doc("Name of the async operation.") + name?: string; + + @doc("Operation status.") + status: string; + + @doc("Percent of the operation that is complete.") + @minValue(0) + @maxValue(100) + percentComplete?: int32; + + @doc("The start time of the operation.") + startTime?: utcDateTime; + + @doc("The end time of the operation.") + endTime?: utcDateTime; + + @doc("The operations list.") + operations: OperationStatusResult[]; + + @doc("If present, details of the operation error.") + error?: ErrorDetail; +} + +/** + * The default operationId parameter type. + */ +@doc("The default operationId parameter type.") +model OperationIdParameter { + @path + @minLength(1) + @doc("The ID of an ongoing async operation.") + @armCommonParameter("OperationIdParameter", Azure.ResourceManager.CommonTypes.Versions.v3) + @armCommonParameter("OperationIdParameter", Azure.ResourceManager.CommonTypes.Versions.v4) + @armCommonParameter("OperationIdParameter", Azure.ResourceManager.CommonTypes.Versions.v5) + operationId: string; +} + +/** + * Extensible enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. + */ +@doc(""" +Extensible enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. +""") +union ActionType { + @doc("Actions are for internal-only APIs.") + Internal: "Internal", + + string, +} + +/** + * The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value is "user,system" + */ +@doc(""" +The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value is "user,system" +""") +union Origin { + @doc("Indicates the operation is initiated by a user.") + user: "user", + + @doc("Indicates the operation is initiated by a system.") + system: "system", + + @doc("Indicates the operation is initiated by a user or system.") + `user,system`: "user,system", + + string, +} + +/** + * The error detail. + */ +@armCommonDefinition("ErrorDetail", Azure.ResourceManager.CommonTypes.Versions.v3) +@armCommonDefinition("ErrorDetail", Azure.ResourceManager.CommonTypes.Versions.v4) +@armCommonDefinition("ErrorDetail", Azure.ResourceManager.CommonTypes.Versions.v5) +@doc("The error detail.") +model ErrorDetail { + @doc("The error code.") + @visibility("read") + code?: string; + + @doc("The error message.") + @visibility("read") + message?: string; + + @doc("The error target.") + @visibility("read") + target?: string; + + @extension("x-ms-identifiers", ["message", "target"]) + @doc("The error details.") + @visibility("read") + details?: ErrorDetail[]; + + @extension("x-ms-identifiers", ["message", "target"]) + @doc("The error additional info.") + @visibility("read") + additionalInfo?: ErrorAdditionalInfo[]; +} + +/** + * The resource management error additional info. + */ +@armCommonDefinition("ErrorAdditionalInfo", Azure.ResourceManager.CommonTypes.Versions.v3) +@armCommonDefinition("ErrorAdditionalInfo", Azure.ResourceManager.CommonTypes.Versions.v4) +@armCommonDefinition("ErrorAdditionalInfo", Azure.ResourceManager.CommonTypes.Versions.v5) +@doc("The resource management error additional info.") +model ErrorAdditionalInfo { + @doc("The additional info type.") + @visibility("read") + type?: string; + + @doc("The additional info.") + @visibility("read") + info?: {}; +} + +/** + * Metadata pertaining to creation and last modification of the resource. + */ +@armCommonDefinition("systemData", Azure.ResourceManager.CommonTypes.Versions.v3) +@armCommonDefinition("systemData", Azure.ResourceManager.CommonTypes.Versions.v4) +@armCommonDefinition("systemData", Azure.ResourceManager.CommonTypes.Versions.v5) +@doc("Metadata pertaining to creation and last modification of the resource.") +model SystemData { + @visibility("read") + @doc("The identity that created the resource.") + createdBy?: string; + + @visibility("read") + @doc("The type of identity that created the resource.") + createdByType?: createdByType; + + @visibility("read") + @doc("The type of identity that created the resource.") + createdAt?: plainDate; + + @visibility("read") + @doc("The identity that last modified the resource.") + lastModifiedBy?: string; + + @visibility("read") + @doc("The type of identity that last modified the resource.") + lastModifiedByType?: createdByType; + + @visibility("read") + @doc("The timestamp of resource last modification (UTC)") + lastModifiedAt?: plainDate; +} + +/** + * The kind of entity that created the resource. + */ +// NOTE: This is how the extensible enum is named in types.json +@doc("The kind of entity that created the resource.") +union createdByType { + @doc("The entity was created by a user.") + User: "User", + + @doc("The entity was created by an application.") + Application: "Application", + + @doc("The entity was created by a managed identity.") + ManagedIdentity: "ManagedIdentity", + + @doc("The entity was created by a key.") + Key: "Key", + + string, +} + +/** + * Details of the resource plan. + */ +@doc("Details of the resource plan.") +@armCommonDefinition("Plan", Azure.ResourceManager.CommonTypes.Versions.v3) +@armCommonDefinition("Plan", Azure.ResourceManager.CommonTypes.Versions.v4) +@armCommonDefinition("Plan", Azure.ResourceManager.CommonTypes.Versions.v5) +model ResourcePlanType { + @doc("A user defined name of the 3rd Party Artifact that is being procured.") + name: string; + + @doc("The publisher of the 3rd Party Artifact that is being bought. E.g. NewRelic") + publisher: string; + + @doc("The 3rd Party artifact that is being procured. E.g. NewRelic. Product maps to the OfferID specified for the artifact at the time of Data Market onboarding. ") + product: string; + + @doc("A publisher provided promotion code as provisioned in Data Market for the said product/artifact.") + promotionCode?: string; + + @doc("The version of the desired product/artifact.") + version?: string; +} + +/** + * The check availability request body. + */ +@armCommonDefinition("CheckNameAvailabilityRequest", Azure.ResourceManager.CommonTypes.Versions.v3) +@armCommonDefinition("CheckNameAvailabilityRequest", Azure.ResourceManager.CommonTypes.Versions.v4) +@armCommonDefinition("CheckNameAvailabilityRequest", Azure.ResourceManager.CommonTypes.Versions.v5) +@doc("The check availability request body.") +model CheckNameAvailabilityRequest { + @doc("The name of the resource for which availability needs to be checked.") + name?: string; + + @doc("The resource type.") + type?: string; +} + +/** + * The check availability result. + */ +@armCommonDefinition("CheckNameAvailabilityResponse", Azure.ResourceManager.CommonTypes.Versions.v3) +@armCommonDefinition("CheckNameAvailabilityResponse", Azure.ResourceManager.CommonTypes.Versions.v4) +@armCommonDefinition("CheckNameAvailabilityResponse", Azure.ResourceManager.CommonTypes.Versions.v5) +@doc("The check availability result.") +model CheckNameAvailabilityResponse { + @doc("Indicates if the resource name is available.") + nameAvailable?: boolean; + + @doc("The reason why the given name is not available.") + reason?: CheckNameAvailabilityReason; + + @doc("Detailed reason why the given name is not available.") + message?: string; +} + +/** + * Possible reasons for a name not being available. + */ +@doc("Possible reasons for a name not being available.") +union CheckNameAvailabilityReason { + @doc("Name is invalid.") + Invalid: "Invalid", + + @doc("Name already exists.") + AlreadyExists: "AlreadyExists", + + string, +} diff --git a/packages/typespec-azure-resource-manager/lib/models.tsp b/packages/typespec-azure-resource-manager/lib/models.tsp index 380f111d94..25bf6e7180 100644 --- a/packages/typespec-azure-resource-manager/lib/models.tsp +++ b/packages/typespec-azure-resource-manager/lib/models.tsp @@ -171,6 +171,20 @@ model DefaultProvisioningStateProperty { provisioningState?: ResourceProvisioningState; } +/** The standard evenlop definition of ExtendedLocation. + * + * @example + * ```typespec + * model Employee is TrackedResource { + * ...ResourceNameParameter; + * ...ExtendedLocationProperty; + * } + * ``` + */ +model ExtendedLocationProperty { + extendedLocation: Foundations.ExtendedLocation; +} + /** * Standard Azure Resource Manager definition of ManagedServiceIdentity */ diff --git a/packages/typespec-azure-resource-manager/package.json b/packages/typespec-azure-resource-manager/package.json index 76b1bd1d53..00274a59d9 100644 --- a/packages/typespec-azure-resource-manager/package.json +++ b/packages/typespec-azure-resource-manager/package.json @@ -47,7 +47,7 @@ "regen-docs": "tspd doc . --enable-experimental --output-dir ../../docs/libraries/azure-resource-manager/reference" }, "files": [ - "lib/*.tsp", + "lib/**/*.tsp", "dist/**", "!dist/test/**" ], diff --git a/packages/typespec-azure-resource-manager/test/resource.test.ts b/packages/typespec-azure-resource-manager/test/resource.test.ts index dd4b72b386..4d9be5f670 100644 --- a/packages/typespec-azure-resource-manager/test/resource.test.ts +++ b/packages/typespec-azure-resource-manager/test/resource.test.ts @@ -1076,4 +1076,27 @@ describe("typespec-azure-resource-manager: ARM resource model", () => { }, }); }); + + it("emits correct extended location for resource", async () => { + const { program, diagnostics } = await checkFor(` + @armProviderNamespace + @useDependency(Azure.ResourceManager.Versions.v1_0_Preview_1) + namespace Microsoft.Contoso; + + @doc("Widget resource") + model Widget is ProxyResource { + ...ResourceNameParameter; + ...ExtendedLocationProperty; + } + + @doc("The properties of a widget") + model WidgetProperties { + size: int32; + } + `); + const resources = getArmResources(program); + expectDiagnosticEmpty(diagnostics); + strictEqual(resources.length, 1); + ok(resources[0].typespecType.properties.has("extendedLocation")); + }); });