Skip to content

Decorators

Override access for operations, models, enums and model properties. When setting access for namespaces, the access info will be propagated to the models and operations defined in the namespace. If the model has an access override, the model override takes precedence. When setting access for an operation, it will influence the access info for models/enums that are used by this operation. Models/enums that are used in any operations with @access(Access.public) will be set to access “public” Models/enums that are only used in operations with @access(Access.internal) will be set to access “internal”. The access info for models will be propagated to models’ properties, parent models, discriminated sub models. The override access should not be narrower than the access calculated by operation, and different override access should not conflict with each other, otherwise a warning will be added to the diagnostics list. Model property’s access will default to public unless there is an override.

@Azure.ClientGenerator.Core.access(value: EnumMember, scope?: valueof string)

The target type you want to override access info. ModelProperty | Model | Operation | Enum | Union | Namespace

NameTypeDescription
valueEnumMemberThe access info you want to set for this model or operation. It should be one of the Access enum values, either Access.public or Access.internal.
scopevalueof stringSpecifies the target language emitters that the decorator should apply. If not set, the decorator will be applied to all language emitters by default.
You can use ”!” to exclude specific languages, for example: !(java, python) or !java, !python.
Access.internal
@access(Access.internal)
model ModelToHide {
prop: string;
}
// Access.internal
@access(Access.internal)
op test: void;
Access.internal
@discriminator("kind")
model Fish {
age: int32;
}
// Access.internal
@discriminator("sharktype")
model Shark extends Fish {
kind: "shark";
origin: Origin;
}
// Access.internal
model Salmon extends Fish {
kind: "salmon";
}
// Access.internal
model SawShark extends Shark {
sharktype: "saw";
}
// Access.internal
model Origin {
country: string;
city: string;
manufacture: string;
}
// Access.internal
@get
@access(Access.internal)
op getModel(): Fish;
Access.internal
model Test1 {}
// Access.internal
@access(Access.internal)
@route("/func1")
op func1(@body body: Test1): void;
// Access.public
model Test2 {}
// Access.public
@route("/func2")
op func2(@body body: Test2): void;
// Access.public
model Test3 {}
// Access.public
@access(Access.public)
@route("/func3")
op func3(@body body: Test3): void;
// Access.public
model Test4 {}
// Access.internal
@access(Access.internal)
@route("/func4")
op func4(@body body: Test4): void;
// Access.public
@route("/func5")
op func5(@body body: Test4): void;
// Access.public
model Test5 {}
// Access.internal
@access(Access.internal)
@route("/func6")
op func6(@body body: Test5): void;
// Access.public
@route("/func7")
op func7(@body body: Test5): void;
// Access.public
@access(Access.public)
@route("/func8")
op func8(@body body: Test5): void;

Set an alternate type for a model property, Scalar, or function parameter. Note that @encode will be overridden by the one defined in the alternate type. When the source type is Scalar, the alternate type must be Scalar.

@Azure.ClientGenerator.Core.alternateType(alternate: unknown, scope?: valueof string)

The source type to which the alternate type will be applied. ModelProperty | Scalar

NameTypeDescription
alternateunknownThe alternate type to apply to the target.
scopevalueof stringSpecifies the target language emitters that the decorator should apply. If not set, the decorator will be applied to all language emitters by default.
You can use ”!” to exclude specific languages, for example: !(java, python) or !java, !python.
model Foo {
date: utcDateTime;
}
@@alternateType(Foo.date, string);
scalar storageDateTime extends utcDateTime;
@@alternateType(storageDateTime, string, "python");
op test(@param @alternateType(string) date: utcDateTime): void;
Change a model property to a different type with language specific alternate type
Section titled “Change a model property to a different type with language specific alternate type”
model Test {
@alternateType(unknown)
thumbprint?: string;
@alternateType(AzureLocation[], "csharp")
locations: string[];
}

Specify whether a parameter is an API version parameter or not. By default, we detect an API version parameter by matching the parameter name with api-version or apiversion, or if the type is referenced by the @versioned decorator. Since API versions are a client parameter, we will also elevate this parameter up onto the client. This decorator allows you to explicitly specify whether a parameter should be treated as an API version parameter or not.

@Azure.ClientGenerator.Core.apiVersion(value?: valueof boolean, scope?: valueof string)

The target parameter that you want to mark as an API version parameter. ModelProperty

NameTypeDescription
valuevalueof booleanIf true, we will treat this parameter as an api-version parameter. If false, we will not. Default is true.
scopevalueof stringSpecifies the target language emitters that the decorator should apply. If not set, the decorator will be applied to all language emitters by default.
You can use ”!” to exclude specific languages, for example: !(java, python) or !java, !python.
namespace Contoso;
op test(
@apiVersion
@header("x-ms-version")
version: string,
): void;
Mark a parameter as not presenting an API version parameter
Section titled “Mark a parameter as not presenting an API version parameter”
namespace Contoso;
op test(
@apiVersion(false)
@query
api-version: string
): void;

Define the client generated in the client SDK. If there is any @client definition or @operationGroup definition, then each @client is a root client and each @operationGroup is a sub client with hierarchy. This decorator cannot be used along with @clientLocation. This decorator cannot be used as augmentation.

@Azure.ClientGenerator.Core.client(options?: Azure.ClientGenerator.Core.ClientOptions, scope?: valueof string)

The target namespace or interface that you want to define as a client. Namespace | Interface

NameTypeDescription
optionsClientOptionsOptional configuration for the service.
scopevalueof stringSpecifies the target language emitters that the decorator should apply. If not set, the decorator will be applied to all language emitters by default.
You can use ”!” to exclude specific languages, for example: !(java, python) or !java, !python.
namespace MyService {
}
@client({
service: MyService,
})
interface MyInterface {}
namespace MyService {
}
@client({
service: MyService,
name: "MySpecialClient",
})
interface MyInterface {}

Specify additional API versions that the client can support. These versions should include those defined by the service’s versioning configuration. This decorator is useful for extending the API version enum exposed by the client. It is particularly beneficial when generating a complete API version enum without requiring the entire specification to be annotated with versioning decorators, as the generation process does not depend on versioning details.

@Azure.ClientGenerator.Core.clientApiVersions(value: Enum, scope?: valueof string)

The target client for which you want to define additional API versions. Namespace

NameTypeDescription
valueEnumIf true, we will treat this parameter as an api-version parameter. If false, we will not. Default is true.
scopevalueof stringSpecifies the target language emitters that the decorator should apply. If not set, the decorator will be applied to all language emitters by default.
You can use ”!” to exclude specific languages, for example: !(java, python) or !java, !python.
main.tsp
@versioned(Versions)
namespace Contoso {
enum Versions {
v4,
v5,
}
}
// client.tsp
enum ClientApiVersions {
v1,
v2,
v3,
...Contoso.Versions,
}
@@clientApiVersions(Contoso, ClientApiVersions);

Override documentation for a type in client libraries. This allows you to provide client-specific documentation that differs from the original documentation.

@Azure.ClientGenerator.Core.clientDoc(documentation: valueof string, mode: EnumMember, scope?: valueof string)

The target type (operation, model, enum, etc.) for which you want to apply client-specific documentation. unknown

NameTypeDescription
documentationvalueof stringThe client-specific documentation to apply
modeEnumMemberSpecifies how to apply the documentation (append or replace)
scopevalueof stringSpecifies the target language emitters that the decorator should apply. If not set, the decorator will be applied to all language emitters by default.
You can use ”!” to exclude specific languages, for example: !(java, python) or !java, !python.
@doc("This is service documentation")
@clientDoc("This is client-specific documentation", DocumentationMode.replace)
op myOperation(): void;
@doc("This is service documentation.")
@clientDoc("This additional note is for client libraries only.", DocumentationMode.append)
model MyModel {
prop: string;
}
@doc("This is service documentation")
@clientDoc("Python-specific documentation", DocumentationMode.replace, "python")
@clientDoc("JavaScript-specific documentation", DocumentationMode.replace, "javascript")
op myOperation(): void;

Allows customization of how clients are initialized in the generated SDK. By default, the root client is initialized independently, while sub clients are initialized through their parent client. Initialization parameters typically include endpoint, credential, and API version. With @clientInitialization decorator, you can elevate operation level parameters to client level, and set how the client is initialized. This decorator can be combined with @paramAlias decorator to change the parameter name in client initialization.

@Azure.ClientGenerator.Core.clientInitialization(options: Azure.ClientGenerator.Core.ClientInitializationOptions, scope?: valueof string)

The target client that you want to customize client initialization for. Namespace | Interface

NameTypeDescription
optionsClientInitializationOptionsThe options for client initialization. You can use ClientInitializationOptions model to set the options.
scopevalueof stringSpecifies the target language emitters that the decorator should apply. If not set, the decorator will be applied to all language emitters by default.
You can use ”!” to exclude specific languages, for example: !(java, python) or !java, !python.
main.tsp
namespace MyService;
op upload(blobName: string): void;
op download(blobName: string): void;
// client.tsp
namespace MyCustomizations;
model MyServiceClientOptions {
blobName: string;
}
@@clientInitialization(MyService, {parameters: MyServiceClientOptions})
// The generated client will have `blobName` in its initialization method. We will also
// elevate the existing `blobName` parameter from method level to client level.

Change the operation location in the client. If the target client is not defined, use string to indicate a new client name. This decorator allows you to change the client an operation belongs to in the client SDK. This decorator cannot be used along with @client or @operationGroup decorators.

@Azure.ClientGenerator.Core.clientLocation(target: Interface | Namespace | valueof string, scope?: valueof string)

The operation to change location for. Operation

NameTypeDescription
targetInterface | Namespace | valueof stringThe target Namespace, Interface or a string which can indicate the client.
scopevalueof stringSpecifies the target language emitters that the decorator should apply. If not set, the decorator will be applied to all language emitters by default.
You can use ”!” to exclude specific languages, for example: !(java, python) or !java, !python.
@service
namespace MoveToExistingSubClient;
interface UserOperations {
@route("/user")
@get
getUser(): void;
@route("/user")
@delete
@clientLocation(AdminOperations)
deleteUser(): void; // This operation will be moved to AdminOperations sub client.
}
interface AdminOperations {
@route("/admin")
@get
getAdminInfo(): void;
}
@service
namespace MoveToNewSubClient;
interface ProductOperations {
@route("/products")
@get
listProducts(): void;
@route("/products/archive")
@post
@clientLocation("ArchiveOperations")
archiveProduct(): void; // This operation will be moved to a new sub client named ArchiveOperations.
}
@service
namespace MoveToRootClient;
interface ResourceOperations {
@route("/resource")
@get
getResource(): void;
@route("/health")
@get
@clientLocation(MoveToRootClient)
getHealthStatus(): void; // This operation will be moved to the root client of MoveToRootClient namespace.
}

Changes the name of a client, method, parameter, union, model, enum, model property, etc. generated in the client SDK.

@Azure.ClientGenerator.Core.clientName(rename: valueof string, scope?: valueof string)

The type you want to rename. unknown

NameTypeDescription
renamevalueof stringThe rename you want applied to the object.
scopevalueof stringSpecifies the target language emitters that the decorator should apply. If not set, the decorator will be applied to all language emitters by default.
You can use ”!” to exclude specific languages, for example: !(java, python) or !java, !python.
@clientName("RenamedModel")
model TestModel {
prop: string;
}
model TestModel {
@clientName("renamedProp")
prop: string;
}
op example(@clientName("renamedParameter") parameter: string): void;
@clientName("nameInClient")
op example(): void;
@clientName("nameForJava", "java")
@clientName("name_for_python", "python")
@clientName("nameForCsharp", "csharp")
@clientName("nameForJavascript", "javascript")
op example(): void;

Changes the namespace of a client, model, enum or union generated in the client SDK. By default, the client namespace for them will follow the TypeSpec namespace.

@Azure.ClientGenerator.Core.clientNamespace(rename: valueof string, scope?: valueof string)

The type you want to change the namespace for. Namespace | Interface | Model | Enum | Union

NameTypeDescription
renamevalueof stringThe rename you want applied to the object
scopevalueof stringSpecifies the target language emitters that the decorator should apply. If not set, the decorator will be applied to all language emitters by default.
You can use ”!” to exclude specific languages, for example: !(java, python) or !java, !python.
@clientNamespace("ContosoClient")
namespace Contoso;
@clientNamespace("ContosoClient.Models")
model Test {
prop: string;
}

Whether you want to generate an operation as a convenient method.

@Azure.ClientGenerator.Core.convenientAPI(flag?: valueof boolean, scope?: valueof string)

The target operation. Operation

NameTypeDescription
flagvalueof booleanWhether to generate the operation as a convenience method or not.
scopevalueof stringSpecifies the target language emitters that the decorator should apply. If not set, the decorator will be applied to all language emitters by default.
You can use ”!” to exclude specific languages, for example: !(java, python) or !java, !python.
@convenientAPI(false)
op test: void;

Indicates that a model property of type string or a Scalar type derived from string should be deserialized as null when its value is an empty string ("").

@Azure.ClientGenerator.Core.deserializeEmptyStringAsNull(scope?: valueof string)

The target type that you want to apply this deserialization behavior to. ModelProperty

NameTypeDescription
scopevalueof stringSpecifies the target language emitters that the decorator should apply. If not set, the decorator will be applied to all language emitters by default.
You can use ”!” to exclude specific languages, for example: !(java, python) or !java, !python.
model MyModel {
scalar stringlike extends string;
@deserializeEmptyStringAsNull
prop: string;
@deserializeEmptyStringAsNull
prop: stringlike;
}

Set whether a model property should be flattened or not. This decorator is not recommended to use for green field services.

@Azure.ClientGenerator.Core.flattenProperty(scope?: valueof string)

The target model property that you want to flatten. ModelProperty

NameTypeDescription
scopevalueof stringSpecifies the target language emitters that the decorator should apply. If not set, the decorator will be applied to all language emitters by default.
You can use ”!” to exclude specific languages, for example: !(java, python) or !java, !python.
model Foo {
@flattenProperty
prop: Bar;
}
model Bar {}

Define the sub client generated in the client SDK. If there is any @client definition or @operationGroup definition, then each @client is a root client and each @operationGroup is a sub client with hierarchy. This decorator cannot be used along with @clientLocation. This decorator cannot be used as augmentation.

@Azure.ClientGenerator.Core.operationGroup(scope?: valueof string)

The target namespace or interface that you want to define as a sub client. Namespace | Interface

NameTypeDescription
scopevalueof stringSpecifies the target language emitters that the decorator should apply. If not set, the decorator will be applied to all language emitters by default.
You can use ”!” to exclude specific languages, for example: !(java, python) or !java, !python.
@operationGroup
interface MyInterface {}

Customize a method’s signature in the generated client SDK. Currently, only parameter signature customization is supported. This decorator allows you to specify a different method signature for the client SDK than the original definition.

@Azure.ClientGenerator.Core.override(override: Operation, scope?: valueof string)

: The target operation that you want to override. Operation

NameTypeDescription
overrideOperation: The override method definition that specifies the exact client method you want
scopevalueof stringSpecifies the target language emitters that the decorator should apply. If not set, the decorator will be applied to all language emitters by default.
You can use ”!” to exclude specific languages, for example: !(java, python) or !java, !python.
main.tsp
@service
namespace MyService;
op myOperation(foo: string, bar: string): void; // by default, we generate the method signature as `op myOperation(foo: string, bar: string)`;
// client.tsp
namespace MyCustomizations;
model Params {
foo: string;
bar: string;
}
op myOperationCustomization(params: MyService.Params): void;
@@override(MyService.myOperation, myOperationCustomization); // method signature is now `op myOperation(params: Params)`
main.tsp
@service
namespace MyService;
op myOperation(foo: string, bar?: string): void; // by default, we generate the method signature as `op myOperation(foo: string, bar?: string)`;
// client.tsp
namespace MyCustomizations;
op myOperationCustomization(foo: string, bar: string): void;
@@override(MyService.myOperation, myOperationCustomization)
// method signature is now `op myOperation(params: Params)` just for csharp // method signature is now `op myOperation(foo: string, bar: string)`

Alias the name of a client parameter to a different name. This permits you to have a different name for the parameter in client initialization and the original parameter in the operation.

@Azure.ClientGenerator.Core.paramAlias(paramAlias: valueof string, scope?: valueof string)

The target model property that you want to alias. ModelProperty

NameTypeDescription
paramAliasvalueof stringThe alias name you want to apply to the target model property.
scopevalueof stringSpecifies the target language emitters that the decorator should apply. If not set, the decorator will be applied to all language emitters by default.
You can use ”!” to exclude specific languages, for example: !(java, python) or !java, !python.
Elevate an operation parameter to client level and alias it to a different name
Section titled “Elevate an operation parameter to client level and alias it to a different name”
main.tsp
namespace MyService;
op upload(blobName: string): void;
// client.tsp
namespace MyCustomizations;
model MyServiceClientOptions {
blob: string;
}
@@clientInitialization(MyService, MyServiceClientOptions)
@@paramAlias(MyServiceClientOptions.blob, "blobName")
// The generated client will have `blobName` in it. We will also
// elevate the existing `blob` parameter to the client level.

Whether you want to generate an operation as a protocol method.

@Azure.ClientGenerator.Core.protocolAPI(flag?: valueof boolean, scope?: valueof string)

The target operation. Operation

NameTypeDescription
flagvalueof booleanWhether to generate the operation as a protocol method or not.
scopevalueof stringSpecifies the target language emitters that the decorator should apply. If not set, the decorator will be applied to all language emitters by default.
You can use ”!” to exclude specific languages, for example: !(java, python) or !java, !python.
@protocolAPI(false)
op test: void;

Indicates that a HEAD operation should be modeled as Response. 404 will not raise an error, instead the service method will return false. 2xx will return true. Everything else will still raise an error.

@Azure.ClientGenerator.Core.responseAsBool(scope?: valueof string)

The target operation that you want to apply this behavior to. Operation

NameTypeDescription
scopevalueof stringSpecifies the target language emitters that the decorator should apply. If not set, the decorator will be applied to all language emitters by default.
You can use ”!” to exclude specific languages, for example: !(java, python) or !java, !python.
@responseAsBool
@head
op headOperation(): void;

Define the scope of an operation. By default, the operation will be applied to all language emitters. This decorator allows you to omit the operation from certain languages or apply it to specific languages.

@Azure.ClientGenerator.Core.scope(scope?: valueof string)

The target operation that you want to scope. Operation

NameTypeDescription
scopevalueof stringSpecifies the target language emitters that the decorator should apply. If not set, the decorator will be applied to all language emitters by default.
You can use ”!” to exclude specific languages, for example: !(java, python) or !java, !python.
@scope("!csharp")
op test: void;
@scope("go")
op test: void;

Add usage for models/enums. A model/enum’s default usage info is always calculated by the operations that use it. You can use this decorator to add additional usage info. When setting usage for namespaces, the usage info will be propagated to the models defined in the namespace. If the model has a usage override, the model override takes precedence. For example, with operation definition op test(): OutputModel, the model OutputModel has default usage Usage.output. After adding decorator @@usage(OutputModel, Usage.input | Usage.json), the final usage result for OutputModel is Usage.input | Usage.output | Usage.json. The usage info for models will be propagated to models’ properties, parent models, discriminated sub models.

@Azure.ClientGenerator.Core.usage(value: EnumMember | Union, scope?: valueof string)

The target type you want to extend usage. Model | Enum | Union | Namespace

NameTypeDescription
valueEnumMember | UnionThe usage info you want to add for this model. It can be a single value of Usage enum value or a combination of Usage enum values using bitwise OR.
For example, Usage.input | Usage.output | Usage.json.
scopevalueof stringSpecifies the target language emitters that the decorator should apply. If not set, the decorator will be applied to all language emitters by default.
You can use ”!” to exclude specific languages, for example: !(java, python) or !java, !python.
op test(): OutputModel;
// The resolved usage for `OutputModel` is `Usage.input | Usage.output | Usage.json`
@usage(Usage.input | Usage.json)
model OutputModel {
prop: string;
}
Propagation of usage, all usage will be propagated to the parent model, discriminated sub models, and model properties.
Section titled “Propagation of usage, all usage will be propagated to the parent model, discriminated sub models, and model properties.”
// The resolved usage for `Fish` is `Usage.input | Usage.output | Usage.json`
@discriminator("kind")
model Fish {
age: int32;
}
// The resolved usage for `Shark` is `Usage.input | Usage.output | Usage.json`
@discriminator("sharktype")
@usage(Usage.input | Usage.json)
model Shark extends Fish {
kind: "shark";
origin: Origin;
}
// The resolved usage for `Salmon` is `Usage.output | Usage.json`
model Salmon extends Fish {
kind: "salmon";
}
// The resolved usage for `SawShark` is `Usage.input | Usage.output | Usage.json`
model SawShark extends Shark {
sharktype: "saw";
}
// The resolved usage for `Origin` is `Usage.input | Usage.output | Usage.json`
model Origin {
country: string;
city: string;
manufacture: string;
}
@get
op getModel(): Fish;

Whether a model needs the custom JSON converter, this is only used for backward compatibility for csharp.

@Azure.ClientGenerator.Core.useSystemTextJsonConverter(scope?: valueof string)

The target model that you want to set the custom JSON converter. Model

NameTypeDescription
scopevalueof stringSpecifies the target language emitters that the decorator should apply. If not set, the decorator will be applied to all language emitters by default.
You can use ”!” to exclude specific languages, for example: !(java, python) or !java, !python.
@useSystemTextJsonConverter
model MyModel {
prop: string;
}