Replace custom schemas with pydantic models for improved validation
This PR modernizes the FioBank library by replacing custom transaction and info schemas with Pydantic models, significantly simplifying the codebase while improving type safety and maintainability.
Changes
Removed complex custom schemas:
- Eliminated 53 lines of complex
transaction_schemaandinfo_schemadictionaries - Replaced manual field mapping and validation logic with declarative Pydantic models
Added robust Pydantic models:
-
Transactionmodel with 20+ fields mapped from API column format (column0-column27) -
Infomodel for account information with proper type conversion - Custom validators handle complex API response format with nested
{name, value, id}objects - Automatic type conversion for both float and Decimal modes
Simplified parsing methods:
-
_parse_info()and_parse_transactions()now use clean model validation - Preserved all existing functionality including data refinements and transformations
- Maintained backward compatibility - public interface unchanged
Benefits
- Type safety: Automatic validation and type conversion via Pydantic
- Maintainability: Clear model definitions replace complex dictionaries
- Robustness: Better error handling and validation
- Documentation: Models serve as living documentation of data structures
- Code reduction: Eliminated complex custom parsing logic
Example
Before (custom schema):
self.transaction_schema = {
"column0": ("date", coerce_date),
"column1": ("amount", self.float_type),
# ... 20+ more fields
}
# Complex parsing logic in _parse_transactions()
After (Pydantic model):
class Transaction(BaseModel):
date: date | None = Field(None, alias="column0")
amount: float | Decimal | None = Field(None, alias="column1")
# ... clean field definitions with validators
The implementation includes conditional import fallback for environments where Pydantic isn't installed yet, ensuring smooth deployment.
Fixes #32.
[!WARNING]
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
astral.sh
- Triggering command:
curl -LsSf REDACTED(dns block)If you need me to access, download, or install something from one of these locations, you can either:
- Configure Actions setup steps to set up my environment, which run before the firewall is enabled
- Add the appropriate URLs or hosts to the custom allowlist in this repository's Copilot coding agent settings (admins only)
💡 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 in the docs.