Skip to content

Implement base model class with serialization helpers #36

Description

@codebestia

All response models should share a common base that provides from_dict(data: dict), to_dict(), and a readable __repr__. Using Pydantic as the base eliminates boilerplate validation and gives free type coercion.

Proposed Steps:

  • Create src/shade/models/__init__.py and src/shade/models/base.py.
  • Define ShadeObject(pydantic.BaseModel) with model_config = ConfigDict(populate_by_name=True, extra="allow").
  • Add to_dict() method wrapping model.model_dump().
  • Add a classmethod from_dict(cls, data: dict) that constructs the model.
  • Override __repr__ to show class name and primary ID field.

Acceptance Criteria:

  • All models can be round-tripped through from_dict(m.to_dict()) without data loss.
  • Unknown fields from the API are accepted without raising (extra="allow").
  • repr(model) shows the class name and key ID field.
  • Pydantic validation errors surface as InvalidRequestError, not raw ValidationError.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions