Commit 25161b6
committed
Allow bare dict / Dict[Any, ...] fields in json schema generation
GenerateJsonSchemaSafe rejected any dict whose key type wasn't exactly
'str', which also caught bare dict / Dict[Any, ...] fields (keys_schema
type 'any'). Those map to an unconstrained JSON object, which is valid
(JSON object keys are always strings) and is accepted by the backend, so
rejecting them with 'JSON does not support non-string keys' is a false
positive with a misleading message.
Allow the 'any' key type alongside 'str'; int/float/etc. keys stay
rejected. Also read keys_schema/type defensively via .get(). Adds tests
for bare dict, Dict[str, Any], Dict[Any, Any], and a bare-dict model
field being accepted, and keeps the existing int-key rejection test.
Closes #14931 parent 21b1d90 commit 25161b6
2 files changed
Lines changed: 30 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
22 | 28 | | |
23 | 29 | | |
24 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
173 | 195 | | |
174 | 196 | | |
175 | 197 | | |
| |||
0 commit comments