Decorators
TypeSpec.Http
@body
Explicitly specify that this property type will be exactly the HTTP body.
This means that any properties under @body
cannot be marked as headers, query parameters, or path parameters.
If wanting to change the resolution of the body but still mix parameters, use @bodyRoot
.
Target
ModelProperty
Parameters
None
Examples
@bodyIgnore
Specify that this property shouldn’t be included in the HTTP body. This can be useful when bundling metadata together that would result in an empty property to be included in the body.
Target
ModelProperty
Parameters
None
Examples
@bodyRoot
Specify that the body resolution should be resolved from that property. By default the body is resolved by including all properties in the operation request/response that are not metadata. This allows to nest the body in a property while still allowing to use headers, query parameters, and path parameters in the same model.
Target
ModelProperty
Parameters
None
Examples
@cookie
Specify this property is to be sent or received in the cookie.
Target
ModelProperty
Parameters
Name | Type | Description |
---|---|---|
cookieNameOrOptions | valueof string | TypeSpec.Http.CookieOptions | Optional name of the cookie in the cookie or cookie options. By default the cookie name will be the property name converted from camelCase to snake_case. (e.g. authToken -> auth_token ) |
Examples
Implicit header name
@delete
Specify the HTTP verb for the target operation to be DELETE
.
Target
Operation
Parameters
None
Examples
@get
Specify the HTTP verb for the target operation to be GET
.
Target
Operation
Parameters
None
Examples
@head
Specify the HTTP verb for the target operation to be HEAD
.
Target
Operation
Parameters
None
Examples
@header
Specify this property is to be sent or received as an HTTP header.
Target
ModelProperty
Parameters
Name | Type | Description |
---|---|---|
headerNameOrOptions | string | TypeSpec.Http.HeaderOptions | Optional name of the header when sent over HTTP or header options. By default the header name will be the property name converted from camelCase to kebab-case. (e.g. contentType -> content-type ) |
Examples
Implicit header name
@includeInapplicableMetadataInPayload
Specify if inapplicable metadata should be included in the payload for the given entity.
Target
unknown
Parameters
Name | Type | Description |
---|---|---|
value | valueof boolean | If true, inapplicable metadata will be included in the payload. |
@multipartBody
Target
ModelProperty
Parameters
None
Examples
@patch
Specify the HTTP verb for the target operation to be PATCH
.
Target
Operation
Parameters
None
Examples
@path
Explicitly specify that this property is to be interpolated as a path parameter.
Target
ModelProperty
Parameters
Name | Type | Description |
---|---|---|
paramNameOrOptions | valueof string | TypeSpec.Http.PathOptions | Optional name of the parameter in the uri template or options. |
Examples
@post
Specify the HTTP verb for the target operation to be POST
.
Target
Operation
Parameters
None
Examples
@put
Specify the HTTP verb for the target operation to be PUT
.
Target
Operation
Parameters
None
Examples
@query
Specify this property is to be sent as a query parameter.
Target
ModelProperty
Parameters
Name | Type | Description |
---|---|---|
queryNameOrOptions | valueof string | TypeSpec.Http.QueryOptions | Optional name of the query when included in the url or query parameter options. |
Examples
@route
Defines the relative route URI template for the target operation as defined by RFC 6570
@route
can only be applied to operations, namespaces, and interfaces.
Target
Namespace | Interface | Operation
Parameters
Name | Type | Description |
---|---|---|
path | valueof string | |
options | {...} | DEPRECATED Set of parameters used to configure the route. Supports {shared: true} which indicates that the route may be shared by several operations. |
Examples
Simple path parameter
Reserved characters
Query parameter
@server
Specify an endpoint for this service. Multiple @server
decorators can be used to specify multiple endpoints.
Target
Namespace
Parameters
Name | Type | Description |
---|---|---|
url | valueof string | Server endpoint |
description | valueof string | Description of the endpoint |
parameters | Record<unknown> | Optional set of parameters used to interpolate the url. |
Examples
With a description
Parameterized
Multiple
@sharedRoute
@sharedRoute
marks the operation as sharing a route path with other operations.
When an operation is marked with @sharedRoute
, it enables other operations to share the same
route path as long as those operations are also marked with @sharedRoute
.
@sharedRoute
can only be applied directly to operations.
Target
Operation
Parameters
None
@statusCode
Specify the status code for this response. Property type must be a status code integer or a union of status code integer.
Target
ModelProperty
Parameters
None
Examples
@useAuth
Specify authentication for a whole service or specific methods. See the documentation in the Http library for full details.
Target
Namespace | Interface | Operation
Parameters
Name | Type | Description |
---|---|---|
auth | {} | Union | {}[] | Authentication configuration. Can be a single security scheme, a union(either option is valid authentication) or a tuple (must use all authentication together) |