Skip to content

Commit

Permalink
Refactor models module
Browse files Browse the repository at this point in the history
Refactor the models module to improve the code reuse.
  • Loading branch information
JAVGan committed Sep 18, 2024
1 parent e417c77 commit 5053262
Showing 1 changed file with 36 additions and 31 deletions.
67 changes: 36 additions & 31 deletions starmap_client/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@
]


class PaginationMetadata(TypedDict):
"""Datastructure of the metadata about the paginated query."""

first: str
last: str
next: Optional[str]
page: int
per_page: int
previous: Optional[str]
total: int
total_pages: int


class PaginatedRawData(TypedDict):
"""Represent a paginated StArMap data in its raw format (Dict)."""

items: List[Any]
nav: PaginationMetadata


class Workflow(str, Enum):
"""Define the valid workflows for StArMap."""

Expand Down Expand Up @@ -85,14 +105,8 @@ def from_json(cls, json: Any):


@frozen
class StarmapBaseData:
"""Represent the common data present in StArMap entities."""

id: Optional[str] = field(validator=optional(instance_of(str)))
"""
The unique ID for a StArMap model.
This field is never set on :class:`~starmap_client.models.QueryResponse`.
"""
class MetaMixin:
"""Mixin for defining the meta attribute and its validator."""

meta: Optional[Dict[str, Any]] = field()
"""Dictionary with additional information related to a VM image."""
Expand All @@ -109,7 +123,18 @@ def _is_meta_dict_of_str_any(self, attribute: Attribute, value: Any):


@frozen
class Destination(StarmapBaseData, StarmapJSONDecodeMixin):
class StarmapBaseData(StarmapJSONDecodeMixin, MetaMixin):
"""Represent the common data present in StArMap entities."""

id: Optional[str] = field(validator=optional(instance_of(str)))
"""
The unique ID for a StArMap model.
This field is never set on :class:`~starmap_client.models.QueryResponse`.
"""


@frozen
class Destination(StarmapBaseData):
"""Represent a destination entry from Mapping."""

architecture: Optional[str] = field(validator=optional(instance_of(str)))
Expand Down Expand Up @@ -146,7 +171,7 @@ class Destination(StarmapBaseData, StarmapJSONDecodeMixin):


@frozen
class Mapping(StarmapBaseData, StarmapJSONDecodeMixin):
class Mapping(StarmapBaseData):
"""Represent a marketplace Mapping from Policy."""

destinations: List[Destination] = field(
Expand Down Expand Up @@ -176,7 +201,7 @@ class Mapping(StarmapBaseData, StarmapJSONDecodeMixin):


@frozen
class Policy(StarmapBaseData, StarmapJSONDecodeMixin):
class Policy(StarmapBaseData):
"""Represent a StArMap policy."""

mappings: List[Mapping] = field(
Expand Down Expand Up @@ -237,23 +262,3 @@ def _preprocess_json(cls, json: Any) -> Dict[str, Any]:
mappings[c] = dst
json["clouds"] = mappings
return json


class PaginationMetadata(TypedDict):
"""Datastructure of the metadata about the paginated query."""

first: str
last: str
next: Optional[str]
page: int
per_page: int
previous: Optional[str]
total: int
total_pages: int


class PaginatedRawData(TypedDict):
"""Represent a paginated StArMap data in its raw format (Dict)."""

items: List[Any]
nav: PaginationMetadata

0 comments on commit 5053262

Please sign in to comment.