Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,32 @@ async def handler(request: web.Request, *, query: QueryArgs) -> APIResponse[int]
assert result[1]["type"] == "string_type"


async def test_query_literal(aiohttp_client: AiohttpClient) -> None:
schema_gen = SchemaGenerator()

class QueryArgs(TypedDict):
foo: Literal[42, "spam"]

@schema_gen.api()
async def handler(request: web.Request, *, query: QueryArgs) -> APIResponse[int]:
return APIResponse(query["foo"])

app = web.Application()
schema_gen.setup(app)
app.router.add_get("/foo", handler)

client = await aiohttp_client(app)
async with client.get("/foo", params={"foo": 42}) as resp:
assert resp.status == 200
result = await resp.json()
assert result == 42

async with client.get("/foo", params={"foo": "spam"}) as resp:
assert resp.status == 200
result = await resp.json()
assert result == "spam"


async def test_query_pydantic_annotations(aiohttp_client: AiohttpClient) -> None:
schema_gen = SchemaGenerator()

Expand Down
Loading