Repository navigation
Commit e1c6f23
Fixes #1027.
For `T | None`, `_json_schema.py` was emitting `{"type": "null"}` before
the struct/`$ref` entry in `anyOf`. Tools that pick the first `anyOf`
element for example generation (Swagger UI in the issue) ended up
showing
`null`. Pydantic puts `null` last for the same reason.
Move `NoneType` out of the union iteration into a `has_none` flag and
append `{"type": "null"}` last in all three union branches (no-struct,
single-struct, tagged-struct). The tagged-struct branch's `if options:`
guard becomes `if options or has_none:` so `Tagged | None` keeps `null`
in its `anyOf` instead of dropping it.
Observable changes:
- `Struct | None`: was `[null, $ref]`, now `[$ref, null]`.
- `Union[X, None, Y]`: `null` moves from the middle to the end.
- `str | None`: already `[string, null]` on CPython, unchanged.
Tests added in `tests/unit/test_schema.py` for `Optional[Struct]`,
`Union[int, None, str]`, and `Union[Tagged, None]` (covers the third
branch that previously dropped `null` entirely).
---------
Signed-off-by: SarthakB11 <[email protected]>
Co-authored-by: Siyet <[email protected]>
1 parent ecf2282 commit e1c6f23
2 files changed
Lines changed: 93 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
| 333 | + | |
| 334 | + | |
333 | 335 | | |
334 | 336 | | |
335 | 337 | | |
| |||
338 | 340 | | |
339 | 341 | | |
340 | 342 | | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
341 | 346 | | |
342 | 347 | | |
343 | 348 | | |
| |||
354 | 359 | | |
355 | 360 | | |
356 | 361 | | |
| 362 | + | |
| 363 | + | |
357 | 364 | | |
| 365 | + | |
| 366 | + | |
358 | 367 | | |
359 | 368 | | |
360 | 369 | | |
361 | 370 | | |
362 | 371 | | |
| 372 | + | |
| 373 | + | |
363 | 374 | | |
364 | 375 | | |
| 376 | + | |
| 377 | + | |
365 | 378 | | |
366 | 379 | | |
367 | 380 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
828 | 829 | | |
829 | 830 | | |
830 | 831 | | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
831 | 855 | | |
832 | 856 | | |
833 | 857 | | |
| |||
899 | 923 | | |
900 | 924 | | |
901 | 925 | | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
902 | 948 | | |
903 | 949 | | |
904 | 950 | | |
| |||
945 | 991 | | |
946 | 992 | | |
947 | 993 | | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
948 | 1028 | | |
949 | 1029 | | |
950 | 1030 | | |
| |||
0 commit comments