scim2-models 0.3.4__py3-none-any.whl → 0.3.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,6 @@ from typing import Any
4
4
  from typing import Generic
5
5
  from typing import Optional
6
6
  from typing import TypeVar
7
- from typing import Union
8
7
  from typing import get_args
9
8
  from typing import get_origin
10
9
 
@@ -17,12 +16,14 @@ from ..base import BaseModelType
17
16
  from ..base import CaseExact
18
17
  from ..base import ComplexAttribute
19
18
  from ..base import ExternalReference
19
+ from ..base import MultiValuedComplexAttribute
20
20
  from ..base import Mutability
21
21
  from ..base import Required
22
22
  from ..base import Returned
23
23
  from ..base import Uniqueness
24
24
  from ..base import URIReference
25
25
  from ..base import is_complex_attribute
26
+ from ..utils import UNION_TYPES
26
27
  from ..utils import normalize_attribute_name
27
28
 
28
29
 
@@ -116,7 +117,7 @@ class ResourceMetaclass(BaseModelType):
116
117
  extensions = kwargs["__pydantic_generic_metadata__"]["args"][0]
117
118
  extensions = (
118
119
  get_args(extensions)
119
- if get_origin(extensions) == Union
120
+ if get_origin(extensions) in UNION_TYPES
120
121
  else [extensions]
121
122
  )
122
123
  for extension in extensions:
@@ -182,7 +183,8 @@ class Resource(BaseModel, Generic[AnyExtension], metaclass=ResourceMetaclass):
182
183
  extension_models = cls.__pydantic_generic_metadata__.get("args", [])
183
184
  extension_models = (
184
185
  get_args(extension_models[0])
185
- if len(extension_models) == 1 and get_origin(extension_models[0]) == Union
186
+ if len(extension_models) == 1
187
+ and get_origin(extension_models[0]) in UNION_TYPES
186
188
  else extension_models
187
189
  )
188
190
 
@@ -253,8 +255,8 @@ class Resource(BaseModel, Generic[AnyExtension], metaclass=ResourceMetaclass):
253
255
  AnyResource = TypeVar("AnyResource", bound="Resource")
254
256
 
255
257
 
256
- def dedicated_attributes(model):
257
- """Return attributes that are not members of parent classes."""
258
+ def dedicated_attributes(model, excluded_models):
259
+ """Return attributes that are not members the parent 'excluded_models'."""
258
260
 
259
261
  def compare_field_infos(fi1, fi2):
260
262
  return (
@@ -268,8 +270,8 @@ def dedicated_attributes(model):
268
270
 
269
271
  parent_field_infos = {
270
272
  field_name: field_info
271
- for parent in model.__bases__
272
- for field_name, field_info in parent.model_fields.items()
273
+ for excluded_model in excluded_models
274
+ for field_name, field_info in excluded_model.model_fields.items()
273
275
  }
274
276
  field_infos = {
275
277
  field_name: field_info
@@ -283,7 +285,7 @@ def model_to_schema(model: type[BaseModel]):
283
285
  from scim2_models.rfc7643.schema import Schema
284
286
 
285
287
  schema_urn = model.model_fields["schemas"].default[0]
286
- field_infos = dedicated_attributes(model)
288
+ field_infos = dedicated_attributes(model, [Resource])
287
289
  attributes = [
288
290
  model_attribute_to_attribute(model, attribute_name)
289
291
  for attribute_name in field_infos
@@ -300,7 +302,7 @@ def model_to_schema(model: type[BaseModel]):
300
302
 
301
303
  def get_reference_types(type) -> list[str]:
302
304
  first_arg = get_args(type)[0]
303
- types = get_args(first_arg) if get_origin(first_arg) == Union else [first_arg]
305
+ types = get_args(first_arg) if get_origin(first_arg) in UNION_TYPES else [first_arg]
304
306
 
305
307
  def serialize_ref_type(ref_type):
306
308
  if ref_type == URIReference:
@@ -323,7 +325,9 @@ def model_attribute_to_attribute(model, attribute_name):
323
325
  sub_attributes = (
324
326
  [
325
327
  model_attribute_to_attribute(root_type, sub_attribute_name)
326
- for sub_attribute_name in dedicated_attributes(root_type)
328
+ for sub_attribute_name in dedicated_attributes(
329
+ root_type, [MultiValuedComplexAttribute]
330
+ )
327
331
  if (
328
332
  attribute_name != "sub_attributes"
329
333
  or sub_attribute_name != "sub_attributes"
@@ -1,5 +1,7 @@
1
1
  from typing import Annotated
2
2
  from typing import Optional
3
+ from typing import get_args
4
+ from typing import get_origin
3
5
 
4
6
  from pydantic import Field
5
7
  from typing_extensions import Self
@@ -11,6 +13,7 @@ from ..base import Reference
11
13
  from ..base import Required
12
14
  from ..base import Returned
13
15
  from ..base import URIReference
16
+ from ..utils import UNION_TYPES
14
17
  from .resource import Resource
15
18
 
16
19
 
@@ -82,7 +85,16 @@ class ResourceType(Resource):
82
85
  """Build a naive ResourceType from a resource model."""
83
86
  schema = resource_model.model_fields["schemas"].default[0]
84
87
  name = schema.split(":")[-1]
85
- extensions = resource_model.__pydantic_generic_metadata__["args"]
88
+ if resource_model.__pydantic_generic_metadata__["args"]:
89
+ extensions = resource_model.__pydantic_generic_metadata__["args"][0]
90
+ extensions = (
91
+ get_args(extensions)
92
+ if get_origin(extensions) in UNION_TYPES
93
+ else [extensions]
94
+ )
95
+ else:
96
+ extensions = []
97
+
86
98
  return ResourceType(
87
99
  id=name,
88
100
  name=name,
@@ -20,6 +20,7 @@ from ..base import BaseModelType
20
20
  from ..base import Context
21
21
  from ..base import Required
22
22
  from ..rfc7643.resource import AnyResource
23
+ from ..utils import UNION_TYPES
23
24
  from .message import Message
24
25
 
25
26
 
@@ -29,7 +30,7 @@ class ListResponseMetaclass(BaseModelType):
29
30
 
30
31
  https://docs.pydantic.dev/latest/concepts/unions/#discriminated-unions
31
32
  """
32
- if not get_origin(resource_union) == Union:
33
+ if get_origin(resource_union) not in UNION_TYPES:
33
34
  return resource_union
34
35
 
35
36
  resource_types = get_args(resource_union)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scim2-models
3
- Version: 0.3.4
3
+ Version: 0.3.6
4
4
  Summary: SCIM2 models serialization and validation with pydantic
5
5
  Project-URL: documentation, https://scim2-models.readthedocs.io
6
6
  Project-URL: repository, https://github.com/python-scim/scim2-models
@@ -6,19 +6,19 @@ scim2_models/utils.py,sha256=MzZz212-lkVWgXcpXvNwoi_u28wBTpkTwPrfYC5v92A,2771
6
6
  scim2_models/rfc7643/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  scim2_models/rfc7643/enterprise_user.py,sha256=EaxdHH2dcBrwWwGpaZC6iZ9dbcaVN1NpoRLAdkTYssQ,1781
8
8
  scim2_models/rfc7643/group.py,sha256=JML8OtgKjvHHv2YufiYcTtbZuN5GFVQTbm1J6MLtp8o,1427
9
- scim2_models/rfc7643/resource.py,sha256=zMyk02Traoq6XNBcS_fSnXIOadZwxTdA9CV4vLuy38k,12648
10
- scim2_models/rfc7643/resource_type.py,sha256=p8IKV5IakPMBX6d2Fv2MFqaQL5iTw152vmozVVSC8gU,3196
9
+ scim2_models/rfc7643/resource.py,sha256=oEm0RVBFonTrrhS-iYQquAdiy4UW4nXHbk_Bf--fR3g,12849
10
+ scim2_models/rfc7643/resource_type.py,sha256=vT2ItHvBzmsFVt3zbIJABxjcnSLUK-mW-zWduHxGE3k,3570
11
11
  scim2_models/rfc7643/schema.py,sha256=B7TzMbT6ngYQrMqvqW5_LberN6EaqtZaFwBVsgoA3S0,10388
12
12
  scim2_models/rfc7643/service_provider_config.py,sha256=deMNCXlqiNzuLcVRN9mdHiTUxhczDnvi-oO6k-Anj8U,5402
13
13
  scim2_models/rfc7643/user.py,sha256=EEje4V_zbMVwVYOu2Gj1W7GjD90WnC0lUK3FJuh4jWE,10607
14
14
  scim2_models/rfc7644/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  scim2_models/rfc7644/bulk.py,sha256=I6S40kyJPwDQwPFi668wFFDVTST7z6QTe9HTL5QUViI,2577
16
16
  scim2_models/rfc7644/error.py,sha256=l4-vtGQYm5u13-ParhbHSeqXEil0E09QXSO9twAT3SU,6185
17
- scim2_models/rfc7644/list_response.py,sha256=ltjV1WII2fNy8j3RX8J0_Jb5DW4hTFoO6P-Myr7TnBY,4551
17
+ scim2_models/rfc7644/list_response.py,sha256=GNfRKpL2WK2KHGC3kg7ldaSiPwCXl0AxDfhnbHByEAY,4589
18
18
  scim2_models/rfc7644/message.py,sha256=F4kPqbHAka3-wZzap9a45noQZw-o1vznTJypNABBF7w,253
19
19
  scim2_models/rfc7644/patch_op.py,sha256=OE-ixDanTkY5zQP7EK7OAp88uE_fMk03mqmaZHxgJ-g,2210
20
20
  scim2_models/rfc7644/search_request.py,sha256=DRGlixcWtYtbUuP9MT7PsnvyxlONLcXGEcQveWdqQng,3003
21
- scim2_models-0.3.4.dist-info/METADATA,sha256=K4xDCV3A2Hv7Wq-QiCoXrPU3XoDKFaeqAzTQL8aKybY,16288
22
- scim2_models-0.3.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
23
- scim2_models-0.3.4.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
24
- scim2_models-0.3.4.dist-info/RECORD,,
21
+ scim2_models-0.3.6.dist-info/METADATA,sha256=ihhjxgKo0dF-ufWhrgCdsNiH6vGXOplFlga07UVHrLw,16288
22
+ scim2_models-0.3.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
23
+ scim2_models-0.3.6.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
24
+ scim2_models-0.3.6.dist-info/RECORD,,