Skip to content

Commit

Permalink
add test_pydantic_model_with_keyword_property
Browse files Browse the repository at this point in the history
  • Loading branch information
lecko-cngroup committed Sep 25, 2024
1 parent 102945e commit deed104
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/asyncapi/base/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,33 @@ async def handle(user: User): ...
"type": "object",
}

def test_pydantic_model_with_keyword_property(self):
class TestModel(pydantic.BaseModel):
discriminator: int = 0

broker = self.broker_class()

@broker.subscriber("test")
async def handle(user: TestModel): ...

schema = get_app_schema(self.build_app(broker)).to_jsonable()

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

for key, v in payload.items():
assert key == "TestModel"
assert v == {
"properties": {
"discriminator": {
"default": 0,
"title": "Discriminator",
"type": "integer"
},
},
"title": key,
"type": "object",
}

def test_ignores_depends(self):
broker = self.broker_class()

Expand Down
26 changes: 26 additions & 0 deletions tests/asyncapi/base/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,29 @@ async def handler(msg: str):
schema = get_app_schema(self.build_app(broker))

assert schema.channels == {}, schema.channels

def test_pydantic_model_with_keyword_property_publisher(self):
class TestModel(pydantic.BaseModel):
discriminator: int = 0

broker = self.broker_class()

@broker.publisher("test")
async def handle(msg) -> TestModel: ...

schema = get_app_schema(self.build_app(broker)).to_jsonable()

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

for key, v in payload.items():
assert v == {
"properties": {
"discriminator": {
"default": 0,
"title": "Discriminator",
"type": "integer",
},
},
"title": key,
"type": "object",
}

0 comments on commit deed104

Please sign in to comment.