Skip to content

Commit fd15026

Browse files
committed
Fix bytes rendered wrong
1 parent 6b7c7cb commit fd15026

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/python-fastui/fastui/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def __get_pydantic_core_schema__(self, source_type: _t.Type[_t.Any], *_args) ->
130130
def __get_pydantic_json_schema__(self, core_schema_: core_schema.CoreSchema, *_args) -> 'json_schema.JsonSchemaAny':
131131
from . import json_schema
132132

133-
s = json_schema.JsonSchemaFile(type='string', format='binary')
133+
s = json_schema.JsonSchemaFile(type='string', format='data-url')
134134
if self.accept:
135135
s['accept'] = self.accept
136136

src/python-fastui/fastui/json_schema.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class JsonSchemaStringSearch(JsonSchemaBase, total=False):
6868

6969
class JsonSchemaFile(JsonSchemaBase, total=False):
7070
type: _ta.Required[_t.Literal['string']]
71-
format: _ta.Required[_t.Literal['binary']]
71+
format: _ta.Required[_t.Literal['data-url']]
7272
accept: str
7373

7474

@@ -214,7 +214,7 @@ def special_string_field(
214214
schema: JsonSchemaConcrete, name: str, title: _t.List[str], required: bool, multiple: bool
215215
) -> _t.Union[FormField, None]:
216216
if schema['type'] == 'string':
217-
if schema.get('format') == 'binary':
217+
if schema.get('format') == 'data-url':
218218
return FormFieldFile(
219219
name=name,
220220
title=title,
@@ -315,6 +315,8 @@ def as_title(s: _t.Any) -> str:
315315
'string-uri': 'url',
316316
'string-uuid': 'text',
317317
'string-password': 'password',
318+
'string-binary': 'text',
319+
'string-base64': 'text',
318320
'number': 'number',
319321
'integer': 'number',
320322
}

src/python-fastui/tests/test_forms.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
from fastapi import HTTPException
77
from fastui import components
88
from fastui.forms import FormFile, fastui_form
9-
from pydantic import BaseModel
9+
from pydantic import Base64Str, BaseModel
1010
from starlette.datastructures import FormData, Headers, UploadFile
1111
from typing_extensions import Annotated
1212

1313

1414
class SimpleForm(BaseModel):
1515
name: str
1616
size: int = 4
17+
base64: Base64Str = 'ZmFzdHVp'
1718

1819

1920
class FakeRequest:
@@ -54,6 +55,15 @@ def test_simple_form_fields():
5455
'htmlType': 'number',
5556
'type': 'FormFieldInput',
5657
},
58+
{
59+
'name': 'base64',
60+
'title': ['Base64'],
61+
'initial': 'ZmFzdHVp',
62+
'required': False,
63+
'locked': False,
64+
'htmlType': 'text',
65+
'type': 'FormFieldInput',
66+
},
5767
],
5868
}
5969

@@ -85,18 +95,27 @@ def test_inline_form_fields():
8595
'htmlType': 'number',
8696
'type': 'FormFieldInput',
8797
},
98+
{
99+
'name': 'base64',
100+
'title': ['Base64'],
101+
'initial': 'ZmFzdHVp',
102+
'required': False,
103+
'locked': False,
104+
'htmlType': 'text',
105+
'type': 'FormFieldInput',
106+
},
88107
],
89108
}
90109

91110

92111
async def test_simple_form_submit():
93112
form_dep = fastui_form(SimpleForm)
94113

95-
request = FakeRequest([('name', 'bar'), ('size', '123')])
114+
request = FakeRequest([('name', 'bar'), ('size', '123'), ('base64', 'ZmFzdHVp')])
96115

97116
m = await form_dep.dependency(request)
98117
assert isinstance(m, SimpleForm)
99-
assert m.model_dump() == {'name': 'bar', 'size': 123}
118+
assert m.model_dump() == {'name': 'bar', 'size': 123, 'base64': 'ZmFzdHVp\n'}
100119

101120

102121
async def test_simple_form_submit_repeat():

0 commit comments

Comments
 (0)