Skip to content

bug: Nested Pydantic model are not included in AsyncAPI components/schemas (inplaced instead) #2443

Description

@legau

Describe the bug
With AsyncAPI 3.0, when registering multiple handlers on the same publishers with some of the return types having nested Pydantic models inside them, these nested models are not defined correctly in the AsyncAPI spec resulting in an invalid state (the model referenced does not exist)

How to reproduce
Include source code:

class User(pydantic.BaseModel):
    class Email(pydantic.BaseModel):
        email: str

    email: Email
    name: str = ""
    id: int
    

broker = self.broker_class()

publisher = broker.publisher("test")

@publisher
def handle0(msg) -> User:
    ...


class Other(pydantic.BaseModel):
    id: int

@publisher
def handle1(msg) -> Other:
    ...

schema = self.get_spec(broker).to_jsonable()

payload = schema["components"]["schemas"]

assert "User" in payload
assert "Other" in payload

assert "Email" in payload # <-- Assert fails

Expected behavior
The AsyncAPI schema should be valid.

Environment
main branch / 0.6.0rc0

Additional context
I will try to find a workaround/bugfix for now

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions