-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathscim_object.py
More file actions
66 lines (54 loc) · 2.35 KB
/
scim_object.py
File metadata and controls
66 lines (54 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""Base SCIM object classes with schema identification."""
from typing import TYPE_CHECKING
from typing import Annotated
from typing import Any
from typing import Optional
from .annotations import Required
from .base import BaseModel
from .context import Context
if TYPE_CHECKING:
pass
class ScimObject(BaseModel):
schemas: Annotated[list[str], Required.true]
"""The "schemas" attribute is a REQUIRED attribute and is an array of
Strings containing URIs that are used to indicate the namespaces of the
SCIM schemas that define the attributes present in the current JSON
structure."""
def _prepare_model_dump(
self,
scim_ctx: Optional[Context] = Context.DEFAULT,
**kwargs: Any,
) -> dict[str, Any]:
kwargs.setdefault("context", {}).setdefault("scim", scim_ctx)
if scim_ctx:
kwargs.setdefault("exclude_none", True)
kwargs.setdefault("by_alias", True)
return kwargs
def model_dump(
self,
*args: Any,
scim_ctx: Optional[Context] = Context.DEFAULT,
**kwargs: Any,
) -> dict[str, Any]:
"""Create a model representation that can be included in SCIM messages by using Pydantic :code:`BaseModel.model_dump`.
:param scim_ctx: If a SCIM context is passed, some default values of
Pydantic :code:`BaseModel.model_dump` are tuned to generate valid SCIM
messages. Pass :data:`None` to get the default Pydantic behavior.
"""
dump_kwargs = self._prepare_model_dump(scim_ctx, **kwargs)
if scim_ctx:
dump_kwargs.setdefault("mode", "json")
return super(BaseModel, self).model_dump(*args, **dump_kwargs)
def model_dump_json(
self,
*args: Any,
scim_ctx: Optional[Context] = Context.DEFAULT,
**kwargs: Any,
) -> str:
"""Create a JSON model representation that can be included in SCIM messages by using Pydantic :code:`BaseModel.model_dump_json`.
:param scim_ctx: If a SCIM context is passed, some default values of
Pydantic :code:`BaseModel.model_dump` are tuned to generate valid SCIM
messages. Pass :data:`None` to get the default Pydantic behavior.
"""
dump_kwargs = self._prepare_model_dump(scim_ctx, **kwargs)
return super(BaseModel, self).model_dump_json(*args, **dump_kwargs)