AnyOf
vs OneOf
for Optional[T]
#706
bruno-f-cruz
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is a discussion that generates a lot of confusion in the OpenApi and in the pydantic forums (pydantic/pydantic#7161).
Basically, when you have a nullable type, which tag should you use?
AnyOf
orOneOf
?Pydantic locks it to
AnyOf
(in a bit of a self-admited arbitrary choice, https://github.com/pydantic/pydantic/blob/da468c48624b202685af4baebf0edf0df4402a81/pydantic/json_schema.py#L1021-L1023) which breaks the interoperability with other tools. This can be bypassed by having our own JsonGenerator:The export thus becomes:
Beta Was this translation helpful? Give feedback.
All reactions