|
1 | | -from collections import UserString |
2 | 1 | from enum import Enum |
3 | 2 | from inspect import isclass |
4 | 3 | from typing import Annotated |
5 | 4 | from typing import Any |
6 | | -from typing import Generic |
7 | 5 | from typing import Optional |
8 | | -from typing import TypeVar |
9 | 6 | from typing import get_args |
10 | 7 | from typing import get_origin |
11 | 8 |
|
|
14 | 11 | from pydantic import ConfigDict |
15 | 12 | from pydantic import Field |
16 | 13 | from pydantic import FieldSerializationInfo |
17 | | -from pydantic import GetCoreSchemaHandler |
18 | 14 | from pydantic import SerializationInfo |
19 | 15 | from pydantic import SerializerFunctionWrapHandler |
20 | 16 | from pydantic import ValidationInfo |
|
24 | 20 | from pydantic import model_serializer |
25 | 21 | from pydantic import model_validator |
26 | 22 | from pydantic_core import PydanticCustomError |
27 | | -from pydantic_core import core_schema |
28 | | -from typing_extensions import NewType |
29 | 23 | from typing_extensions import Self |
30 | 24 |
|
31 | 25 | from scim2_models.context import Context |
| 26 | +from scim2_models.reference import Reference |
32 | 27 | from scim2_models.utils import normalize_attribute_name |
33 | 28 | from scim2_models.utils import to_camel |
34 | 29 |
|
35 | 30 | from .utils import UNION_TYPES |
36 | 31 |
|
37 | | -ReferenceTypes = TypeVar("ReferenceTypes") |
38 | | -URIReference = NewType("URIReference", str) |
39 | | -ExternalReference = NewType("ExternalReference", str) |
40 | | - |
41 | 32 |
|
42 | 33 | def validate_model_attribute(model: type["BaseModel"], attribute_base: str) -> None: |
43 | 34 | """Validate that an attribute name or a sub-attribute path exist for a given model.""" |
@@ -125,43 +116,6 @@ def contains_attribute_or_subattributes( |
125 | 116 | ) |
126 | 117 |
|
127 | 118 |
|
128 | | -class Reference(UserString, Generic[ReferenceTypes]): |
129 | | - """Reference type as defined in :rfc:`RFC7643 §2.3.7 <7643#section-2.3.7>`. |
130 | | -
|
131 | | - References can take different type parameters: |
132 | | -
|
133 | | - - Any :class:`~scim2_models.Resource` subtype, or :class:`~typing.ForwardRef` of a Resource subtype, or :data:`~typing.Union` of those, |
134 | | - - :data:`~scim2_models.ExternalReference` |
135 | | - - :data:`~scim2_models.URIReference` |
136 | | -
|
137 | | - Examples |
138 | | - -------- |
139 | | -
|
140 | | - .. code-block:: python |
141 | | -
|
142 | | - class Foobar(Resource): |
143 | | - bff: Reference[User] |
144 | | - managers: Reference[Union["User", "Group"]] |
145 | | - photo: Reference[ExternalReference] |
146 | | - website: Reference[URIReference] |
147 | | -
|
148 | | - """ |
149 | | - |
150 | | - @classmethod |
151 | | - def __get_pydantic_core_schema__( |
152 | | - cls, |
153 | | - _source: type[Any], |
154 | | - _handler: GetCoreSchemaHandler, |
155 | | - ) -> core_schema.CoreSchema: |
156 | | - return core_schema.no_info_after_validator_function( |
157 | | - cls._validate, core_schema.str_schema() |
158 | | - ) |
159 | | - |
160 | | - @classmethod |
161 | | - def _validate(cls, input_value: str, /) -> str: |
162 | | - return input_value |
163 | | - |
164 | | - |
165 | 119 | class Mutability(str, Enum): |
166 | 120 | """A single keyword indicating the circumstances under which the value of the attribute can be (re)defined.""" |
167 | 121 |
|
|
0 commit comments