@@ -78,13 +78,6 @@ class Meta(ComplexAttribute):
78
78
79
79
80
80
class 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
-
88
81
@classmethod
89
82
def to_schema (cls ):
90
83
"""Build a :class:`~scim2_models.Schema` from the current extension class."""
@@ -127,7 +120,7 @@ def __new__(cls, name, bases, attrs, **kwargs):
127
120
else [extensions ]
128
121
)
129
122
for extension in extensions :
130
- schema = extension .scim_schema
123
+ schema = extension .model_fields [ "schemas" ]. default [ 0 ]
131
124
attrs .setdefault ("__annotations__" , {})[extension .__name__ ] = Annotated [
132
125
Optional [extension ],
133
126
WrapSerializer (extension_serializer ),
@@ -143,18 +136,6 @@ def __new__(cls, name, bases, attrs, **kwargs):
143
136
144
137
145
138
class 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
-
158
139
schemas : list [str ]
159
140
"""The "schemas" attribute is a REQUIRED attribute and is an array of
160
141
Strings containing URIs that are used to indicate the namespaces of the
@@ -205,7 +186,9 @@ def get_extension_models(cls) -> dict[str, type]:
205
186
else extension_models
206
187
)
207
188
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
+ }
209
192
return by_schema
210
193
211
194
@staticmethod
@@ -214,7 +197,7 @@ def get_by_schema(
214
197
) -> Optional [type ]:
215
198
"""Given a resource type list and a schema, find the matching resource type."""
216
199
by_schema = {
217
- resource_type .scim_schema .lower (): resource_type
200
+ resource_type .model_fields [ "schemas" ]. default [ 0 ] .lower (): resource_type
218
201
for resource_type in (resource_types or [])
219
202
}
220
203
if with_extensions :
@@ -291,7 +274,7 @@ def compare_field_infos(fi1, fi2):
291
274
def model_to_schema (model : type [BaseModel ]):
292
275
from scim2_models .rfc7643 .schema import Schema
293
276
294
- schema_urn = model .scim_schema
277
+ schema_urn = model .model_fields [ "schemas" ]. default [ 0 ]
295
278
field_infos = dedicated_attributes (model )
296
279
attributes = [
297
280
model_attribute_to_attribute (model , attribute_name )
0 commit comments