def get_app_schema(
*brokers: "BrokerUsecase[Any, Any]",
title: str,
app_version: str,
schema_version: str,
description: str | None,
terms_of_service: Optional["AnyHttpUrl"],
contact: Union["SpecContact", "ContactDict", dict[str, Any]] | None,
license: Union["SpecLicense", "LicenseDict", dict[str, Any]] | None,
identifier: str | None,
tags: Sequence[Union["SpecTag", "TagDict", dict[str, Any]]],
external_docs: Union["SpecDocs", "ExternalDocsDict", dict[str, Any]] | None,
http_handlers: list[tuple[str, "HttpHandler"]],
) -> ApplicationSchema:
"""Get the application schema."""
if any(br.specification.security for br in brokers):
list_of_specification_security = (
br.specification.security.get_schema()
for br in brokers
if br.specification.security
)
security_schemes = convert_list_of_dict_to_dict(
list_of_specification_security,
"specification security",
)
else:
security_schemes = None
servers, broker_servers = get_broker_server(*brokers)
channels = convert_list_of_dict_to_dict(
(get_broker_channels(br, servers=srv) for br, srv in broker_servers.items()),
"channel",
)
channels.update(get_asgi_routes(http_handlers))
messages: dict[str, Message] = {}
payloads: dict[str, dict[str, Any]] = {}
for channel_name, ch in channels.items():
resolve_channel_messages(ch, channel_name, payloads, messages)
return ApplicationSchema(
info=ApplicationInfo(
title=title,
version=app_version,
description=description,
termsOfService=terms_of_service,
contact=Contact.from_spec(contact),
license=License.from_spec(license),
),
tags=[Tag.from_spec(tag) for tag in tags] or None,
externalDocs=ExternalDocs.from_spec(external_docs),
asyncapi=schema_version,
defaultContentType=ContentTypes.JSON.value,
id=identifier,
servers=servers,
channels=channels,
components=Components(
messages=messages,
schemas=payloads,
securitySchemes=security_schemes,
),
)