|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | | -from typing import Generic, TypeVar, List, Optional |
| 3 | +from typing import Generic, TypeVar, List, Optional, Tuple, Literal |
4 | 4 |
|
5 | 5 | from pydantic import BaseModel, Field |
6 | 6 |
|
@@ -543,3 +543,31 @@ def endpoint_test(): |
543 | 543 | data = test_app.api_doc["paths"]["/test"]["post"] |
544 | 544 |
|
545 | 545 | assert "deprecated" not in data |
| 546 | + |
| 547 | + |
| 548 | +class TupleModel(BaseModel): |
| 549 | + my_tuple: Tuple[Literal["a", "b"], Literal["c", "d"]] |
| 550 | + |
| 551 | + |
| 552 | +def test_prefix_items(request): |
| 553 | + test_app = OpenAPI(request.node.name) |
| 554 | + test_app.config["TESTING"] = True |
| 555 | + |
| 556 | + @test_app.post("/test") |
| 557 | + def endpoint_test(body: TupleModel): |
| 558 | + print([]) # pragma: no cover |
| 559 | + |
| 560 | + schema = test_app.api_doc["paths"]["/test"]["post"]["requestBody"]["content"]["application/json"]["schema"] |
| 561 | + assert schema == {'$ref': '#/components/schemas/TupleModel'} |
| 562 | + components = test_app.api_doc["components"]["schemas"] |
| 563 | + assert components["TupleModel"] == {'properties': {'my_tuple': {'maxItems': 2, |
| 564 | + 'minItems': 2, |
| 565 | + 'prefixItems': [{'enum': ['a', 'b'], |
| 566 | + 'type': 'string'}, |
| 567 | + {'enum': ['c', 'd'], |
| 568 | + 'type': 'string'}], |
| 569 | + 'title': 'My Tuple', |
| 570 | + 'type': 'array'}}, |
| 571 | + 'required': ['my_tuple'], |
| 572 | + 'title': 'TupleModel', |
| 573 | + 'type': 'object'} |
0 commit comments