Skip to content

Decorators

Specify this operation is an action. (Scoped to a resource item /pets/{petId}/my-action)

@TypeSpec.Rest.action(name?: valueof string)

Operation

NameTypeDescription
namevalueof stringName of the action. If not specified, the name of the operation will be used.

Defines the separator string that is inserted before the action name in auto-generated routes for actions.

@TypeSpec.Rest.actionSeparator(seperator: valueof "/" | ":" | "/:")

Model | ModelProperty | Operation

NameTypeDescription
seperatorvalueof "/" | ":" | "/:"Seperator seperating the action segment from the rest of the url

This interface or operation should resolve its route automatically. To be used with resource types where the route segments area defined on the models.

@TypeSpec.Rest.autoRoute

Interface | Operation

None

@autoRoute
interface Pets {
get(@segment("pets") @path id: string): void; //-> route: /pets/{id}
}

Specify this operation is a collection action. (Scopped to a resource, /pets/my-action)

@TypeSpec.Rest.collectionAction(resourceType: Model, name?: valueof string)

Operation

NameTypeDescription
resourceTypeModelResource marked with
namevalueof stringName of the action. If not specified, the name of the operation will be used.

Copy the resource key parameters on the model

@TypeSpec.Rest.copyResourceKeyParameters(filter?: valueof string)

Model

NameTypeDescription
filtervalueof stringFilter to exclude certain properties.

Specify that this is a CreateOrReplace operation for a given resource.

@TypeSpec.Rest.createsOrReplacesResource(resourceType: Model)

Operation

NameTypeDescription
resourceTypeModelResource marked with

Specify that this is a CreatesOrUpdate operation for a given resource.

@TypeSpec.Rest.createsOrUpdatesResource(resourceType: Model)

Operation

NameTypeDescription
resourceTypeModelResource marked with

Specify that this is a Create operation for a given resource.

@TypeSpec.Rest.createsResource(resourceType: Model)

Operation

NameTypeDescription
resourceTypeModelResource marked with

Specify that this is a Delete operation for a given resource.

@TypeSpec.Rest.deletesResource(resourceType: Model)

Operation

NameTypeDescription
resourceTypeModelResource marked with

Specify that this is a List operation for a given resource.

@TypeSpec.Rest.listsResource(resourceType: Model)

Operation

NameTypeDescription
resourceTypeModelResource marked with

Mark model as a child of the given parent resource.

@TypeSpec.Rest.parentResource(parent: Model)

Model

NameTypeDescription
parentModelParent model.

Specify that this is a Read operation for a given resource.

@TypeSpec.Rest.readsResource(resourceType: Model)

Operation

NameTypeDescription
resourceTypeModelResource marked with

Mark this model as a resource type with a name.

@TypeSpec.Rest.resource(collectionName: valueof string)

Model

NameTypeDescription
collectionNamevalueof stringtype’s collection name

Defines the preceding path segment for a

@TypeSpec.Rest.segment(name: valueof string)

Model | ModelProperty | Operation

NameTypeDescription
namevalueof stringSegment that will be inserted into the operation route before the path parameter’s name field.

Returns the URL segment of a given model if it has @segment and @key decorator.

@TypeSpec.Rest.segmentOf(type: Model)

Operation

NameTypeDescription
typeModelTarget model

Specify that this is a Update operation for a given resource.

@TypeSpec.Rest.updatesResource(resourceType: Model)

Operation

NameTypeDescription
resourceTypeModelResource marked with