Skip to main content

Module openapi

Module openapi 

Source
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 object
  • ExternalDocs - External documentation
  • Contact, License - Info sub-types

Structs§

AdditionalInfo
OpenAPI additional information. Ported from TS AdditionalInfo interface.
Contact
Contact information for the API. Ported from TS Contact interface.
ExternalDocs
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).