Skip to content

Commit

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


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'),
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,
]
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['oneOf']
components_union = json_schema['anyOf']
components_union_set = set(d['$ref'] for d in components_union)


Expand Down

0 comments on commit e41f0ac

Please sign in to comment.