scim2-models 0.3.5__tar.gz → 0.3.7__tar.gz

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.
Files changed (117) hide show
  1. {scim2_models-0.3.5 → scim2_models-0.3.7}/.github/workflows/tests.yaml +14 -0
  2. {scim2_models-0.3.5 → scim2_models-0.3.7}/.pre-commit-config.yaml +4 -2
  3. {scim2_models-0.3.5 → scim2_models-0.3.7}/PKG-INFO +1 -1
  4. {scim2_models-0.3.5 → scim2_models-0.3.7}/conftest.py +1 -1
  5. {scim2_models-0.3.5 → scim2_models-0.3.7}/doc/changelog.rst +15 -0
  6. {scim2_models-0.3.5 → scim2_models-0.3.7}/pyproject.toml +16 -5
  7. {scim2_models-0.3.5 → scim2_models-0.3.7}/scim2_models/__init__.py +11 -11
  8. scim2_models-0.3.7/scim2_models/annotations.py +104 -0
  9. scim2_models-0.3.7/scim2_models/attributes.py +57 -0
  10. scim2_models-0.3.7/scim2_models/base.py +447 -0
  11. {scim2_models-0.3.5 → scim2_models-0.3.7}/scim2_models/constants.py +3 -3
  12. scim2_models-0.3.7/scim2_models/context.py +168 -0
  13. scim2_models-0.3.7/scim2_models/reference.py +82 -0
  14. {scim2_models-0.3.5 → scim2_models-0.3.7}/scim2_models/rfc7643/enterprise_user.py +4 -4
  15. {scim2_models-0.3.5 → scim2_models-0.3.7}/scim2_models/rfc7643/group.py +5 -5
  16. {scim2_models-0.3.5 → scim2_models-0.3.7}/scim2_models/rfc7643/resource.py +202 -94
  17. {scim2_models-0.3.5 → scim2_models-0.3.7}/scim2_models/rfc7643/resource_type.py +13 -10
  18. {scim2_models-0.3.5 → scim2_models-0.3.7}/scim2_models/rfc7643/schema.py +44 -38
  19. {scim2_models-0.3.5 → scim2_models-0.3.7}/scim2_models/rfc7643/service_provider_config.py +7 -7
  20. {scim2_models-0.3.5 → scim2_models-0.3.7}/scim2_models/rfc7643/user.py +9 -9
  21. {scim2_models-0.3.5 → scim2_models-0.3.7}/scim2_models/rfc7644/bulk.py +2 -2
  22. {scim2_models-0.3.5 → scim2_models-0.3.7}/scim2_models/rfc7644/error.py +11 -11
  23. scim2_models-0.3.7/scim2_models/rfc7644/list_response.py +75 -0
  24. scim2_models-0.3.7/scim2_models/rfc7644/message.py +110 -0
  25. {scim2_models-0.3.5 → scim2_models-0.3.7}/scim2_models/rfc7644/patch_op.py +20 -6
  26. {scim2_models-0.3.5 → scim2_models-0.3.7}/scim2_models/rfc7644/search_request.py +4 -4
  27. scim2_models-0.3.7/scim2_models/scim_object.py +143 -0
  28. {scim2_models-0.3.5 → scim2_models-0.3.7}/scim2_models/utils.py +1 -1
  29. {scim2_models-0.3.5 → scim2_models-0.3.7}/tests/test_dynamic_resources.py +10 -10
  30. {scim2_models-0.3.5 → scim2_models-0.3.7}/tests/test_dynamic_schemas.py +23 -2
  31. {scim2_models-0.3.5 → scim2_models-0.3.7}/tests/test_model_attributes.py +18 -5
  32. {scim2_models-0.3.5 → scim2_models-0.3.7}/tests/test_model_serialization.py +5 -5
  33. {scim2_models-0.3.5 → scim2_models-0.3.7}/tests/test_model_validation.py +5 -5
  34. {scim2_models-0.3.5 → scim2_models-0.3.7}/tests/test_patch_op.py +26 -0
  35. scim2_models-0.3.7/tests/test_reference.py +80 -0
  36. {scim2_models-0.3.5 → scim2_models-0.3.7}/tests/test_resource_extension.py +41 -0
  37. {scim2_models-0.3.5 → scim2_models-0.3.7}/tests/test_resource_type.py +34 -0
  38. {scim2_models-0.3.5 → scim2_models-0.3.7}/uv.lock +172 -171
  39. scim2_models-0.3.5/scim2_models/base.py +0 -904
  40. scim2_models-0.3.5/scim2_models/rfc7644/list_response.py +0 -135
  41. scim2_models-0.3.5/scim2_models/rfc7644/message.py +0 -10
  42. {scim2_models-0.3.5 → scim2_models-0.3.7}/.github/FUNDING.yml +0 -0
  43. {scim2_models-0.3.5 → scim2_models-0.3.7}/.github/workflows/release.yml +0 -0
  44. {scim2_models-0.3.5 → scim2_models-0.3.7}/.gitignore +0 -0
  45. {scim2_models-0.3.5 → scim2_models-0.3.7}/.readthedocs.yml +0 -0
  46. {scim2_models-0.3.5 → scim2_models-0.3.7}/LICENSE +0 -0
  47. {scim2_models-0.3.5 → scim2_models-0.3.7}/README.md +0 -0
  48. {scim2_models-0.3.5 → scim2_models-0.3.7}/doc/__init__.py +0 -0
  49. {scim2_models-0.3.5 → scim2_models-0.3.7}/doc/conf.py +0 -0
  50. {scim2_models-0.3.5 → scim2_models-0.3.7}/doc/contributing.rst +0 -0
  51. {scim2_models-0.3.5 → scim2_models-0.3.7}/doc/index.rst +0 -0
  52. {scim2_models-0.3.5 → scim2_models-0.3.7}/doc/reference.rst +0 -0
  53. {scim2_models-0.3.5 → scim2_models-0.3.7}/doc/tutorial.rst +0 -0
  54. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7643-8.1-user-minimal.json +0 -0
  55. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7643-8.2-user-full.json +0 -0
  56. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7643-8.3-enterprise_user.json +0 -0
  57. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7643-8.4-group.json +0 -0
  58. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7643-8.5-service_provider_configuration.json +0 -0
  59. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7643-8.6-resource_type-group.json +0 -0
  60. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7643-8.6-resource_type-user.json +0 -0
  61. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7643-8.7.1-schema-enterprise_user.json +0 -0
  62. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7643-8.7.1-schema-group.json +0 -0
  63. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7643-8.7.1-schema-user.json +0 -0
  64. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7643-8.7.2-schema-resource_type.json +0 -0
  65. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7643-8.7.2-schema-schema.json +0 -0
  66. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7643-8.7.2-schema-service_provider_configuration.json +0 -0
  67. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.12-error-bad_request.json +0 -0
  68. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.12-error-not_found.json +0 -0
  69. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.14-user-post_request.json +0 -0
  70. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.14-user-post_response.json +0 -0
  71. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.3-user-post_request.json +0 -0
  72. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.3-user-post_response.json +0 -0
  73. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.4.1-user-known-resource.json +0 -0
  74. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.4.2-list_response-partial_attributes.json +0 -0
  75. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.4.3-list_response-post_query.json +0 -0
  76. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.4.3-search_request.json +0 -0
  77. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.5.1-user-put_request.json +0 -0
  78. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.5.1-user-put_response.json +0 -0
  79. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.5.2.1-patch_op-add_emails.json +0 -0
  80. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.5.2.1-patch_op-add_members.json +0 -0
  81. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.5.2.2-patch_op-remove_all_members.json +0 -0
  82. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.5.2.2-patch_op-remove_and_add_one_member.json +0 -0
  83. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.5.2.2-patch_op-remove_multi_complex_value.json +0 -0
  84. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.5.2.2-patch_op-remove_one_member.json +0 -0
  85. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.5.2.3-patch_op-replace_all_email_values.json +0 -0
  86. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.5.2.3-patch_op-replace_all_members.json +0 -0
  87. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.5.2.3-patch_op-replace_street_address.json +0 -0
  88. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.5.2.3-patch_op-replace_user_work_address.json +0 -0
  89. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.6-error-not_found.json +0 -0
  90. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.7.1-bulk_request-circular_conflict.json +0 -0
  91. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.7.1-list_response-circular_reference.json +0 -0
  92. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.7.2-bulk_request-enterprise_user.json +0 -0
  93. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.7.2-bulk_request-temporary_identifier.json +0 -0
  94. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.7.2-bulk_response-temporary_identifier.json +0 -0
  95. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.7.3-bulk_request-multiple_operations.json +0 -0
  96. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.7.3-bulk_response-error_invalid_syntax.json +0 -0
  97. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.7.3-bulk_response-multiple_errors.json +0 -0
  98. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.7.3-bulk_response-multiple_operations.json +0 -0
  99. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.7.3-error-invalid_syntax.json +0 -0
  100. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.7.4-error-payload_too_large.json +0 -0
  101. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-3.9-user-partial_response.json +0 -0
  102. {scim2_models-0.3.5 → scim2_models-0.3.7}/samples/rfc7644-4-list_response-resource_types.json +0 -0
  103. {scim2_models-0.3.5 → scim2_models-0.3.7}/scim2_models/py.typed +0 -0
  104. {scim2_models-0.3.5 → scim2_models-0.3.7}/scim2_models/rfc7643/__init__.py +0 -0
  105. {scim2_models-0.3.5 → scim2_models-0.3.7}/scim2_models/rfc7644/__init__.py +0 -0
  106. {scim2_models-0.3.5 → scim2_models-0.3.7}/tests/__init__.py +0 -0
  107. {scim2_models-0.3.5 → scim2_models-0.3.7}/tests/conftest.py +0 -0
  108. {scim2_models-0.3.5 → scim2_models-0.3.7}/tests/test_enterprise_user.py +0 -0
  109. {scim2_models-0.3.5 → scim2_models-0.3.7}/tests/test_errors.py +0 -0
  110. {scim2_models-0.3.5 → scim2_models-0.3.7}/tests/test_group.py +0 -0
  111. {scim2_models-0.3.5 → scim2_models-0.3.7}/tests/test_list_response.py +0 -0
  112. {scim2_models-0.3.5 → scim2_models-0.3.7}/tests/test_models.py +0 -0
  113. {scim2_models-0.3.5 → scim2_models-0.3.7}/tests/test_schema.py +0 -0
  114. {scim2_models-0.3.5 → scim2_models-0.3.7}/tests/test_search_request.py +0 -0
  115. {scim2_models-0.3.5 → scim2_models-0.3.7}/tests/test_service_provider_configuration.py +0 -0
  116. {scim2_models-0.3.5 → scim2_models-0.3.7}/tests/test_user.py +0 -0
  117. {scim2_models-0.3.5 → scim2_models-0.3.7}/tests/test_utils.py +0 -0
@@ -34,6 +34,20 @@ jobs:
34
34
  - name: Run tests
35
35
  run: uv run pytest --showlocals
36
36
 
37
+ coverage:
38
+ name: py${{ matrix.python }} unit tests
39
+ runs-on: ubuntu-latest
40
+ steps:
41
+ - uses: actions/checkout@v4
42
+ - name: Install uv
43
+ uses: astral-sh/setup-uv@v3
44
+ with:
45
+ enable-cache: true
46
+ - name: Install Python ${{ matrix.python }}
47
+ run: uv python install ${{ matrix.python }}
48
+ - name: Run tests
49
+ run: uv run pytest --cov --cov-fail-under=100
50
+
37
51
  downstream-tests:
38
52
  name: py${{ matrix.python }} ${{ matrix.downstream }} downstream unit tests
39
53
  runs-on: ubuntu-latest
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  repos:
3
3
  - repo: https://github.com/astral-sh/ruff-pre-commit
4
- rev: 'v0.11.10'
4
+ rev: 'v0.12.3'
5
5
  hooks:
6
6
  - id: ruff
7
7
  args: [--fix, --exit-non-zero-on-fix]
@@ -16,9 +16,11 @@ repos:
16
16
  exclude: "\\.svg$|\\.map$|\\.min\\.css$|\\.min\\.js$|\\.po$|\\.pot$"
17
17
  - id: check-toml
18
18
  - repo: https://github.com/pre-commit/mirrors-mypy
19
- rev: v1.15.0
19
+ rev: v1.17.0
20
20
  hooks:
21
21
  - id: mypy
22
+ additional_dependencies:
23
+ - pydantic[email]>=2.7.0
22
24
  - repo: https://github.com/codespell-project/codespell
23
25
  rev: v2.4.1
24
26
  hooks:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scim2-models
3
- Version: 0.3.5
3
+ Version: 0.3.7
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
@@ -5,7 +5,7 @@ import scim2_models
5
5
 
6
6
 
7
7
  @pytest.fixture(autouse=True)
8
- def add_doctest_namespace(doctest_namespace):
8
+ def add_doctest_namespace(doctest_namespace: dict) -> dict:
9
9
  doctest_namespace["pydantic"] = pydantic
10
10
  imports = {item: getattr(scim2_models, item) for item in scim2_models.__all__}
11
11
  doctest_namespace.update(imports)
@@ -1,6 +1,21 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ [0.3.7] - 2025-07-17
5
+ --------------------
6
+
7
+ Fixed
8
+ ^^^^^
9
+ - All non strict mypy type annotations are fixed.
10
+
11
+ [0.3.6] - 2025-07-02
12
+ --------------------
13
+
14
+ Added
15
+ ^^^^^
16
+ - Fix :meth:`ResourceType.from_resource <scim2_models.ResourceType.from_resource>`
17
+ usage for resources with several extensions. :pr:`95`
18
+
4
19
  [0.3.5] - 2025-06-05
5
20
  --------------------
6
21
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "scim2-models"
7
- version = "0.3.5"
7
+ version = "0.3.7"
8
8
  description = "SCIM2 models serialization and validation with pydantic"
9
9
  authors = [{name="Yaal Coop", email="contact@yaal.coop"}]
10
10
  license = {file = "LICENSE"}
@@ -68,6 +68,7 @@ exclude_lines = [
68
68
  "pragma: no cover",
69
69
  "raise NotImplementedError",
70
70
  "except ImportError",
71
+ "if TYPE_CHECKING:",
71
72
  ]
72
73
 
73
74
  [tool.ruff.lint]
@@ -104,10 +105,20 @@ docstring-code-format = true
104
105
  addopts = "--doctest-modules --doctest-glob='*.rst'"
105
106
  doctest_optionflags= "ALLOW_UNICODE IGNORE_EXCEPTION_DETAIL ELLIPSIS"
106
107
 
107
- # [tool.mypy]
108
- # plugins = [
109
- # "pydantic.mypy"
110
- # ]
108
+ [tool.mypy]
109
+ plugins = [
110
+ "pydantic.mypy"
111
+ ]
112
+ warn_unused_ignores = true
113
+ exclude = [
114
+ "tests/",
115
+ "conftest.py",
116
+ ]
117
+
118
+ [tool.pydantic-mypy]
119
+ init_forbid_extra = true
120
+ init_typed = true
121
+ warn_required_dynamic_aliases = true
111
122
 
112
123
  [tool.tox]
113
124
  requires = ["tox>=4.19"]
@@ -1,15 +1,15 @@
1
+ from .annotations import CaseExact
2
+ from .annotations import Mutability
3
+ from .annotations import Required
4
+ from .annotations import Returned
5
+ from .annotations import Uniqueness
6
+ from .attributes import ComplexAttribute
7
+ from .attributes import MultiValuedComplexAttribute
1
8
  from .base import BaseModel
2
- from .base import CaseExact
3
- from .base import ComplexAttribute
4
- from .base import Context
5
- from .base import ExternalReference
6
- from .base import MultiValuedComplexAttribute
7
- from .base import Mutability
8
- from .base import Reference
9
- from .base import Required
10
- from .base import Returned
11
- from .base import Uniqueness
12
- from .base import URIReference
9
+ from .context import Context
10
+ from .reference import ExternalReference
11
+ from .reference import Reference
12
+ from .reference import URIReference
13
13
  from .rfc7643.enterprise_user import EnterpriseUser
14
14
  from .rfc7643.enterprise_user import Manager
15
15
  from .rfc7643.group import Group
@@ -0,0 +1,104 @@
1
+ from enum import Enum
2
+
3
+
4
+ class Mutability(str, Enum):
5
+ """A single keyword indicating the circumstances under which the value of the attribute can be (re)defined."""
6
+
7
+ read_only = "readOnly"
8
+ """The attribute SHALL NOT be modified."""
9
+
10
+ read_write = "readWrite"
11
+ """The attribute MAY be updated and read at any time."""
12
+
13
+ immutable = "immutable"
14
+ """The attribute MAY be defined at resource creation (e.g., POST) or at
15
+ record replacement via a request (e.g., a PUT).
16
+
17
+ The attribute SHALL NOT be updated.
18
+ """
19
+
20
+ write_only = "writeOnly"
21
+ """The attribute MAY be updated at any time.
22
+
23
+ Attribute values SHALL NOT be returned (e.g., because the value is a
24
+ stored hash). Note: An attribute with a mutability of "writeOnly"
25
+ usually also has a returned setting of "never".
26
+ """
27
+
28
+ _default = read_write
29
+
30
+
31
+ class Returned(str, Enum):
32
+ """A single keyword that indicates when an attribute and associated values are returned in response to a GET request or in response to a PUT, POST, or PATCH request."""
33
+
34
+ always = "always" # cannot be excluded
35
+ """The attribute is always returned, regardless of the contents of the
36
+ "attributes" parameter.
37
+
38
+ For example, "id" is always returned to identify a SCIM resource.
39
+ """
40
+
41
+ never = "never" # always excluded
42
+ """The attribute is never returned, regardless of the contents of the
43
+ "attributes" parameter."""
44
+
45
+ default = "default" # included by default but can be excluded
46
+ """The attribute is returned by default in all SCIM operation responses
47
+ where attribute values are returned, unless it is explicitly excluded."""
48
+
49
+ request = "request" # excluded by default but can be included
50
+ """The attribute is returned in response to any PUT, POST, or PATCH
51
+ operations if specified in the "attributes" parameter."""
52
+
53
+ _default = default
54
+
55
+
56
+ class Uniqueness(str, Enum):
57
+ """A single keyword value that specifies how the service provider enforces uniqueness of attribute values."""
58
+
59
+ none = "none"
60
+ """The values are not intended to be unique in any way."""
61
+
62
+ server = "server"
63
+ """The value SHOULD be unique within the context of the current SCIM
64
+ endpoint (or tenancy) and MAY be globally unique (e.g., a "username", email
65
+ address, or other server-generated key or counter).
66
+
67
+ No two resources on the same server SHOULD possess the same value.
68
+ """
69
+
70
+ global_ = "global"
71
+ """The value SHOULD be globally unique (e.g., an email address, a GUID, or
72
+ other value).
73
+
74
+ No two resources on any server SHOULD possess the same value.
75
+ """
76
+
77
+ _default = none
78
+
79
+
80
+ class Required(Enum):
81
+ """A Boolean value that specifies whether the attribute is required or not.
82
+
83
+ Missing required attributes raise a :class:`~pydantic.ValidationError` on :attr:`~scim2_models.Context.RESOURCE_CREATION_REQUEST` and :attr:`~scim2_models.Context.RESOURCE_REPLACEMENT_REQUEST` validations.
84
+ """
85
+
86
+ true = True
87
+ false = False
88
+
89
+ _default = false
90
+
91
+ def __bool__(self) -> bool:
92
+ return self.value
93
+
94
+
95
+ class CaseExact(Enum):
96
+ """A Boolean value that specifies whether a string attribute is case- sensitive or not."""
97
+
98
+ true = True
99
+ false = False
100
+
101
+ _default = false
102
+
103
+ def __bool__(self) -> bool:
104
+ return self.value
@@ -0,0 +1,57 @@
1
+ from inspect import isclass
2
+ from typing import Annotated
3
+ from typing import Any
4
+ from typing import Optional
5
+ from typing import get_origin
6
+
7
+ from pydantic import Field
8
+
9
+ from .annotations import Mutability
10
+
11
+ # This import will work because we'll import this module after BaseModel is defined
12
+ from .base import BaseModel
13
+ from .reference import Reference
14
+
15
+
16
+ class ComplexAttribute(BaseModel):
17
+ """A complex attribute as defined in :rfc:`RFC7643 §2.3.8 <7643#section-2.3.8>`."""
18
+
19
+ attribute_urn: Optional[str] = Field(None, exclude=True)
20
+
21
+ def get_attribute_urn(self, field_name: str) -> str:
22
+ """Build the full URN of the attribute.
23
+
24
+ See :rfc:`RFC7644 §3.10 <7644#section-3.10>`.
25
+ """
26
+ alias = (
27
+ self.__class__.model_fields[field_name].serialization_alias or field_name
28
+ )
29
+ return f"{self.attribute_urn}.{alias}"
30
+
31
+
32
+ class MultiValuedComplexAttribute(ComplexAttribute):
33
+ type: Optional[str] = None
34
+ """A label indicating the attribute's function."""
35
+
36
+ primary: Optional[bool] = None
37
+ """A Boolean value indicating the 'primary' or preferred attribute value
38
+ for this attribute."""
39
+
40
+ display: Annotated[Optional[str], Mutability.immutable] = None
41
+ """A human-readable name, primarily used for display purposes."""
42
+
43
+ value: Optional[Any] = None
44
+ """The value of an entitlement."""
45
+
46
+ ref: Optional[Reference] = Field(None, serialization_alias="$ref")
47
+ """The reference URI of a target resource, if the attribute is a
48
+ reference."""
49
+
50
+
51
+ def is_complex_attribute(type_: type) -> bool:
52
+ # issubclass raise a TypeError with 'Reference' on python < 3.11
53
+ return (
54
+ get_origin(type_) != Reference
55
+ and isclass(type_)
56
+ and issubclass(type_, (ComplexAttribute, MultiValuedComplexAttribute))
57
+ )