Commit 75f72c6
committed
Add support for Pydantic models with
This change ensures that the generated JSON schema
/ OpenAPI docs match the `alias=` param when
present, and that any returned JSON uses the alias
for the keys. This is the most consistent behavior
with Pydantic's usage, *but* is a breaking change
for any existing code that uses `alias=` and
relies on FastOpenAPI returning the field name
instead of the alias.
We could put this behind a setting if desired
instead, i.e.,:
```
model_dump(
by_alias=(True if use_aliases else False)
)
model_json_schema(
mode=("serialization" if use_aliases else "validation")
)
```alias=
1 parent e9bf5ab commit 75f72c6
2 files changed
+15
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
228 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
229 | 231 | | |
230 | 232 | | |
231 | 233 | | |
| |||
337 | 339 | | |
338 | 340 | | |
339 | 341 | | |
340 | | - | |
| 342 | + | |
341 | 343 | | |
342 | 344 | | |
343 | 345 | | |
| |||
356 | 358 | | |
357 | 359 | | |
358 | 360 | | |
359 | | - | |
| 361 | + | |
360 | 362 | | |
361 | 363 | | |
362 | 364 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
16 | 20 | | |
17 | 21 | | |
18 | 22 | | |
| |||
30 | 34 | | |
31 | 35 | | |
32 | 36 | | |
33 | | - | |
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
| |||
465 | 468 | | |
466 | 469 | | |
467 | 470 | | |
| 471 | + | |
468 | 472 | | |
469 | 473 | | |
470 | 474 | | |
| |||
517 | 521 | | |
518 | 522 | | |
519 | 523 | | |
| 524 | + | |
520 | 525 | | |
521 | 526 | | |
522 | 527 | | |
| |||
566 | 571 | | |
567 | 572 | | |
568 | 573 | | |
569 | | - | |
| 574 | + | |
570 | 575 | | |
571 | 576 | | |
572 | 577 | | |
| 578 | + | |
573 | 579 | | |
574 | 580 | | |
575 | 581 | | |
576 | 582 | | |
577 | 583 | | |
| 584 | + | |
578 | 585 | | |
579 | 586 | | |
580 | 587 | | |
| |||
0 commit comments