Skip to content

Commit 325157c

Browse files
committed
More compat
1 parent 31d6c8b commit 325157c

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ def __get_pydantic_json_schema__(
154154
) -> _t.Any:
155155
# until https://github.com/pydantic/pydantic/issues/8413 is fixed
156156
json_schema = handler(core_schema)
157-
json_schema['required'].append('level')
157+
schema_def = handler.resolve_ref_schema(json_schema)
158+
schema_def['required'].append('level')
158159
return json_schema
159160

160161

@@ -309,7 +310,8 @@ def __get_pydantic_json_schema__(
309310
) -> _t.Any:
310311
# until https://github.com/pydantic/pydantic/issues/8413 is fixed
311312
json_schema = handler(core_schema)
312-
json_schema.setdefault('required', []).extend(['startLinks', 'endLinks'])
313+
schema_def = handler.resolve_ref_schema(json_schema)
314+
schema_def.setdefault('required', []).extend(['startLinks', 'endLinks'])
313315
return json_schema
314316

315317

@@ -523,7 +525,8 @@ def __get_pydantic_json_schema__(
523525
) -> _t.Any:
524526
# add `children` to the schema so it can be used in the client
525527
json_schema = handler(core_schema)
526-
json_schema['properties']['children'] = {'tsType': 'ReactNode'}
528+
schema_def = handler.resolve_ref_schema(json_schema)
529+
schema_def['properties']['children'] = {'tsType': 'ReactNode'}
527530
return json_schema
528531

529532

src/python-fastui/fastui/json_schema.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,17 @@ def json_schema_obj_to_fields(
160160
def json_schema_any_to_fields(
161161
schema: JsonSchemaAny, loc: SchemeLocation, title: _t.List[str], required: bool, defs: JsonSchemaDefs
162162
) -> _t.Iterable[FormField]:
163-
schema, required = deference_json_schema(schema, defs, required)
164-
title = title + [schema.get('title') or loc_to_title(loc)]
163+
dereferenced, required = deference_json_schema(schema, defs, required)
164+
title = title + [schema.get('title', dereferenced.get('title', loc_to_title(loc)))]
165165

166-
if schema_is_field(schema):
167-
yield json_schema_field_to_field(schema, loc, title, required)
168-
elif schema_is_array(schema):
169-
yield from json_schema_array_to_fields(schema, loc, title, required, defs)
166+
if schema_is_field(dereferenced):
167+
yield json_schema_field_to_field(dereferenced, loc, title, required)
168+
elif schema_is_array(dereferenced):
169+
yield from json_schema_array_to_fields(dereferenced, loc, title, required, defs)
170170
else:
171-
assert schema_is_object(schema), f'Unexpected schema type {schema}'
171+
assert schema_is_object(dereferenced), f'Unexpected schema type {dereferenced}'
172172

173-
yield from json_schema_obj_to_fields(schema, loc, title, defs)
173+
yield from json_schema_obj_to_fields(dereferenced, loc, title, defs)
174174

175175

176176
def json_schema_field_to_field(

src/python-fastui/requirements/pyproject.txt

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# This file is autogenerated by pip-compile with Python 3.11
2+
# This file is autogenerated by pip-compile with Python 3.12
33
# by the following command:
44
#
55
# pip-compile --constraint=src/python-fastui/requirements/lint.txt --extra=fastapi --output-file=src/python-fastui/requirements/pyproject.txt --strip-extras src/python-fastui/pyproject.toml
@@ -18,20 +18,19 @@ idna==3.6
1818
# via
1919
# anyio
2020
# email-validator
21-
pydantic==2.6.1
21+
pydantic==2.10.6
2222
# via
2323
# fastapi
2424
# fastui (src/python-fastui/pyproject.toml)
25-
# pydantic
26-
pydantic-core==2.16.2
25+
pydantic-core==2.27.2
2726
# via pydantic
2827
python-multipart==0.0.7
2928
# via fastui (src/python-fastui/pyproject.toml)
3029
sniffio==1.3.0
3130
# via anyio
3231
starlette==0.36.3
3332
# via fastapi
34-
typing-extensions==4.9.0
33+
typing-extensions==4.12.2
3534
# via
3635
# fastapi
3736
# pydantic

src/python-fastui/tests/test_components.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
that's just testing pydantic!
66
"""
77
from fastui import FastUI, components
8-
from pydantic_core import Url
8+
from pydantic import HttpUrl
99

1010

1111
def test_div_text():
@@ -56,7 +56,7 @@ def test_root_model_single():
5656
def test_iframe():
5757
iframe = components.Iframe(src='https://www.example.com', srcdoc='<p>hello world</p>', sandbox='allow-scripts')
5858
assert iframe.model_dump(by_alias=True, exclude_none=True) == {
59-
'src': Url('https://www.example.com'),
59+
'src': HttpUrl('https://www.example.com'),
6060
'type': 'Iframe',
6161
'srcdoc': '<p>hello world</p>',
6262
'sandbox': 'allow-scripts',

0 commit comments

Comments
 (0)