Skip to content

Commit

Permalink
Fix Location resource, add mechanism for additional non-resource path…
Browse files Browse the repository at this point in the history
… segments (#203)
  • Loading branch information
markcowl authored Feb 3, 2024
1 parent b909dae commit ebfe639
Show file tree
Hide file tree
Showing 20 changed files with 2,399 additions and 118 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-shrimps-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@azure-tools/typespec-azure-resource-manager": patch
---

Fix Location resource issue, add mechanism for additional path segments
29 changes: 29 additions & 0 deletions docs/libraries/azure-resource-manager/reference/data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@ The response for synchronous delete of a resource
model Azure.ResourceManager.ArmDeletedResponse
```

### `ArmLocationResource` {#Azure.ResourceManager.ArmLocationResource}

Template for ARM location resources. Use the parameter to specify

```typespec
model Azure.ResourceManager.ArmLocationResource<BaseType>
```

#### Template Parameters

| Name | Description |
| -------- | ----------- |
| BaseType | |

### `ArmLroLocationHeader` {#Azure.ResourceManager.ArmLroLocationHeader}

The default header for lro PUT and DELETE polling
Expand Down Expand Up @@ -505,6 +519,15 @@ model Azure.ResourceManager.ProxyResource<Properties>
| ---------- | --------------------------------------------------------------------- |
| Properties | A model containing the provider-specific properties for this resource |

### `ResourceGroupLocationResource` {#Azure.ResourceManager.ResourceGroupLocationResource}

The location resource for resourceGroup-based locations. This can be used as a parent
resource for resource types that are homed in a resourceGroup-based location.

```typespec
model Azure.ResourceManager.ResourceGroupLocationResource
```

### `ResourceGroupParameter` {#Azure.ResourceManager.ResourceGroupParameter}

The default resource group parameter type.
Expand Down Expand Up @@ -637,12 +660,18 @@ model Azure.ResourceManager.SubscriptionIdParameter

### `SubscriptionLocationResource` {#Azure.ResourceManager.SubscriptionLocationResource}

The location resource for subscription-based locations. This can be used as a parent
resource for resource types that are homed in a subscription-based location.

```typespec
model Azure.ResourceManager.SubscriptionLocationResource
```

### `TenantLocationResource` {#Azure.ResourceManager.TenantLocationResource}

The location resource for tenant-based locations. This can be used as a parent
resource for resource types that are homed in a tenant-based location.

```typespec
model Azure.ResourceManager.TenantLocationResource
```
Expand Down
35 changes: 35 additions & 0 deletions docs/libraries/azure-resource-manager/reference/decorators.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,23 @@ clients.
| ------------ | ------- | -------------- |
| resourceType | `Model` | Resource model |

### `@armVirtualResource` {#@Azure.ResourceManager.armVirtualResource}

This decorator is used on Azure Resource Manager resources that are not based on
Azure.ResourceManager common types.

```typespec
@Azure.ResourceManager.armVirtualResource
```

#### Target

`Model`

#### Parameters

None

### `@extensionResource` {#@Azure.ResourceManager.extensionResource}

`@extensionResource` marks an Azure Resource Manager resource model as an Extension resource.
Expand Down Expand Up @@ -298,6 +315,24 @@ See more details on [different Azure Resource Manager resource type here.](https

None

### `@resourceBaseType` {#@Azure.ResourceManager.resourceBaseType}

This decorator sets the base type of the given resource.

```typespec
@Azure.ResourceManager.resourceBaseType(baseType: Tenant | Subscription | ResourceGroup | Location | Extension)
```

#### Target

`Model`

#### Parameters

| Name | Type | Description |
| -------- | ------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------- |
| baseType | `union Tenant \| Subscription \| ResourceGroup \| Location \| Extension` | The built-in parent of the resource, this can be "Tenant", "Subscription", "ResourceGroup", "Location", or "Extension" |

### `@resourceGroupResource` {#@Azure.ResourceManager.resourceGroupResource}

`@resourceGroupResource` marks an Azure Resource Manager resource model as a resource group level resource.
Expand Down
4 changes: 4 additions & 0 deletions docs/libraries/azure-resource-manager/reference/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ npm install --save-peer @azure-tools/typespec-azure-resource-manager
- [`@armResourceOperations`](./decorators.md#@Azure.ResourceManager.armResourceOperations)
- [`@armResourceRead`](./decorators.md#@Azure.ResourceManager.armResourceRead)
- [`@armResourceUpdate`](./decorators.md#@Azure.ResourceManager.armResourceUpdate)
- [`@armVirtualResource`](./decorators.md#@Azure.ResourceManager.armVirtualResource)
- [`@extensionResource`](./decorators.md#@Azure.ResourceManager.extensionResource)
- [`@locationResource`](./decorators.md#@Azure.ResourceManager.locationResource)
- [`@resourceBaseType`](./decorators.md#@Azure.ResourceManager.resourceBaseType)
- [`@resourceGroupResource`](./decorators.md#@Azure.ResourceManager.resourceGroupResource)
- [`@singleton`](./decorators.md#@Azure.ResourceManager.singleton)
- [`@subscriptionResource`](./decorators.md#@Azure.ResourceManager.subscriptionResource)
Expand Down Expand Up @@ -122,6 +124,7 @@ npm install --save-peer @azure-tools/typespec-azure-resource-manager
- [`ArmDeleteAcceptedResponse`](./data-types.md#Azure.ResourceManager.ArmDeleteAcceptedResponse)
- [`ArmDeletedNoContentResponse`](./data-types.md#Azure.ResourceManager.ArmDeletedNoContentResponse)
- [`ArmDeletedResponse`](./data-types.md#Azure.ResourceManager.ArmDeletedResponse)
- [`ArmLocationResource`](./data-types.md#Azure.ResourceManager.ArmLocationResource)
- [`ArmLroLocationHeader`](./data-types.md#Azure.ResourceManager.ArmLroLocationHeader)
- [`ArmNoContentResponse`](./data-types.md#Azure.ResourceManager.ArmNoContentResponse)
- [`ArmOperationStatus`](./data-types.md#Azure.ResourceManager.ArmOperationStatus)
Expand Down Expand Up @@ -155,6 +158,7 @@ npm install --save-peer @azure-tools/typespec-azure-resource-manager
- [`PrivateLinkServiceConnectionState`](./data-types.md#Azure.ResourceManager.PrivateLinkServiceConnectionState)
- [`ProviderNamespace`](./data-types.md#Azure.ResourceManager.ProviderNamespace)
- [`ProxyResource`](./data-types.md#Azure.ResourceManager.ProxyResource)
- [`ResourceGroupLocationResource`](./data-types.md#Azure.ResourceManager.ResourceGroupLocationResource)
- [`ResourceGroupParameter`](./data-types.md#Azure.ResourceManager.ResourceGroupParameter)
- [`ResourceIdentifierAllowedResource`](./data-types.md#Azure.ResourceManager.ResourceIdentifierAllowedResource)
- [`ResourceInstanceParameters`](./data-types.md#Azure.ResourceManager.ResourceInstanceParameters)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import "@typespec/rest";
import "@typespec/versioning";
import "@azure-tools/typespec-azure-core";
import "@azure-tools/typespec-azure-resource-manager";

using TypeSpec.Http;
using TypeSpec.Rest;
using TypeSpec.Versioning;
using Azure.Core;
using Azure.ResourceManager;

/** Contoso Resource Provider management API. */
@armProviderNamespace
@service({
title: "ContosoProviderHubClient",
})
@versioned(Versions)
namespace Microsoft.ContosoProviderHub;

/** Contoso API versions */
enum Versions {
/** 2021-10-01-preview version */
@useDependency(Azure.ResourceManager.Versions.v1_0_Preview_1)
@armCommonTypesVersion(Azure.ResourceManager.CommonTypes.Versions.v5)
`2021-10-01-preview`,
}

/** A ContosoProviderHub resource */
@parentResource(ArmLocationResource<"ResourceGroup">)
model Employee is TrackedResource<EmployeeProperties> {
/** Name of employee */
@pattern("^[a-zA-Z0-9-]{3,24}$")
@key("employeeName")
@path
@segment("employees")
@visibility("read")
name: string;
}

/** Employee properties */
model EmployeeProperties {
/** Age of employee */
age?: int32;

/** City of employee */
city?: string;

/** Profile of employee */
@encode("base64url")
profile?: bytes;

/** The status of the last operation. */
@visibility("read")
provisioningState?: ProvisioningState;
}

/** The provisioning state of a resource. */
@lroStatus
enum ProvisioningState {
...ResourceProvisioningState,

/** The resource is being provisioned */
Provisioning,

/** The resource is updating */
Updating,

/** The resource is being deleted */
Deleting,

/** The resource create request has been accepted */
Accepted,
}

interface Operations extends Azure.ResourceManager.Operations {}

@armResourceOperations
interface Employees {
get is ArmResourceRead<Employee>;
createOrUpdate is ArmResourceCreateOrReplaceAsync<Employee>;
update is ArmResourcePatchSync<Employee, EmployeeProperties>;
delete is ArmResourceDeleteSync<Employee>;
list is ArmResourceListByParent<Employee>;
/** A sample resource action that move employee to different location */
move is ArmResourceActionSync<Employee, MoveRequest, MoveResponse>;
}

/** Employee move request */
model MoveRequest {
/** The moving from location */
from: string;

/** The moving to location */
to: string;
}

/** Employee move response */
model MoveResponse {
/** The status of the move */
movingStatus: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import "@typespec/http";
import "@typespec/rest";
import "@typespec/versioning";
import "@azure-tools/typespec-azure-core";
import "@azure-tools/typespec-azure-resource-manager";

using TypeSpec.Http;
using TypeSpec.Rest;
using TypeSpec.Versioning;
using Azure.ResourceManager;

@service({
title: "Microsoft.OperationsTest",
})
@versioned(Versions)
@armProviderNamespace
namespace Microsoft.OperationStatusSample;

enum Versions {
@useDependency(Azure.ResourceManager.Versions.v1_0_Preview_1)
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
@armCommonTypesVersion("v5")
`2022-11-01-preview`,
}

interface Operations extends Azure.ResourceManager.Operations {}

/** The standard operation status */
@parentResource(TenantLocationResource)
model MyOpStatus is ArmOperationStatus;

/** The standard operation status at the subscription level] */
@parentResource(SubscriptionLocationResource)
model MySubOpStatus is ArmOperationStatus;

@parentResource(ArmLocationResource<"ResourceGroup">)
model MyResourceGroupStatus is ArmOperationStatus;

interface OperationStatuses {
getStatus is ArmResourceRead<MyOpStatus>;
getSubscriptionStatus is ArmResourceRead<MySubOpStatus>;
getRgStatus is ArmResourceRead<MyResourceGroupStatus>;
}
Loading

0 comments on commit ebfe639

Please sign in to comment.