@@ -78,13 +78,6 @@ class Meta(ComplexAttribute):
7878
7979
8080class Extension (BaseModel ):
81- def __init_subclass__ (cls , ** kwargs ):
82- super ().__init_subclass__ (** kwargs )
83- if not hasattr (cls , "scim_schema" ):
84- raise AttributeError (
85- f"{ cls .__name__ } did not define a scim_schema attribute"
86- )
87-
8881 @classmethod
8982 def to_schema (cls ):
9083 """Build a :class:`~scim2_models.Schema` from the current extension class."""
@@ -127,7 +120,7 @@ def __new__(cls, name, bases, attrs, **kwargs):
127120 else [extensions ]
128121 )
129122 for extension in extensions :
130- schema = extension .scim_schema
123+ schema = extension .model_fields [ "schemas" ]. default [ 0 ]
131124 attrs .setdefault ("__annotations__" , {})[extension .__name__ ] = Annotated [
132125 Optional [extension ],
133126 WrapSerializer (extension_serializer ),
@@ -143,18 +136,6 @@ def __new__(cls, name, bases, attrs, **kwargs):
143136
144137
145138class Resource (BaseModel , Generic [AnyExtension ], metaclass = ResourceMetaclass ):
146- def __init_subclass__ (cls , ** kwargs ):
147- super ().__init_subclass__ (** kwargs )
148- if not hasattr (cls , "scim_schema" ):
149- raise AttributeError (
150- f"{ cls .__name__ } did not define a scim_schema attribute"
151- )
152-
153- def init_schemas ():
154- return [cls .scim_schema ]
155-
156- cls .model_fields ["schemas" ].default_factory = init_schemas
157-
158139 schemas : list [str ]
159140 """The "schemas" attribute is a REQUIRED attribute and is an array of
160141 Strings containing URIs that are used to indicate the namespaces of the
@@ -205,7 +186,9 @@ def get_extension_models(cls) -> dict[str, type]:
205186 else extension_models
206187 )
207188
208- by_schema = {ext .scim_schema : ext for ext in extension_models }
189+ by_schema = {
190+ ext .model_fields ["schemas" ].default [0 ]: ext for ext in extension_models
191+ }
209192 return by_schema
210193
211194 @staticmethod
@@ -214,7 +197,7 @@ def get_by_schema(
214197 ) -> Optional [type ]:
215198 """Given a resource type list and a schema, find the matching resource type."""
216199 by_schema = {
217- resource_type .scim_schema .lower (): resource_type
200+ resource_type .model_fields [ "schemas" ]. default [ 0 ] .lower (): resource_type
218201 for resource_type in (resource_types or [])
219202 }
220203 if with_extensions :
@@ -291,7 +274,7 @@ def compare_field_infos(fi1, fi2):
291274def model_to_schema (model : type [BaseModel ]):
292275 from scim2_models .rfc7643 .schema import Schema
293276
294- schema_urn = model .scim_schema
277+ schema_urn = model .model_fields [ "schemas" ]. default [ 0 ]
295278 field_infos = dedicated_attributes (model )
296279 attributes = [
297280 model_attribute_to_attribute (model , attribute_name )
0 commit comments