Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with missing required field default value in Navbar JSON schema. #130

Merged
merged 7 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 @@ -185,7 +185,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(),
}