Schema generation¶
from litestar_asyncapi.asyncapi.schema_generation import AsyncAPISchemaGenerator
from litestar_asyncapi.asyncapi.schema_generation.dialect import to_asyncapi_schema
Payload and header schemas come from Litestar's own schema generation, with a registry that belongs to one document build. The result is exported as JSON Schema Draft07, the default schema format of AsyncAPI 3.
Schema generator¶
litestar_asyncapi.asyncapi.schema_generation.AsyncAPISchemaGenerator
¶
Generate AsyncAPI schemas through a fresh native Litestar schema registry.
generate(type_or_field: Any, *, provenance: str | None = None) -> dict[str, Any] | bool
¶
Generate a payload schema, retaining native references until component finalization.
components() -> dict[str, Any]
¶
Finalize native component names and update previously returned reference dictionaries.
declared_examples(type_or_field: Any) -> list[Any] | None
¶
Read native schema example declarations without finalizing components.
Draft07 export¶
litestar_asyncapi.asyncapi.schema_generation.dialect.to_asyncapi_schema(value: Mapping[str, Any] | bool) -> dict[str, Any] | bool
¶
Export modern schema keywords to native AsyncAPI Draft07 semantics.
Only schema positions are traversed. Literal examples, defaults, constants, enumerations and extensions remain data. Explicit MultiFormatSchema objects must bypass this adapter at the integration boundary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Mapping[str, Any] | bool
|
A schema mapping or boolean schema. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | bool
|
An independent Draft07-compatible schema. |
Raises:
| Type | Description |
|---|---|
ImproperlyConfiguredException
|
If a keyword cannot preserve its meaning in Draft07, or a schema position has an invalid shape. |