Skip to content

Commit

Permalink
Fix issue with missing required field default value in Navbar JSON sc…
Browse files Browse the repository at this point in the history
…hema. (#130)

Co-authored-by: Samuel Colvin <[email protected]>
  • Loading branch information
YiHuangDB and samuelcolvin authored Dec 28, 2023
1 parent b3321da commit d551f87
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/python-fastui/fastui/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def __get_pydantic_json_schema__(
) -> _t.Any:
# until https://github.com/pydantic/pydantic/issues/8413 is fixed
json_schema = handler(core_schema)
json_schema['required'].append('links')
json_schema.setdefault('required', []).append('links')
return json_schema


Expand Down
26 changes: 25 additions & 1 deletion src/python-fastui/tests/test_json_schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from dirty_equals import IsPartialDict
from fastui import FastUI
from fastapi import FastAPI
from fastui import FastUI, components
from fastui.generate_typescript import generate_json_schema
from httpx import AsyncClient


async def test_json_schema():
Expand All @@ -12,3 +14,25 @@ async def test_json_schema():
'type': 'array',
}
# TODO test more specific cases


async def test_openapi():
app = FastAPI()

@app.get('/api/', response_model=FastUI, response_model_exclude_none=True)
def test_endpoint():
return [components.Text(text='hello')]

async with AsyncClient(app=app, base_url='http://test') as client:
r = await client.get('/openapi.json')
assert r.status_code == 200
assert r.headers['content-type'] == 'application/json'
assert r.json() == {
'openapi': '3.1.0',
'info': {
'title': 'FastAPI',
'version': '0.1.0',
},
'paths': IsPartialDict(),
'components': IsPartialDict(),
}

0 comments on commit d551f87

Please sign in to comment.