Open rafalkrupinski opened 3 months ago
actual example from my project:
class Responses(ExtendableModel, ModelWithPatternProperties):
responses: typing.Annotated[
dict[str, Reference[Response] | Response],
pydantic.Field(default_factory=dict, min_length=1),
PropertyPattern(r'^[1-5](?:\d{2}|XX)|default$'),
]
Hey @rafalkrupinski - happy to accept a contribution for this. In general I'd prefer to maintain support for Pydantic v1 + v2 for now until v1 support is dropped on the Pydantic side, so if you could extend the v2 approach with the compat module that would be ideal (it can be a bit fiddly though with typing)
Currently callbacks, paths and responses are modelled as dicts, but that breaks support for specification extensions.
An alternative solution would be to use before-validation to catch all non-extension entries and put them in a dict inside the model, and leave extensions to be handled by
extra
. Basically all dynamic names would be pushed down into a dict. This would improve compatibility with python but break 1-1 mapping with the JSON representation, and would need to be coupled with pre-processing during serialization.I've done something roughly similar but only for V2 and only for parsing.