Skip to content

Decorators

Pairs named HTTP server endpoints with OAuth authentication configurations.

Requires a public configuration, which is always the default regardless of declaration order. Calls @server for each configuration, with public first, and exposes the combined OR of HTTP authentication requirements. Existing AND groups and credential alternatives are preserved.

The HTTP view exposes servers and auth alternatives independently. Azure Core metadata retains their pairing and the public default for SDK generation.

Every configuration must include OAuth2, but OAuth flows, URLs, scopes, and authentication requirements may differ between configurations. Use ordinary HTTP authentication models. Do not combine this decorator with @server or @useAuth on the same namespace.

OAuth URL metadata does not change a caller-owned credential’s authority or tenant.

Declare a value record and use typeref(...) to reference authentication types and endpoint parameter models. Enable the experimental typeref compiler feature in the consuming project’s tspconfig.yaml:

kind: project
features:
- typeref
@Azure.Core.azureServiceConfigurations(configurations: valueof Record<Azure.Core.AzureServiceConfiguration>)

The namespace using these configurations. Namespace

NameTypeDescription
configurationsvalueof Record<Azure.Core.AzureServiceConfiguration>The named endpoint and authentication records.
model PublicAuth is AadOauth2Auth<
["https://api.loganalytics.io/.default"],
"https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
"https://login.microsoftonline.com/common/oauth2/v2.0/token"
>;
model GovernmentAuth is AadOauth2Auth<
["https://api.loganalytics.us/.default"],
"https://login.microsoftonline.us/common/oauth2/v2.0/authorize",
"https://login.microsoftonline.us/common/oauth2/v2.0/token"
>;
const Configurations: Record<AzureServiceConfiguration> = #{
public: #{ endpoint: "https://api.loganalytics.io", authentication: typeref(PublicAuth) },
government: #{ endpoint: "https://api.loganalytics.us", authentication: typeref(GovernmentAuth) },
};
@service
@azureServiceConfigurations(Configurations)
namespace Logs {
@get op query(): string;
}

Declare endpoint parameters inline with parameters: typeref({ ... }), using the same property types and defaults as @server. Here, account is required and region defaults to "westus".

import "@typespec/http";
import "@azure-tools/typespec-azure-core";
using TypeSpec.Http;
using Azure.Core;
model ServiceAuth is AadOauth2Auth<["https://example.com/.default"]>;
const Configurations: Record<AzureServiceConfiguration> = #{
public: #{
endpoint: "https://{account}.{region}.example.com",
authentication: typeref(ServiceAuth),
parameters: typeref({
@doc("Account name.")
account: string,
@doc("Deployment region.")
region?: string = "westus",
}),
description: "Regional service endpoint",
},
};
@service
@azureServiceConfigurations(Configurations)
namespace RegionalService {
@get op read(): string;
}

Identifies a ModelProperty as containing the final location for the operation result.

@Azure.Core.finalLocation(finalResult?: Model | unknown | void)

ModelProperty

NameTypeDescription
finalResultModel | unknown | voidSets the expected return value for the final result. Overrides
any value provided in the decorated property, if the property uses ResourceLocation.

Identifies that an operation is the final operation for an LRO.

@Azure.Core.finalOperation(linkedOperation: Operation, parameters?: {})

Operation

NameTypeDescription
linkedOperationOperationThe linked Operation
parameters{}Map of RequestParameter<Name> and/or ResponseProperty<Name> that will
be passed to the linked operation request.

Used for custom StatusMonitor implementation. Identifies an EnumMember as a long-running “Canceled” terminal state.

@Azure.Core.lroCanceled

EnumMember | UnionVariant

None

Used for custom StatusMonitor implementation. Identifies a model property of a StatusMonitor as containing the result of a long-running operation that terminates unsuccessfully (Failed).

@Azure.Core.lroErrorResult

ModelProperty

None

Used for custom StatusMonitor implementation. Identifies an enum member as a long-running “Failed” terminal state.

@Azure.Core.lroFailed

EnumMember | UnionVariant

None

Used for custom StatusMonitor implementation. Identifies a model property of a StatusMonitor as containing the result of a long-running operation that terminates successfully (Succeeded).

@Azure.Core.lroResult

ModelProperty

None

Used for custom StatusMonitor implementation. Identifies an Enum or ModelProperty as containing long-running operation status.

@Azure.Core.lroStatus

Enum | Union | ModelProperty

None

Used for custom StatusMonitor implementation. Identifies an EnumMember as a long-running “Succeeded” terminal state.

@Azure.Core.lroSucceeded

EnumMember | UnionVariant

None

Identifies an operation that is linked to the target operation.

@Azure.Core.operationLink(linkedOperation: Operation, linkType: valueof string, parameters?: {})

Operation

NameTypeDescription
linkedOperationOperationThe linked Operation
linkTypevalueof stringA string indicating the role of the linked operation
parameters{}Map of RequestParameter<Name> and/or ResponseProperty<Name> that will
be passed to the linked operation request.

Identifies a model property as containing the location to poll for operation state.

@Azure.Core.pollingLocation(options?: Azure.Core.PollingOptions)

ModelProperty

NameTypeDescription
optionsPollingOptionsPollingOptions for the poller pointed to by this link. Overrides
settings derived from property value it is decorating, if the value of the
property is ResourceLocation

Identifies that an operation is a polling operation for an LRO.

@Azure.Core.pollingOperation(linkedOperation: Operation, parameters?: {})

Operation

NameTypeDescription
linkedOperationOperationThe linked Operation
parameters{}Map of RequestParameter<Name> and/or ResponseProperty<Name> that will
be passed to the linked operation request.

Used to define how to call custom polling operations for long-running operations.

@Azure.Core.pollingOperationParameter(targetParameter?: ModelProperty | string)

ModelProperty

NameTypeDescription
targetParameterModelProperty | stringA reference to the polling operation parameter this parameter
provides a value for, or the name of that parameter. The default value is the name of
the decorated parameter or property.

Decorator that marks a Version EnumMember as a preview version. This is used to indicate that the version is not yet stable and may change in future releases.

@Azure.Core.previewVersion

The EnumMember that represents the preview version. EnumMember

None

@versioned(Versions)
@service(#{ title: "Widget Service" })
namespace DemoService;
enum Versions {
v1,
v2,
@previewVersion
v3Preview,
}

Specifies that an array model or array-typed property should contain only unique items.

@Azure.Core.uniqueItems

ModelProperty | Model

None

Overrides the final state value for an operation

@Azure.Core.useFinalStateVia(finalState: valueof "original-uri" | "operation-location" | "location" | "azure-async-operation")

Operation

NameTypeDescription
finalStatevalueof "original-uri" | "operation-location" | "location" | "azure-async-operation"The desired final state value

Deletes any key properties from the model.

@Azure.Core.Foundations.omitKeyProperties

Model

None

Identifies a property on a request model that serves as a linked operation parameter.

@Azure.Core.Foundations.requestParameter(name: valueof string)

Model

NameTypeDescription
namevalueof stringProperty name on the target

Identifies a property on all non-error response models that serve as a linked operation parameter.

@Azure.Core.Foundations.responseProperty(name: valueof string)

Model

NameTypeDescription
namevalueof stringProperty name on the target

Overrides the API-version wire value used for operations within a namespace or interface.

The value is opaque and does not need to be declared by the service version enum. The override is inherited by enclosed namespaces, interfaces, and operations, with the nearest override taking precedence.

This decorator is considered legacy functionality and should only be used to preserve compatibility with an existing SDK.

@Azure.Core.Legacy.overrideApiVersion(version: valueof string)

The namespace or interface whose operations use the API-version override. Namespace | Interface

NameTypeDescription
versionvalueof stringThe non-empty API-version wire value.
@Azure.Core.Legacy.overrideApiVersion("2021-11-01")
interface Widgets {
get(): void;
}

@trait marks a model type as representing a ‘trait’ and performs basic validation checks.

@Azure.Core.Traits.trait(traitName?: valueof string)

The model type to mark as a trait. Model

NameTypeDescription
traitNamevalueof stringAn optional name to uniquely identify the trait. If unspecified,
the model type name is used.

Sets the version for when the trait was added to the specification. Can be applied to either a trait model type or its envelope property.

@Azure.Core.Traits.traitAdded(addedVersion: EnumMember | null)

Model | ModelProperty

NameTypeDescription
addedVersionEnumMember | nullThe enum member representing the service version.

@traitContext sets the applicable context for a trait on its envelope property.

@Azure.Core.Traits.traitContext(contexts: EnumMember | Union | unknown)

The trait envelope property where the context will be applied. ModelProperty

NameTypeDescription
contextsEnumMember | Union | unknownAn enum member or union of enum members representing the trait’s
applicable contexts.

@traitLocation sets the applicable location for a trait on its envelope property.

@Azure.Core.Traits.traitLocation(contexts: EnumMember)

The trait envelope property where the context will be applied. ModelProperty

NameTypeDescription
contextsEnumMemberAn enum member or union of enum members representing the trait’s
applicable contexts.