Skip to content

Commit

Permalink
refactor: rewrite model attributes in snake case
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed May 24, 2024
1 parent dd99958 commit 9730234
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 172 deletions.
7 changes: 7 additions & 0 deletions pydantic_scim2/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from pydantic import BaseModel
from pydantic import ConfigDict
from pydantic.alias_generators import to_camel


class SCIM2Model(BaseModel):
model_config = ConfigDict(extra="allow", alias_generator=to_camel)
13 changes: 7 additions & 6 deletions pydantic_scim2/enterprise_user.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from typing import Optional

from pydantic import AnyUrl
from pydantic import BaseModel
from pydantic import Field

from .base import SCIM2Model

class Manager(BaseModel):

class Manager(SCIM2Model):
value: Optional[str] = Field(
None,
description="The id of the SCIM resource representingthe User's manager. REQUIRED.",
Expand All @@ -15,18 +16,18 @@ class Manager(BaseModel):
alias="$ref",
description="The URI of the SCIM resource representing the User's manager. REQUIRED.",
)
displayName: Optional[str] = Field(
display_name: Optional[str] = Field(
None,
description="The displayName of the User's manager. OPTIONAL and READ-ONLY.",
)


class EnterpriseUser(BaseModel):
employeeNumber: Optional[str] = Field(
class EnterpriseUser(SCIM2Model):
employee_number: Optional[str] = Field(
None,
description="Numeric or alphanumeric identifier assigned to a person, typically based on order of hire or association with anorganization.",
)
costCenter: Optional[str] = Field(
cost_center: Optional[str] = Field(
None, description="Identifies the name of a cost center."
)
organization: Optional[str] = Field(
Expand Down
6 changes: 3 additions & 3 deletions pydantic_scim2/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from typing import Optional

from pydantic import AnyUrl
from pydantic import BaseModel
from pydantic import ConfigDict
from pydantic import Field

from .base import SCIM2Model
from .resource import Resource


class GroupMember(BaseModel):
class GroupMember(SCIM2Model):
model_config = ConfigDict(populate_by_name=True)

value: Optional[str] = None
Expand All @@ -23,7 +23,7 @@ class GroupMember(BaseModel):

class Group(Resource):
schemas: List[str] = ["urn:ietf:params:scim:schemas:core:2.0:Group"]
displayName: str = Field(
display_name: str = Field(
..., description="A human-readable name for the Group. REQUIRED."
)
members: Optional[List[GroupMember]] = Field(
Expand Down
17 changes: 11 additions & 6 deletions pydantic_scim2/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
from typing import List
from typing import Optional

from pydantic import BaseModel
from pydantic import ConfigDict
from pydantic.alias_generators import to_camel

from .base import SCIM2Model

class Meta(BaseModel):

class Meta(SCIM2Model):
"""All "meta" sub-attributes are assigned by the service provider (have a
"mutability" of "readOnly"), and all of these sub-attributes have a
"returned" characteristic of "default".
Expand All @@ -15,7 +18,7 @@ class Meta(BaseModel):
sub-attributes:
"""

resourceType: Optional[str] = None
resource_type: Optional[str] = None
"""The name of the resource type of the resource.
This attribute has a mutability of "readOnly" and "caseExact" as
Expand All @@ -28,7 +31,7 @@ class Meta(BaseModel):
This attribute MUST be a DateTime.
"""

lastModified: Optional[datetime] = None
last_modified: Optional[datetime] = None
"""The most recent DateTime that the details of this resource were updated
at the service provider.
Expand Down Expand Up @@ -60,7 +63,9 @@ class Meta(BaseModel):
"""


class Resource(BaseModel):
class Resource(SCIM2Model):
model_config = ConfigDict(extra="allow", alias_generator=to_camel)

schemas: List[str]
"""The "schemas" attribute is a REQUIRED attribute and is an array of
Strings containing URIs that are used to indicate the namespaces of the
Expand Down Expand Up @@ -97,7 +102,7 @@ class Resource(BaseModel):
Section 9 for additional considerations regarding privacy.
"""

externalId: Optional[str] = None
external_id: Optional[str] = None
"""A String that is an identifier for the resource as defined by the
provisioning client.
Expand Down
8 changes: 4 additions & 4 deletions pydantic_scim2/resource_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
from typing import Optional

from pydantic import AnyUrl
from pydantic import BaseModel
from pydantic import ConfigDict
from pydantic import Field

from .base import SCIM2Model
from .resource import Meta
from .resource import Resource


class SchemaExtension(BaseModel):
class SchemaExtension(SCIM2Model):
model_config = ConfigDict(extra="allow")

schema_: AnyUrl = Field(
Expand Down Expand Up @@ -48,7 +48,7 @@ class ResourceType(Resource):
Section 9 for additional considerations regarding privacy.
"""

externalId: Optional[str] = None
external_id: Optional[str] = None
"""A String that is an identifier for the resource as defined by the
provisioning client.
Expand Down Expand Up @@ -91,6 +91,6 @@ class ResourceType(Resource):
schema_: AnyUrl = Field(
..., alias="schema", description="The resource type's primary/base schema URI."
)
schemaExtensions: Optional[List[SchemaExtension]] = Field(
schema_extensions: Optional[List[SchemaExtension]] = Field(
None, description="A list of URIs of the resource type's schema extensions."
)
17 changes: 9 additions & 8 deletions pydantic_scim2/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import Optional
from typing import Union

from pydantic import BaseModel
from pydantic import Discriminator
from pydantic import Tag

Expand All @@ -14,8 +13,10 @@
from pydantic_scim2.service_provider import ServiceProviderConfiguration
from pydantic_scim2.user import User

from .base import SCIM2Model

class SCIMError(BaseModel):

class SCIMError(SCIM2Model):
detail: str
status: int
schemas: List[str] = ["urn:ietf:params:scim:api:messages:2.0:Error"]
Expand All @@ -39,13 +40,13 @@ class PatchOp(str, Enum):
add = "add"


class PatchOperation(BaseModel):
class PatchOperation(SCIM2Model):
op: PatchOp
path: str
value: Optional[Any] = None


class PatchRequest(BaseModel):
class PatchRequest(SCIM2Model):
Operations: List[PatchOperation]


Expand All @@ -56,10 +57,10 @@ def get_model_name(obj: Any):
return obj["meta"]["resourceType"]


class ListResponse(BaseModel):
totalResults: int
startIndex: int
itemsPerPage: int
class ListResponse(SCIM2Model):
total_results: int
start_index: int
items_per_page: int
Resources: List[
Annotated[
Union[
Expand Down
27 changes: 13 additions & 14 deletions pydantic_scim2/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
from typing import List
from typing import Optional

from pydantic import BaseModel

from .base import SCIM2Model
from .resource import Meta


Expand All @@ -12,17 +11,17 @@ class AttributeKind(str, Enum):
boolean = "boolean"
decimal = "decimal"
integer = "integer"
dateTime = "dateTime"
date_time = "dateTime"
reference = "reference"
binary = "binary"
complex = "complex"


class Mutability(str, Enum):
readOnly = "readOnly"
readWrite = "readWrite"
read_only = "readOnly"
read_write = "readWrite"
immutable = "immutable"
writeOnly = "writeOnly"
write_only = "writeOnly"


class Returned(str, Enum):
Expand All @@ -38,18 +37,18 @@ class Uniqueness(str, Enum):
global_ = "global"


class Attribute(BaseModel):
class Attribute(SCIM2Model):
name: str
"""The attribute's name."""

type: AttributeKind
"""The attribute's data type."""

subAttributes: Optional[List["Attribute"]] = None
sub_attributes: Optional[List["Attribute"]] = None
"""When an attribute is of type "complex", "subAttributes" defines a set of
sub-attributes."""

multiValued: bool
multi_valued: bool
"""A Boolean value indicating the attribute's plurality."""

description: str
Expand All @@ -59,15 +58,15 @@ class Attribute(BaseModel):
"""A Boolean value that specifies whether or not the attribute is
required."""

canonicalValues: Optional[List[str]] = None
canonical_values: Optional[List[str]] = None
"""A collection of suggested canonical values that MAY be used (e.g.,
"work" and "home")."""

caseExact: bool = True
case_exact: bool = True
"""A Boolean value that specifies whether or not a string attribute is case
sensitive."""

mutability: Mutability = Mutability.readWrite
mutability: Mutability = Mutability.read_write
"""A single keyword indicating the circumstances under which the value of
the attribute can be (re)defined."""

Expand All @@ -80,12 +79,12 @@ class Attribute(BaseModel):
"""A single keyword value that specifies how the service provider enforces
uniqueness of attribute values."""

referenceTypes: Optional[List[str]] = None
reference_types: Optional[List[str]] = None
"""A multi-valued array of JSON strings that indicate the SCIM resource
types that may be referenced."""


class Schema(BaseModel):
class Schema(SCIM2Model):
id: str
"""The unique URI of the schema."""

Expand Down
Loading

0 comments on commit 9730234

Please sign in to comment.