Skip to content

Commit 45d924f

Browse files
authored
revert to disciminated union for AnyComponent (#94)
1 parent bbb5d61 commit 45d924f

File tree

2 files changed

+30
-27
lines changed

2 files changed

+30
-27
lines changed

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

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -231,30 +231,33 @@ class Custom(_p.BaseModel, extra='forbid'):
231231
type: _t.Literal['Custom'] = 'Custom'
232232

233233

234-
AnyComponent = _t.Union[
235-
Text,
236-
Paragraph,
237-
PageTitle,
238-
Div,
239-
Page,
240-
Heading,
241-
Markdown,
242-
Code,
243-
Json,
244-
Button,
245-
Link,
246-
LinkList,
247-
Navbar,
248-
Modal,
249-
ServerLoad,
250-
Image,
251-
Iframe,
252-
Custom,
253-
Table,
254-
Pagination,
255-
Display,
256-
Details,
257-
Form,
258-
FormField,
259-
ModelForm,
234+
AnyComponent = _te.Annotated[
235+
_t.Union[
236+
Text,
237+
Paragraph,
238+
PageTitle,
239+
Div,
240+
Page,
241+
Heading,
242+
Markdown,
243+
Code,
244+
Json,
245+
Button,
246+
Link,
247+
LinkList,
248+
Navbar,
249+
Modal,
250+
ServerLoad,
251+
Image,
252+
Iframe,
253+
Custom,
254+
Table,
255+
Pagination,
256+
Display,
257+
Details,
258+
Form,
259+
FormField,
260+
ModelForm,
261+
],
262+
_p.Field(discriminator='type'),
260263
]

src/python-fastui/tests/test_json_schema_match.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
ta = TypeAdapter(AnyComponent)
1515
json_schema = ta.json_schema(by_alias=True, mode='serialization', ref_template='#/definitions/{model}')
16-
components_union = json_schema['anyOf']
16+
components_union = json_schema['oneOf']
1717
components_union_set = set(d['$ref'] for d in components_union)
1818

1919

0 commit comments

Comments
 (0)