additionalProperties=true #19
rafalkrupinski
started this conversation in
Ideas
Replies: 1 comment 3 replies
-
I fly with root , root is required for discriminated models anyway and pydantic v2 is supposed to lift the limitation. CheckoutBalanceCheckRequest:
properties:
additionalData:
additionalProperties:
type: string
anyOf:
- $ref: "#/components/schemas/AdditionalData3DSecure"
- $ref: "#/components/schemas/AdditionalDataAirline"
type: object |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The problem already starts here. You could map it to a simple dict[str,str] but that's not forwards-compatible.
Schema author can add non-required non-string property, which would be a compatible change, but the python API would change in an incompatible way (no longer a dict).
Can't use rooted pydantic model either, as you can't add fields to it.
Perhaps this:
It requires (get/set)(attr/item), otherwise you could get duplicates in dict&dict, but I think it keeps the semantics of the schema, should work with code completion as intended, and if schema changes from A1 to A2, the code also remains compatible.
I guess you were right about limitations of pydantic model 🤷🏻
Replying to myself: on the other hand, I have a case, where I'm receiving data from one service and just passing it to another. No need to look inside. Also cases where fields are known only at runtime. Cancel the above, not a good decision.
No need, python object is just a fancy dict, you can assign stuff to any legal name.
You can validate data at pretty much any stage before sending it, whether it model's init or the operation call. Though init is nicer - fail fast.
Beta Was this translation helpful? Give feedback.
All reactions