Skip to content

Decorators

Specify that this model is to be treated as the OpenAPI default response. This differs from the compiler built-in @error decorator as this does not necessarily represent an error.

@TypeSpec.OpenAPI.defaultResponse

Model

None

@defaultResponse
model PetStoreResponse is object;
op listPets(): Pet[] | PetStoreResponse;

Attach some custom data to the OpenAPI element generated from this type.

@TypeSpec.OpenAPI.extension(key: valueof string, value: valueof unknown)

unknown

NameTypeDescription
keyvalueof stringExtension key.
valuevalueof unknownExtension value.
@extension("x-custom", "My value")
@extension("x-pageable", #{ nextLink: "x-next-link" })
op read(): string;

Specify the OpenAPI externalDocs property for this type.

@TypeSpec.OpenAPI.externalDocs(url: valueof string, description?: valueof string)

unknown

NameTypeDescription
urlvalueof stringUrl to the docs
descriptionvalueof stringDescription of the docs
@externalDocs(
"https://example.com/detailed.md",
"Detailed information on how to use this operation"
)
op listPets(): Pet[];

Specify OpenAPI additional information. The service title is already specified using @service.

@TypeSpec.OpenAPI.info(additionalInfo: valueof TypeSpec.OpenAPI.AdditionalInfo)

Namespace

NameTypeDescription
additionalInfovalueof AdditionalInfoAdditional information

Specify the OpenAPI operationId property for this operation.

@TypeSpec.OpenAPI.operationId(operationId: valueof string)

Operation

NameTypeDescription
operationIdvalueof stringOperation id value.
@operationId("download")
op read(): string;

Specify OpenAPI tag metadata. Can be used in two forms:

  • Inline form: specify a single tag by name with optional metadata.
  • Array form: specify an ordered list of tags with their metadata in a single decorator call.
@TypeSpec.OpenAPI.tagMetadata(name: valueof string | TypeSpec.OpenAPI.TagMetadataWithName[], tagMetadata?: valueof TypeSpec.OpenAPI.TagMetadata)

Namespace

NameTypeDescription
namevalueof string | TypeSpec.OpenAPI.TagMetadataWithName[]Tag name (inline form) or array of tags with metadata (array form).
tagMetadatavalueof TagMetadataAdditional information for the tag. Only used in inline form.
@service
@tagMetadata(
"Tag Name",
#{
description: "Tag description",
externalDocs: #{ url: "https://example.com", description: "More info.", `x-custom`: "string" },
`x-custom`: "string",
}
)
@tagMetadata("Child Tag", #{ description: "Child tag description", parent: "Tag Name" })
namespace PetStore {
}
@service
@tagMetadata(#[
#{ name: "First Tag", description: "First tag description" },
#{ name: "Second Tag", description: "Second tag description" }
])
namespace PetStore {
}