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
This commit is contained in:
parent
538a985c8e
commit
f942ce333e
@ -11,6 +11,8 @@ from app.core.deps import get_current_user
|
|||||||
from app.db.session import get_db
|
from app.db.session import get_db
|
||||||
from app.models.user import User
|
from app.models.user import User
|
||||||
from app.schemas.token import Token
|
from app.schemas.token import Token
|
||||||
|
from app.schemas.user import User as UserSchema
|
||||||
|
from app.schemas.user import UserCreate
|
||||||
from app.services import user as user_service
|
from app.services import user as user_service
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
@ -61,7 +63,6 @@ def register_user(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Create user
|
# Create user
|
||||||
from app.schemas.user import UserCreate
|
|
||||||
user_in = UserCreate(email=form_data.username, password=form_data.password)
|
user_in = UserCreate(email=form_data.username, password=form_data.password)
|
||||||
user = user_service.create(db, obj_in=user_in)
|
user = user_service.create(db, obj_in=user_in)
|
||||||
|
|
||||||
@ -75,12 +76,11 @@ def register_user(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/me", response_model=Any)
|
@router.get("/me", response_model=UserSchema)
|
||||||
def read_users_me(
|
def read_users_me(
|
||||||
current_user: User = Depends(get_current_user),
|
current_user: User = Depends(get_current_user),
|
||||||
) -> Any:
|
) -> Any:
|
||||||
"""
|
"""
|
||||||
Get current user
|
Get current user
|
||||||
"""
|
"""
|
||||||
from app.schemas.user import User as UserSchema
|
return current_user
|
||||||
return UserSchema.from_orm(current_user)
|
|
@ -1,5 +1,5 @@
|
|||||||
from typing import List
|
from typing import List
|
||||||
from pydantic import AnyHttpUrl, field_validator
|
from pydantic import field_validator
|
||||||
from pydantic_settings import BaseSettings
|
from pydantic_settings import BaseSettings
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@ -10,7 +10,7 @@ class Settings(BaseSettings):
|
|||||||
API_V1_STR: str = "/api/v1"
|
API_V1_STR: str = "/api/v1"
|
||||||
|
|
||||||
# CORS Settings
|
# CORS Settings
|
||||||
CORS_ORIGINS: List[AnyHttpUrl] = []
|
CORS_ORIGINS: List[str] = ["*"] # Allow all origins for development
|
||||||
|
|
||||||
@field_validator("CORS_ORIGINS", mode="before")
|
@field_validator("CORS_ORIGINS", mode="before")
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -22,8 +22,9 @@ class CartItemInDBBase(CartItemBase):
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
class Config:
|
model_config = {
|
||||||
orm_mode = True
|
"from_attributes": True
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class CartItem(CartItemInDBBase):
|
class CartItem(CartItemInDBBase):
|
||||||
@ -48,8 +49,9 @@ class CartInDBBase(CartBase):
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
class Config:
|
model_config = {
|
||||||
orm_mode = True
|
"from_attributes": True
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class Cart(CartInDBBase):
|
class Cart(CartInDBBase):
|
||||||
|
@ -24,8 +24,9 @@ class CategoryInDBBase(CategoryBase):
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
class Config:
|
model_config = {
|
||||||
orm_mode = True
|
"from_attributes": True
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Additional properties to return via API
|
# Additional properties to return via API
|
||||||
|
@ -21,8 +21,9 @@ class OrderItemInDBBase(OrderItemBase):
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
class Config:
|
model_config = {
|
||||||
orm_mode = True
|
"from_attributes": True
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class OrderItem(OrderItemInDBBase):
|
class OrderItem(OrderItemInDBBase):
|
||||||
@ -52,8 +53,9 @@ class OrderInDBBase(OrderBase):
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
class Config:
|
model_config = {
|
||||||
orm_mode = True
|
"from_attributes": True
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class Order(OrderInDBBase):
|
class Order(OrderInDBBase):
|
||||||
@ -66,5 +68,6 @@ class OrderList(BaseModel):
|
|||||||
total_amount: float
|
total_amount: float
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
|
|
||||||
class Config:
|
model_config = {
|
||||||
orm_mode = True
|
"from_attributes": True
|
||||||
|
}
|
@ -35,8 +35,9 @@ class ProductInDBBase(ProductBase):
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
class Config:
|
model_config = {
|
||||||
orm_mode = True
|
"from_attributes": True
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Additional properties to return via API
|
# Additional properties to return via API
|
||||||
@ -53,5 +54,6 @@ class ProductList(BaseModel):
|
|||||||
category_id: str
|
category_id: str
|
||||||
is_active: bool
|
is_active: bool
|
||||||
|
|
||||||
class Config:
|
model_config = {
|
||||||
orm_mode = True
|
"from_attributes": True
|
||||||
|
}
|
@ -27,8 +27,9 @@ class UserInDBBase(UserBase):
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
class Config:
|
model_config = {
|
||||||
orm_mode = True
|
"from_attributes": True
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Additional properties to return via API
|
# Additional properties to return via API
|
||||||
|
2
main.py
2
main.py
@ -17,7 +17,7 @@ app = FastAPI(
|
|||||||
# Set CORS middleware
|
# Set CORS middleware
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=settings.CORS_ORIGINS,
|
allow_origins=["*"], # Allow all origins for development
|
||||||
allow_credentials=True,
|
allow_credentials=True,
|
||||||
allow_methods=["*"],
|
allow_methods=["*"],
|
||||||
allow_headers=["*"],
|
allow_headers=["*"],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user