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.52k stars 128 forks source link

Provide optional "description" argument to consumes and produces decorator #323

Closed Gerleff closed 1 year ago

Gerleff commented 1 year ago

In team we have the rule to document code basis in Russian, but all the docs we provide must be in English. Autogeneration of docs is using doc attribute of function to generate description.

Current way to achieve the goal:

@producers_router.produces(topic="transaction.response.order_status")
async def exchange_orders_status_producer(message: OrderStatus) -> OrderStatus:
    """Продюсер по топику transaction.response.order_status."""
    return message

exchange_orders_status_producer.__doc__ = "Publish exchange_order's status"

Preferable solution:

@producers_router.produces(topic="transaction.response.order_status", description="Publish order status")
async def exchange_orders_status_producer(message: OrderStatus) -> OrderStatus:
    """Продюсер по топику transaction.response.order_status."""
    return message

Thanks for response =)

Gerleff commented 1 year ago

Works well for consumers, and does not for producers.

sternakt commented 1 year ago

I'll reopen the issue, see what went wrong and we'll do a patch for this in the next couple of days.

Thanks for the quick feedback :)

sternakt commented 1 year ago

Can you please explain further what is failing for the producers, with code examples if possible.

For a simple app example:

...
app = FastKafka(kafka_brokers=kafka_brokers)

@app.produces(description="Producer description in documentation")
async def to_hello_world(msg: str) -> HelloWorld:
    """This description should not show"""
    return HelloWorld(msg=msg)

The description "Producer description in documentation" is shown in the async docs for the producer.

Gerleff commented 1 year ago

Checked out more precisely, everything works as expected! Seems like browser caches web app, served by "fastkafka docs serve" command