Automated Action f942ce333e Fix OpenAPI schema generation and Pydantic model compatibility
- Update Pydantic models to use model_config instead of Config class for v2 compatibility
- Fix CORS settings to allow all origins in development mode
- Fix circular imports in auth.py
- Remove unused imports
2025-05-26 11:12:38 +00:00

40 lines
1.1 KiB
Python

from typing import List
from pydantic import field_validator
from pydantic_settings import BaseSettings
from pathlib import Path
class Settings(BaseSettings):
PROJECT_NAME: str = "E-Commerce API"
VERSION: str = "0.1.0"
API_V1_STR: str = "/api/v1"
# CORS Settings
CORS_ORIGINS: List[str] = ["*"] # Allow all origins for development
@field_validator("CORS_ORIGINS", mode="before")
@classmethod
def validate_cors_origins(cls, v):
if isinstance(v, str) and not v.startswith("["):
return [i.strip() for i in v.split(",")]
elif isinstance(v, (list, str)):
return v
raise ValueError(v)
# JWT Settings
SECRET_KEY: str = "supersecretkey" # Change in production
ALGORITHM: str = "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
# Database Settings
DB_DIR: Path = Path("/app") / "storage" / "db"
class Config:
env_file = ".env"
case_sensitive = True
settings = Settings()
# Ensure DB directory exists
settings.DB_DIR.mkdir(parents=True, exist_ok=True)