Skip to content

Commit

Permalink
revert to disciminated union for AnyComponent (pydantic#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin authored Dec 13, 2023
1 parent bbb5d61 commit 45d924f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
55 changes: 29 additions & 26 deletions src/python-fastui/fastui/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,30 +231,33 @@ class Custom(_p.BaseModel, extra='forbid'):
type: _t.Literal['Custom'] = 'Custom'


AnyComponent = _t.Union[
Text,
Paragraph,
PageTitle,
Div,
Page,
Heading,
Markdown,
Code,
Json,
Button,
Link,
LinkList,
Navbar,
Modal,
ServerLoad,
Image,
Iframe,
Custom,
Table,
Pagination,
Display,
Details,
Form,
FormField,
ModelForm,
AnyComponent = _te.Annotated[
_t.Union[
Text,
Paragraph,
PageTitle,
Div,
Page,
Heading,
Markdown,
Code,
Json,
Button,
Link,
LinkList,
Navbar,
Modal,
ServerLoad,
Image,
Iframe,
Custom,
Table,
Pagination,
Display,
Details,
Form,
FormField,
ModelForm,
],
_p.Field(discriminator='type'),
]
2 changes: 1 addition & 1 deletion src/python-fastui/tests/test_json_schema_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

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


Expand Down

0 comments on commit 45d924f

Please sign in to comment.