Skip to content

Commit 93f2620

Browse files
committed
Add an test to ensure examples are present in the OpenAPI output
This is currently only possible with Pydantic BaseModels see jcrist/msgspec#689.
1 parent de59ee6 commit 93f2620

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

tests/test_openapi.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Dict, List, Optional, Tuple, Type
22

33
import pytest
4-
from pydantic import BaseModel, computed_field, Field
4+
from pydantic import BaseModel, computed_field, ConfigDict, Field
55
from pydantic.dataclasses import dataclass
66
from quart import Quart
77

@@ -301,3 +301,29 @@ async def index() -> EmployeeWithComputedField:
301301
assert "firstName" in response_properties
302302
assert "lastName" in response_properties
303303
assert "fullName" in response_properties
304+
305+
306+
class Example(BaseModel):
307+
a: str
308+
309+
model_config = ConfigDict(json_schema_extra={"examples": [{"a": "Foo"}]})
310+
311+
312+
async def test_model_with_example() -> None:
313+
app = Quart(__name__)
314+
QuartSchema(app, convert_casing=True)
315+
316+
@app.post("/")
317+
@validate_request(Example)
318+
async def index(data: Example) -> str:
319+
return ""
320+
321+
test_client = app.test_client()
322+
response = await test_client.get("/openapi.json")
323+
schema = await response.get_json()
324+
325+
properties = schema["paths"]["/"]["post"]["requestBody"]["content"]["application/json"][
326+
"schema"
327+
]
328+
329+
assert properties["examples"] == [{"a": "Foo"}]

0 commit comments

Comments
 (0)