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
3.08k stars 157 forks source link

Bug: AsyncAPI 2.6.0 schema ignores messages schema overriding #1625

Open KrySeyt opened 3 months ago

KrySeyt commented 3 months ago

Describe the bug 1) In some way you describe the message, for example:

@dataclass
class Input:
    value: int

2) Describe the handler with this message:

@broker.subscriber("in1")
async def handle_msg(a: Input) -> None: ...

3) Override your message:

@dataclass
class Input:
    not_in_schema: str

4) Describe the handler with overrided message:

@broker.subscriber("in2")
async def please_good_schema(a: Input) -> None: ...

5) Create asyncapi schema and look at #/components/schemas

"schemas": {
      "Input": {
        "properties": {
          "value": {
            "title": "Value",
            "type": "integer"
          }
        },
        "required": [
          "value"
        ],
        "title": "Input",
        "type": "object"
      }
    }

Where is my Input.not_in_schema: str? For example, it will be a problem if I have the same named dataclasses in different packages

How to reproduce

from dataclasses import dataclass

from faststream import FastStream
from faststream.rabbit import RabbitBroker

broker = RabbitBroker()

app = FastStream(broker)

@dataclass
class Input:
    value: int

@broker.subscriber("in1")
async def handle_msg(a: Input) -> None: ...

@dataclass
class Input:
    not_in_schema: str

@broker.subscriber("in2")
async def please_good_schema(a: Input) -> None: ...

And/Or steps to reproduce the behavior:

  1. faststream docs get main:app

Expected behavior I expect two payload in schema:

Observed behavior Message "overriding" just ignored, in the schema all handlers use only the first definition of the message

Environment Running FastStream 0.5.15 with CPython 3.12.3 on Linux

Additional context Same problem in the case of handlers + args names duplication:

@broker.subscriber("in1")
async def handle_msg(a: int) -> None: ...

@broker.subscriber("in2")
async def handle_msg(a: str) -> None: ...
"schemas": {
  "HandleMsg:Message:Payload": {
    "title": "HandleMsg:Message:Payload",
    "type": "integer"
  }
}
KrySeyt commented 2 months ago

Warning should be good solution