Return typed Pydantic models from external API calls and centralize request logging by status class#129
Draft
Return typed Pydantic models from external API calls and centralize request logging by status class#129
Conversation
Copilot
AI
changed the title
[WIP] Update external API to return Pydantic models
Return typed Pydantic models from external API calls and centralize request logging by status class
Feb 13, 2026
Co-authored-by: fabieu <43068791+fabieu@users.noreply.github.com> # Conflicts: # surehub_api/services/pets.py
Co-authored-by: fabieu <43068791+fabieu@users.noreply.github.com>
Co-authored-by: fabieu <43068791+fabieu@users.noreply.github.com>
Co-authored-by: fabieu <43068791+fabieu@users.noreply.github.com>
- Update dependencies - Rename http_utils to response_handler
…131) This updates the OpenAPI entity modules so class definitions are consistently ordered alphabetically by class name, as requested. Reordering introduced forward-reference ordering changes, so annotation evaluation was adjusted to keep imports and type references stable. - **Class layout normalization** - Reordered all class blocks alphabetically in: - `surehub_api/entities/official.py` - `surehub_api/entities/official_v2.py` - Preserved class contents/signatures; only declaration order changed. - **Forward-reference safety after reorder** - Added postponed annotation evaluation in both files: - `from __future__ import annotations` - Prevents import-time `NameError` when a class annotation references a type declared later in the file after alphabetical sorting. - **Ordering guardrail** - Extended `tests/test_official_openapi_models.py` with a file-level check that class declarations in both entity files remain alphabetically sorted. ```python # added at top of both files from __future__ import annotations ``` <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: fabieu <43068791+fabieu@users.noreply.github.com> Co-authored-by: Fabian Eulitz <dev@sustineo.de>
50ef431 to
0663e65
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
External API responses were being propagated as untyped dicts, requiring repeated ad-hoc parsing in services. This change introduces centralized response-model validation and consistent per-request logging with status-based severity (2xx→INFO, 4xx/5xx→ERROR).
Centralized response parsing and validation
http_utils.extract_response_data(...)with an optionalmodelparameter.pydantic.TypeAdapter, enabling direct return of typed models (including collections likeList[official.Pet]).Centralized external request logging
http_utils.raise_for_status(...)using response metadata (method,url,status_code).INFOfor 2xxERRORfor 4xx/5xxService-layer adoption of typed models
extract_response_data(...)across:dashboard,reports,households,devices,petsRelated consistency cleanup
devicesservice tosettings.endpointfor all device/tag calls.💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.