Polymorphic Resource
Sample configuration for polymorphic-resource in legacy.
import "@typespec/http";import "@typespec/rest";import "@typespec/versioning";import "@azure-tools/typespec-azure-core";import "@azure-tools/typespec-azure-resource-manager";import "./proxy.tsp";import "./extension.tsp";
using Versioning;using Azure.ResourceManager;
/** Contoso Resource Provider management API. */#suppress "@azure-tools/typespec-azure-resource-manager/missing-operations-endpoint" ""@armProviderNamespace@service(#{ title: "ContosoProviderHubClient" })@versioned(Versions)namespace Microsoft.ContosoProviderHub;
/** Contoso API versions */enum Versions { /** 2021-10-01-preview version */ @armCommonTypesVersion(Azure.ResourceManager.CommonTypes.Versions.v5) `2025-10-01-preview`,}
/** Standard operation list */interface Operations extends Azure.ResourceManager.Operations {}import "@typespec/http";import "@typespec/rest";import "@typespec/versioning";import "@azure-tools/typespec-azure-core";import "@azure-tools/typespec-azure-resource-manager";
using Azure.ResourceManager;
namespace Microsoft.ContosoProviderHub;
/** A ContosoProviderHub resource */#suppress "@azure-tools/typespec-azure-core/no-legacy-usage" "For sample purpose"model Cost is Azure.ResourceManager.Legacy.DiscriminatedExtensionResource { ...ResourceNameParameter<Cost>;}
/** The rp-specific properties of the cost */model CapitalProperties { /** The amount of capital */ amount?: float64;
...DefaultProvisioningStateProperty;}
/** The properties of an expense */model ExpenseProperties { /** The amount of the expense */ amount?: float64;
/** The duration of the expense */ duration?: duration;
...DefaultProvisioningStateProperty;}
/** Salaried employee */model Capital extends Cost { kind: "capital"; properties: CapitalProperties;}
/** Hourly employee */model Expense extends Cost { kind: "expense"; properties: ExpenseProperties;}
@armResourceOperationsinterface Costs<Parent extends Foundations.SimpleResource> { get is Extension.Read<Parent, Cost>; list is Extension.ListByTarget<Parent, Cost>;}@armResourceOperationsinterface Scopes extends Costs<Extension.ScopeParameter> {}@armResourceOperationsinterface Tenants extends Costs<Extension.Tenant> {}@armResourceOperationsinterface Subscriptions extends Costs<Extension.Subscription> {}@armResourceOperationsinterface ManagementGroups extends Costs<Extension.ManagementGroup> {}import "@typespec/http";import "@typespec/rest";import "@typespec/versioning";import "@azure-tools/typespec-azure-core";import "@azure-tools/typespec-azure-resource-manager";
using Azure.ResourceManager;
namespace Microsoft.ContosoProviderHub;
/** A ContosoProviderHub resource */#suppress "@azure-tools/typespec-azure-core/no-legacy-usage" "For sample purpose"@subscriptionResourcemodel Room is Azure.ResourceManager.Legacy.DiscriminatedProxyResource { ...ResourceNameParameter<Room>;}
@doc("The rp-specific properties of the room")model ConferenceRoomProperties { /** The number of occupants */ capacity?: int32;
/** The city of current residence */ city?: string;
...DefaultProvisioningStateProperty;}
/** The properties of an office */model OfficeProperties { /** The number of desks in the office */ desks?: int32;
/** The city of current residence */ city?: string;
...DefaultProvisioningStateProperty;}
/** Salaried employee */model ConferenceRoom extends Room { kind: "conference"; properties: ConferenceRoomProperties;}
/** Hourly employee */model Office extends Room { kind: "office"; properties: OfficeProperties;}
@armResourceOperationsinterface Rooms { get is ArmResourceRead<Room>; list is ArmResourceListByParent<Room>;}