airtai / faststream

FastStream is a powerful and easy-to-use Python framework for building asynchronous services interacting with event streams such as Apache Kafka, RabbitMQ, NATS and Redis.
https://faststream.airt.ai/latest/
Apache License 2.0
2.51k stars 128 forks source link

Bug: Title tag including "/" breaks asyncapi schema generation/hosting #1780

Closed oyste closed 3 weeks ago

oyste commented 3 weeks ago

Describe the bug When using publisher/subscriber decorators with a title prop on redis fastapi plugin routers the asyncapi schema generation can fail. This happens specifically when I use "/" in a title name and leads to a blank asyncapi webpage.

How to reproduce This code fails:

from fastapi.responses import HTMLResponse
from faststream.asyncapi import get_app_schema, get_asyncapi_html
from faststream.redis.fastapi import RedisRouter

router = RedisRouter(url=REDIS_URL, prefix="/websocket", tags=["websocket"])

@router.publisher("datastream", title="websocket/datastream", schema=WsMessageDatastreamResponse)
@router.subscriber("datastream", title="websocket/datastream")
async def datastream_func(auth: WsMessageDatastream):
    pass

@router.get("/new_docs")
async def asyncapi_ui_new() -> HTMLResponse:
    return HTMLResponse(get_asyncapi_html(get_app_schema(router), expand_message_examples=False))

however swapping "/" to ":" makes everything work:

@router.publisher("datastream", title="websocket:datastream", schema=WsMessageDatastreamResponse)
@router.subscriber("datastream", title="websocket:datastream")
async def datastream_func(auth: WsMessageDatastream):
    pass

Expected behavior No blank webpage when using "/" in a pubsub decorator title.

Observed behavior Blank Webpage

Screenshots If applicable, attach screenshots to help illustrate the problem.

Environment Running FastStream 0.5.23 with CPython 3.12.5 on Linux

Additional context Could probably be fixed with a regex check somewhere.

KrySeyt commented 2 weeks ago

It will be nice if there is not an empty page, but a description of the error - https://github.com/asyncapi/asyncapi-react/issues/1048