Skip to content

Schema

faststream.asyncapi.schema.main.Schema #

Bases: BaseModel

A class to represent a schema.

ATTRIBUTE DESCRIPTION
asyncapi

version of the async API

id

optional ID

defaultContentType

optional default content type

info

information about the schema

servers

optional dictionary of servers

channels

dictionary of channels

components

optional components of the schema

tags

optional list of tags

externalDocs

optional external documentation

METHOD DESCRIPTION
to_jsonable

Convert the schema to a JSON-serializable object.

to_json

Convert the schema to a JSON string.

to_yaml

Convert the schema to a YAML string.

asyncapi class-attribute instance-attribute #

asyncapi = ASYNC_API_VERSION

id class-attribute instance-attribute #

id = None

defaultContentType class-attribute instance-attribute #

defaultContentType = None

info instance-attribute #

info

servers class-attribute instance-attribute #

servers = None

channels instance-attribute #

channels

components class-attribute instance-attribute #

components = None

tags class-attribute instance-attribute #

tags = None

externalDocs class-attribute instance-attribute #

externalDocs = None

to_jsonable #

to_jsonable()

Convert the schema to a JSON-serializable object.

Source code in faststream/asyncapi/schema/main.py
def to_jsonable(self) -> Any:
    """Convert the schema to a JSON-serializable object."""
    return model_to_jsonable(
        self,
        by_alias=True,
        exclude_none=True,
    )

to_json #

to_json()

Convert the schema to a JSON string.

Source code in faststream/asyncapi/schema/main.py
def to_json(self) -> str:
    """Convert the schema to a JSON string."""
    return model_to_json(
        self,
        by_alias=True,
        exclude_none=True,
    )

to_yaml #

to_yaml()

Convert the schema to a YAML string.

Source code in faststream/asyncapi/schema/main.py
def to_yaml(self) -> str:
    """Convert the schema to a YAML string."""
    from io import StringIO

    import yaml

    io = StringIO(initial_value="", newline="\n")
    yaml.dump(self.to_jsonable(), io, sort_keys=False)
    return io.getvalue()