@@ -160,21 +160,22 @@ def json_schema_obj_to_fields(
160160def 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 )]
165-
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 )
163+ dereferenced , required = deference_json_schema (schema , defs , required )
164+ title = title + [schema .get ('title' , dereferenced .get ('title' , loc_to_title (loc )))]
165+ description = schema .get ('description' , dereferenced .get ('description' ))
166+
167+ if schema_is_field (dereferenced ):
168+ yield json_schema_field_to_field (dereferenced , loc , title , description , required )
169+ elif schema_is_array (dereferenced ):
170+ yield from json_schema_array_to_fields (dereferenced , loc , title , description , required , defs )
170171 else :
171- assert schema_is_object (schema ), f'Unexpected schema type { schema } '
172+ assert schema_is_object (dereferenced ), f'Unexpected schema type { dereferenced } '
172173
173- yield from json_schema_obj_to_fields (schema , loc , title , defs )
174+ yield from json_schema_obj_to_fields (dereferenced , loc , title , defs )
174175
175176
176177def json_schema_field_to_field (
177- schema : JsonSchemaField , loc : SchemeLocation , title : _t .List [str ], required : bool
178+ schema : JsonSchemaField , loc : SchemeLocation , title : _t .List [str ], description : _t . Union [ str , None ], required : bool ,
178179) -> FormField :
179180 name = loc_to_name (loc )
180181 if schema ['type' ] == 'boolean' :
@@ -183,10 +184,10 @@ def json_schema_field_to_field(
183184 title = title ,
184185 required = required ,
185186 initial = schema .get ('default' ),
186- description = schema . get ( ' description' ) ,
187+ description = description ,
187188 mode = schema .get ('mode' , 'checkbox' ),
188189 )
189- elif field := special_string_field (schema , name , title , required , False ):
190+ elif field := special_string_field (schema , name , title , description , required , False ):
190191 return field
191192 else :
192193 return FormFieldInput (
@@ -206,15 +207,15 @@ def loc_to_title(loc: SchemeLocation) -> str:
206207
207208
208209def json_schema_array_to_fields (
209- schema : JsonSchemaArray , loc : SchemeLocation , title : _t .List [str ], required : bool , defs : JsonSchemaDefs
210+ schema : JsonSchemaArray , loc : SchemeLocation , title : _t .List [str ], description : _t . Union [ str , None ], required : bool , defs : JsonSchemaDefs
210211) -> _t .Iterable [FormField ]:
211212 items_schema = schema .get ('items' )
212213 if items_schema :
213214 items_schema , required = deference_json_schema (items_schema , defs , required )
214- for field_name in 'search_url' , 'placeholder' , 'description' :
215+ for field_name in 'search_url' , 'placeholder' :
215216 if value := schema .get (field_name ):
216217 items_schema [field_name ] = value # type: ignore
217- if field := special_string_field (items_schema , loc_to_name (loc ), title , required , True ):
218+ if field := special_string_field (items_schema , loc_to_name (loc ), title , description , required , True ):
218219 yield field
219220 return
220221
@@ -236,7 +237,7 @@ def json_schema_array_to_fields(
236237
237238
238239def special_string_field (
239- schema : JsonSchemaConcrete , name : str , title : _t .List [str ], required : bool , multiple : bool
240+ schema : JsonSchemaConcrete , name : str , title : _t .List [str ], description : _t . Union [ str , None ], required : bool , multiple : bool
240241) -> _t .Union [FormField , None ]:
241242 if schema ['type' ] == 'string' :
242243 if schema .get ('format' ) == 'binary' :
@@ -246,7 +247,7 @@ def special_string_field(
246247 required = required ,
247248 multiple = multiple ,
248249 accept = schema .get ('accept' ),
249- description = schema . get ( ' description' ) ,
250+ description = description ,
250251 )
251252 elif schema .get ('format' ) == 'textarea' :
252253 return FormFieldTextarea (
@@ -257,7 +258,7 @@ def special_string_field(
257258 cols = schema .get ('cols' ),
258259 placeholder = schema .get ('placeholder' ),
259260 initial = schema .get ('initial' ),
260- description = schema . get ( ' description' ) ,
261+ description = description ,
261262 autocomplete = schema .get ('autocomplete' ),
262263 )
263264 elif enum := schema .get ('enum' ):
@@ -270,7 +271,7 @@ def special_string_field(
270271 multiple = multiple ,
271272 options = [SelectOption (value = v , label = enum_labels .get (v ) or as_title (v )) for v in enum ],
272273 initial = schema .get ('default' ),
273- description = schema . get ( ' description' ) ,
274+ description = description ,
274275 autocomplete = schema .get ('autocomplete' ),
275276 )
276277 elif search_url := schema .get ('search_url' ):
@@ -282,7 +283,7 @@ def special_string_field(
282283 required = required ,
283284 multiple = multiple ,
284285 initial = schema .get ('initial' ),
285- description = schema . get ( ' description' ) ,
286+ description = description ,
286287 )
287288
288289
0 commit comments