Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update templates, docs, and sample
  • Loading branch information
markcowl committed Jun 25, 2025
commit 23d65f8cd446a309a3af8821da0e2ff6e676472f
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import "@typespec/versioning";
import "@azure-tools/typespec-azure-core";
import "@azure-tools/typespec-azure-resource-manager";

using Http;
using Rest;
using Versioning;
using Azure.Core;
using Azure.ResourceManager;
Expand Down Expand Up @@ -82,24 +80,29 @@ interface EmplOps<Scope extends Azure.ResourceManager.Foundations.SimpleResource
}

/** Virtual resource for a virtual machine */
alias VirtualMachine = Extension.ExternalResource<"Microsoft.Compute", "virtualMachines", "vmName">;
alias VirtualMachine = Extension.ExternalResource<
"Microsoft.Compute",
"virtualMachines",
"vmName",
NamePattern = "^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}$",
Description = "The name of the virtual machine"
>;

alias Scaleset = Extension.ExternalResource<
"Microsoft.Compute",
"virtualMachineScaleSets",
"scaleSetName"
"scaleSetName",
NamePattern = "^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}$",
Description = "The name of the virtual machine scale set"
>;

alias VirtualMachineScaleSetVm = Extension.ExternalChildResource<
Scaleset,
"virtualMachineScaleSetVms",
"scaleSetVmName",
NamePattern = "^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}$",
Description = "The name of the virtual machine scale set VM"
>;
/** A scaleset VM */
@parentResource(Scaleset)
model VirtualMachineScaleSetVm {
/** Name of the scaleset VM */
@visibility(Lifecycle.Read)
@path
@segment("virtualMachineScaleSetVms")
@key("scaleSetVmName")
@pattern("^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}$")
name: string;
}

@armResourceOperations
interface Employees extends EmplOps<Extension.ScopeParameter> {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1302,14 +1302,15 @@
{
"name": "scaleSetName",
"in": "path",
"description": "The name of the virtual machine",
"description": "The name of the virtual machine scale set",
"required": true,
"type": "string"
"type": "string",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}$"
},
{
"name": "scaleSetVmName",
"in": "path",
"description": "Name of the scaleset VM",
"description": "The name of the virtual machine scale set VM",
"required": true,
"type": "string",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}$"
Expand Down Expand Up @@ -1354,14 +1355,15 @@
{
"name": "scaleSetName",
"in": "path",
"description": "The name of the virtual machine",
"description": "The name of the virtual machine scale set",
"required": true,
"type": "string"
"type": "string",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}$"
},
{
"name": "scaleSetVmName",
"in": "path",
"description": "Name of the scaleset VM",
"description": "The name of the virtual machine scale set VM",
"required": true,
"type": "string",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}$"
Expand Down Expand Up @@ -1409,14 +1411,15 @@
{
"name": "scaleSetName",
"in": "path",
"description": "The name of the virtual machine",
"description": "The name of the virtual machine scale set",
"required": true,
"type": "string"
"type": "string",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}$"
},
{
"name": "scaleSetVmName",
"in": "path",
"description": "Name of the scaleset VM",
"description": "The name of the virtual machine scale set VM",
"required": true,
"type": "string",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}$"
Expand Down Expand Up @@ -1494,14 +1497,15 @@
{
"name": "scaleSetName",
"in": "path",
"description": "The name of the virtual machine",
"description": "The name of the virtual machine scale set",
"required": true,
"type": "string"
"type": "string",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}$"
},
{
"name": "scaleSetVmName",
"in": "path",
"description": "Name of the scaleset VM",
"description": "The name of the virtual machine scale set VM",
"required": true,
"type": "string",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}$"
Expand Down Expand Up @@ -1558,14 +1562,15 @@
{
"name": "scaleSetName",
"in": "path",
"description": "The name of the virtual machine",
"description": "The name of the virtual machine scale set",
"required": true,
"type": "string"
"type": "string",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}$"
},
{
"name": "scaleSetVmName",
"in": "path",
"description": "Name of the scaleset VM",
"description": "The name of the virtual machine scale set VM",
"required": true,
"type": "string",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}$"
Expand Down Expand Up @@ -1630,14 +1635,15 @@
{
"name": "scaleSetName",
"in": "path",
"description": "The name of the virtual machine",
"description": "The name of the virtual machine scale set",
"required": true,
"type": "string"
"type": "string",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}$"
},
{
"name": "scaleSetVmName",
"in": "path",
"description": "Name of the scaleset VM",
"description": "The name of the virtual machine scale set VM",
"required": true,
"type": "string",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}$"
Expand Down Expand Up @@ -1698,7 +1704,8 @@
"in": "path",
"description": "The name of the virtual machine",
"required": true,
"type": "string"
"type": "string",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}$"
}
],
"responses": {
Expand Down Expand Up @@ -1742,7 +1749,8 @@
"in": "path",
"description": "The name of the virtual machine",
"required": true,
"type": "string"
"type": "string",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}$"
},
{
"name": "employeeName",
Expand Down Expand Up @@ -1789,7 +1797,8 @@
"in": "path",
"description": "The name of the virtual machine",
"required": true,
"type": "string"
"type": "string",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}$"
},
{
"name": "employeeName",
Expand Down Expand Up @@ -1866,7 +1875,8 @@
"in": "path",
"description": "The name of the virtual machine",
"required": true,
"type": "string"
"type": "string",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}$"
},
{
"name": "employeeName",
Expand Down Expand Up @@ -1922,7 +1932,8 @@
"in": "path",
"description": "The name of the virtual machine",
"required": true,
"type": "string"
"type": "string",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}$"
},
{
"name": "employeeName",
Expand Down Expand Up @@ -1986,7 +1997,8 @@
"in": "path",
"description": "The name of the virtual machine",
"required": true,
"type": "string"
"type": "string",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}$"
},
{
"name": "employeeName",
Expand Down Expand Up @@ -2506,21 +2518,6 @@
]
},
"readOnly": true
},
"VirtualMachineScaleSetVm": {
"type": "object",
"description": "A scaleset VM",
"properties": {
"name": {
"type": "string",
"description": "Name of the scaleset VM",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}$",
"readOnly": true
}
},
"required": [
"name"
]
}
},
"parameters": {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ using Azure.ResourceManager.CommonTypes;

/**
* The default scope parameter for an extension resource.
* @template Type The type of the scope parameter (default is string). This can be used to specify `Azure.Core.armResourceIdentifier` type or other constrained type
*
* @example
* ```typespec
Expand All @@ -17,11 +18,11 @@ using Azure.ResourceManager.CommonTypes;
* ```
*/
@builtInResource
model ScopeParameter {
model ScopeParameter<Type extends string = string> {
@path(#{ allowReserved: true })
@key
@doc("The fully qualified Azure Resource manager identifier of the resource.")
scope: string;
scope: Type;
}

/**
Expand Down Expand Up @@ -124,6 +125,9 @@ model ManagementGroup<ParameterName extends valueof string = "managementGroupNam
* @template TargetNamespace The provider namespace for the external resource.
* @template ResourceType The type of the external resource.
* @template ResourceParameterName The name of the 'name' parameter of the external resource.
* @template NamePattern The pattern restriction for the name of the external resource (default is none).
* @template NameType The type of the name parameter of the external resource (default is string).
* @template Description The description of the name parameter of the external resource (default is "The name of the resource").
*
* @example
* ```typespec
Expand All @@ -138,35 +142,78 @@ model ManagementGroup<ParameterName extends valueof string = "managementGroupNam
* "virtualMachineScaleSets",
* "scaleSetName"
* >;
*
* @parentResource(Scaleset)
* model VirtualMachineScaleSetVm {
* @visibility(Lifecycle.Read)
* @path
* @segment("virtualMachineScaleSetVms")
* @key("scaleSetVmName")
* @pattern("^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}$")
* @doc("Name of the scaleset VM")
* name: string;
* }
*

* ```
*/
@doc("")
@armVirtualResource(TargetNamespace)
@Http.Private.includeInapplicableMetadataInPayload(false)
model ExternalResource<
TargetNamespace extends valueof string,
ResourceType extends valueof string,
ResourceParameterName extends valueof string
ResourceParameterName extends valueof string,
NamePattern extends valueof string = "",
NameType extends string = string,
Description extends valueof string = "The name of the resource"
> {
/** The name of the virtual machine */
@doc(Description)
@visibility(Lifecycle.Read)
@path
@key(ResourceParameterName)
@segment(ResourceType)
name: string;
@pattern(NamePattern)
name: NameType;
}

/** An external child resource target, used when an extension targets a child resource from another provider namespace
* @template ParentModel The parent of this resource.
* @template ResourceType The type of this resource.
* @template ResourceParameterName The name of the 'name' parameter of this resource.
* @template NamePattern The pattern restriction for the name of this resource (default is none).
* @template NameType The type of the name parameter of this resource (default is string).
* @template Description The description of the name parameter of this resource (default is "The name of the resource").
*
* @example
* ```typespec
* alias VirtualMachine = ExternalResource<"Microsoft.Compute", "virtualMachines", "vmName">;
*
* ```
*
* @example
* ```typespec
* alias Scaleset = Extension.ExternalResource<
* "Microsoft.Compute",
* "virtualMachineScaleSets",
* "scaleSetName"
* >;
*
* alias VirtualMachineScaleSetVm = Extension.ExternalChildResource<
* Scaleset,
* "virtualMachineScaleSetVms",
* "scaleSetVmName"
* >;
*
* ```
*/
@doc("")
@parentResource(ParentModel)
@Http.Private.includeInapplicableMetadataInPayload(false)
model ExternalChildResource<
ParentModel extends {},
ResourceType extends valueof string,
ResourceParameterName extends valueof string,
NamePattern extends valueof string = "",
NameType extends string = string,
Description extends valueof string = "The name of the resource"
> {
@doc(Description)
@visibility(Lifecycle.Read)
@path
@key(ResourceParameterName)
@segment(ResourceType)
@pattern(NamePattern)
name: NameType;
}
/** A subscription target for an extension resource */
@builtInSubscriptionResource
model Subscription {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,23 +277,10 @@ const $assignProviderNameValue: AssignProviderNameValueDecorator = (
const { program } = context;
const armProviderNamespace = getArmProviderNamespace(program, resourceType as Model);
if (armProviderNamespace && target.type.kind === "String") {
target.type = createOrGetProviderType(program, armProviderNamespace);
target.type = $(program).literal.createString(armProviderNamespace);
}
};

function createOrGetProviderType(program: Program, provider: string): StringLiteral {
const cache = ((program as ProviderNameCache)[PROVIDER_NAME_CACHE] ??= new Map<
string,
StringLiteral
>());
if (cache.has(provider)) {
return cache.get(provider)!;
}

const newType = $(program).realm.typekit.literal.createString(provider);
cache.set(provider, newType);
return newType;
}
/**
* Update the ARM provider namespace for a given entity.
* @param {DecoratorContext} context DecoratorContext
Expand Down
Loading