yaal-coop / scim2-models

SCIM resources serialization and validation with Pydantic
https://scim2-models.readthedocs.io
Apache License 2.0
10 stars 2 forks source link

Load extensions at model definition #43

Closed azmeuk closed 3 months ago

azmeuk commented 3 months ago

Currently, on model validation a check is performed to detect model extension attributes, and use setattr to assign the new value.

https://github.com/yaal-coop/scim2-models/blob/d32a5c2a4b62c27eddba12c94d6ab53bc0de1974/scim2_models/rfc7643/resource.py#L176-L178

We should investigate how to dynamically build the new pydantic field based on models type parameters, at the model definition time instead of validation.

This may allow to forbid extra fields:

https://github.com/yaal-coop/scim2-models/blob/d32a5c2a4b62c27eddba12c94d6ab53bc0de1974/scim2_models/rfc7643/resource.py#L92-L93

Good candidates for implementing this are metaclasses, __initsubclass_\.