Skip to content

Commit

Permalink
fix: actually fix wrong schema and docker build automation
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperiio committed Nov 11, 2024
1 parent 0308406 commit e34b14f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: build-docker-image

on:
release:
types: [created]
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
workflow_dispatch:

env:
Expand Down
25 changes: 4 additions & 21 deletions app/schemas.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from datetime import datetime
from typing import Dict, List, Optional
from typing import Dict, List
from pydantic import BaseModel, ConfigDict, Field, RootModel, validator
from zoneinfo import ZoneInfo

from app.models import ElectricityPrice


class PriceData(BaseModel):
Expand All @@ -13,15 +14,6 @@ class PriceData(BaseModel):
description="Ratio of price to daily average"
)

@validator('price_daily_average_ratio')
def validate_ratio(cls, v: float) -> float:
"""Ensure ratio is reasonable."""
if v < 0:
raise ValueError("Price ratio cannot be negative")
if v > 10: # Arbitrary reasonable maximum
raise ValueError("Price ratio seems unreasonably high")
return v


class ElectricityPriceResponse(RootModel[Dict[datetime, PriceData]]):
"""Response schema for electricity price endpoints."""
Expand All @@ -37,7 +29,7 @@ class ElectricityPriceResponse(RootModel[Dict[datetime, PriceData]]):
},
"2024-01-01T13:00:00+00:00": {
"price": 45.0,
"price_daily_average_ratio": 1.1,
"price_daily_average_ratio": -0.9,
}
}
},
Expand Down Expand Up @@ -80,15 +72,6 @@ def timestamp_must_be_aware(cls, v: datetime) -> datetime:
raise ValueError("Timestamp must be timezone-aware")
return v

@validator('price')
def price_must_be_reasonable(cls, v: float) -> float:
"""Validate price is within reasonable bounds."""
if v < -1000: # Adjust these bounds based on your needs
raise ValueError("Price seems unreasonably low")
if v > 10000:
raise ValueError("Price seems unreasonably high")
return v

model_config = ConfigDict(
json_schema_extra={
"example": {
Expand Down
8 changes: 7 additions & 1 deletion release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
"release-type": "simple",
"include-component-in-tag": false,
"tag-separator": "v",
"packages": {
".": {
"release-type": "simple",
"draft": false,
"prerelease": false,
"bump-minor-pre-major": true,
"bump-patch-for-minor-pre-major": true
}
}
}
}

0 comments on commit e34b14f

Please sign in to comment.