@@ -160,21 +160,26 @@ def json_schema_obj_to_fields(
160
160
def json_schema_any_to_fields (
161
161
schema : JsonSchemaAny , loc : SchemeLocation , title : _t .List [str ], required : bool , defs : JsonSchemaDefs
162
162
) -> _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 )
170
171
else :
171
- assert schema_is_object (schema ), f'Unexpected schema type { schema } '
172
+ assert schema_is_object (dereferenced ), f'Unexpected schema type { dereferenced } '
172
173
173
- yield from json_schema_obj_to_fields (schema , loc , title , defs )
174
+ yield from json_schema_obj_to_fields (dereferenced , loc , title , defs )
174
175
175
176
176
177
def json_schema_field_to_field (
177
- schema : JsonSchemaField , loc : SchemeLocation , title : _t .List [str ], required : bool
178
+ schema : JsonSchemaField ,
179
+ loc : SchemeLocation ,
180
+ title : _t .List [str ],
181
+ description : _t .Union [str , None ],
182
+ required : bool ,
178
183
) -> FormField :
179
184
name = loc_to_name (loc )
180
185
if schema ['type' ] == 'boolean' :
@@ -183,10 +188,10 @@ def json_schema_field_to_field(
183
188
title = title ,
184
189
required = required ,
185
190
initial = schema .get ('default' ),
186
- description = schema . get ( ' description' ) ,
191
+ description = description ,
187
192
mode = schema .get ('mode' , 'checkbox' ),
188
193
)
189
- elif field := special_string_field (schema , name , title , required , False ):
194
+ elif field := special_string_field (schema , name , title , description , required , False ):
190
195
return field
191
196
else :
192
197
return FormFieldInput (
@@ -206,15 +211,20 @@ def loc_to_title(loc: SchemeLocation) -> str:
206
211
207
212
208
213
def json_schema_array_to_fields (
209
- schema : JsonSchemaArray , loc : SchemeLocation , title : _t .List [str ], required : bool , defs : JsonSchemaDefs
214
+ schema : JsonSchemaArray ,
215
+ loc : SchemeLocation ,
216
+ title : _t .List [str ],
217
+ description : _t .Union [str , None ],
218
+ required : bool ,
219
+ defs : JsonSchemaDefs ,
210
220
) -> _t .Iterable [FormField ]:
211
221
items_schema = schema .get ('items' )
212
222
if items_schema :
213
223
items_schema , required = deference_json_schema (items_schema , defs , required )
214
- for field_name in 'search_url' , 'placeholder' , 'description' :
224
+ for field_name in 'search_url' , 'placeholder' :
215
225
if value := schema .get (field_name ):
216
226
items_schema [field_name ] = value # type: ignore
217
- if field := special_string_field (items_schema , loc_to_name (loc ), title , required , True ):
227
+ if field := special_string_field (items_schema , loc_to_name (loc ), title , description , required , True ):
218
228
yield field
219
229
return
220
230
@@ -236,7 +246,12 @@ def json_schema_array_to_fields(
236
246
237
247
238
248
def special_string_field (
239
- schema : JsonSchemaConcrete , name : str , title : _t .List [str ], required : bool , multiple : bool
249
+ schema : JsonSchemaConcrete ,
250
+ name : str ,
251
+ title : _t .List [str ],
252
+ description : _t .Union [str , None ],
253
+ required : bool ,
254
+ multiple : bool ,
240
255
) -> _t .Union [FormField , None ]:
241
256
if schema ['type' ] == 'string' :
242
257
if schema .get ('format' ) == 'binary' :
@@ -246,7 +261,7 @@ def special_string_field(
246
261
required = required ,
247
262
multiple = multiple ,
248
263
accept = schema .get ('accept' ),
249
- description = schema . get ( ' description' ) ,
264
+ description = description ,
250
265
)
251
266
elif schema .get ('format' ) == 'textarea' :
252
267
return FormFieldTextarea (
@@ -257,7 +272,7 @@ def special_string_field(
257
272
cols = schema .get ('cols' ),
258
273
placeholder = schema .get ('placeholder' ),
259
274
initial = schema .get ('initial' ),
260
- description = schema . get ( ' description' ) ,
275
+ description = description ,
261
276
autocomplete = schema .get ('autocomplete' ),
262
277
)
263
278
elif enum := schema .get ('enum' ):
@@ -270,7 +285,7 @@ def special_string_field(
270
285
multiple = multiple ,
271
286
options = [SelectOption (value = v , label = enum_labels .get (v ) or as_title (v )) for v in enum ],
272
287
initial = schema .get ('default' ),
273
- description = schema . get ( ' description' ) ,
288
+ description = description ,
274
289
autocomplete = schema .get ('autocomplete' ),
275
290
)
276
291
elif search_url := schema .get ('search_url' ):
@@ -282,7 +297,7 @@ def special_string_field(
282
297
required = required ,
283
298
multiple = multiple ,
284
299
initial = schema .get ('initial' ),
285
- description = schema . get ( ' description' ) ,
300
+ description = description ,
286
301
)
287
302
288
303
0 commit comments