Skip to content

Commit d551f87

Browse files
Fix issue with missing required field default value in Navbar JSON schema. (#130)
Co-authored-by: Samuel Colvin <[email protected]>
1 parent b3321da commit d551f87

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/python-fastui/fastui/components/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def __get_pydantic_json_schema__(
186186
) -> _t.Any:
187187
# until https://github.com/pydantic/pydantic/issues/8413 is fixed
188188
json_schema = handler(core_schema)
189-
json_schema['required'].append('links')
189+
json_schema.setdefault('required', []).append('links')
190190
return json_schema
191191

192192

src/python-fastui/tests/test_json_schema.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from dirty_equals import IsPartialDict
2-
from fastui import FastUI
2+
from fastapi import FastAPI
3+
from fastui import FastUI, components
34
from fastui.generate_typescript import generate_json_schema
5+
from httpx import AsyncClient
46

57

68
async def test_json_schema():
@@ -12,3 +14,25 @@ async def test_json_schema():
1214
'type': 'array',
1315
}
1416
# TODO test more specific cases
17+
18+
19+
async def test_openapi():
20+
app = FastAPI()
21+
22+
@app.get('/api/', response_model=FastUI, response_model_exclude_none=True)
23+
def test_endpoint():
24+
return [components.Text(text='hello')]
25+
26+
async with AsyncClient(app=app, base_url='http://test') as client:
27+
r = await client.get('/openapi.json')
28+
assert r.status_code == 200
29+
assert r.headers['content-type'] == 'application/json'
30+
assert r.json() == {
31+
'openapi': '3.1.0',
32+
'info': {
33+
'title': 'FastAPI',
34+
'version': '0.1.0',
35+
},
36+
'paths': IsPartialDict(),
37+
'components': IsPartialDict(),
38+
}

0 commit comments

Comments
 (0)