Expand description
@typespec/openapi - OpenAPI Decorators and Types
Ported from TypeSpec packages/openapi
Provides decorators for OpenAPI-specific annotations:
@operationId- Set a specific operation ID@extension- Add OpenAPI extension (x-* properties)@defaultResponse- Mark a model as default response@externalDocs- Add external documentation link@info- Set OpenAPI info object@tagMetadata- Add metadata to a tag
§Types
ExtensionKey- Type for OpenAPI extension keys (must start with “x-”)AdditionalInfo- OpenAPI info objectExternalDocs- External documentationContact,License- Info sub-types
Structs§
- Additional
Info - OpenAPI additional information. Ported from TS AdditionalInfo interface.
- Contact
- Contact information for the API. Ported from TS Contact interface.
- External
Docs - External documentation. Ported from TS ExternalDocs interface.
- License
- License information for the API. Ported from TS License interface.
- TagMetadata
- Tag metadata for OpenAPI tags. Ported from TS TagMetadata type.
Constants§
- OPENAPI_
DECORATORS_ TSP - The TypeSpec source for the OpenAPI library
- OPENAPI_
NAMESPACE - Namespace for OpenAPI types
- STATE_
DEFAULT_ RESPONSE - State key for @defaultResponse decorator
- STATE_
EXTENSION - State key for OpenAPI extensions
- STATE_
EXTERNAL_ DOCS - State key for @externalDocs decorator
- STATE_
INFO - State key for @info decorator
- STATE_
OPERATION_ ID - State key for @operationId decorator
- STATE_
TAG_ METADATA - State key for @tagMetadata decorator
Functions§
- apply_
default_ response - Apply decorator (flag - no value).
- apply_
extension - Apply @extension decorator. Stores as “x-keyname::value” format, supporting multiple extensions. Ported from TS $extension().
- apply_
external_ docs - Apply @externalDocs decorator. Ported from TS $externalDocs().
- apply_
info - Apply @info decorator - set OpenAPI info object for a namespace. Ported from TS $info() / setInfo(). The info data is serialized as a simple format for state storage.
- apply_
operation_ id - Apply decorator (string value).
- apply_
tag_ metadata - Apply @tagMetadata decorator - add metadata to a tag for a namespace.
Ported from TS tagMetadataDecorator().
Tags are stored as “tagName<>description<>url<>parent” format with “<>” as sub-separator,
and “||” as entry separator, avoiding conflict with
|in URLs. - create_
openapi_ library - Create the OpenAPI library diagnostic map.
- get_
extension - Get a specific extension value by key.
- get_
extensions - Get all extensions for a type. Ported from TS getExtensions().
- get_
external_ docs - Get external docs for a type. Ported from TS getExternalDocs().
- get_
info - Get the OpenAPI info object for a namespace. Ported from TS getInfo().
- get_
operation_ id - Get decorator value.
- get_
tag_ metadata - Get all tag metadata for a namespace. Ported from TS getTagsMetadata().
- is_
default_ response - Check if decorator is applied.
- is_
valid_ extension_ key - Check if a string is a valid OpenAPI extension key (must start with “x-”).
- is_
valid_ url - Validate a URL string (basic check).