50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
from pydantic import BaseModel, Field
|
|
from typing import Optional, List
|
|
from datetime import datetime
|
|
from uuid import UUID
|
|
|
|
class ShipBase(BaseModel):
|
|
name: str = Field(..., min_length=1, description="Ship's name")
|
|
|
|
class ShipCreate(ShipBase):
|
|
pass
|
|
|
|
class ShipUpdate(BaseModel):
|
|
name: Optional[str] = Field(None, min_length=1, description="Ship's name")
|
|
|
|
class ShipSchema(ShipBase):
|
|
id: UUID
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
schema_extra = {
|
|
"example": {
|
|
"id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
|
|
"name": "HMS Victory",
|
|
"created_at": "2023-01-01T12:00:00",
|
|
"updated_at": "2023-01-01T12:00:00"
|
|
}
|
|
}
|
|
|
|
class ShipNameResponse(BaseModel):
|
|
name: str = Field(..., description="Ship's name")
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
schema_extra = {
|
|
"example": {
|
|
"name": "HMS Victory"
|
|
}
|
|
}
|
|
|
|
class ShipNamesListResponse(BaseModel):
|
|
ships: List[str] = Field(..., description="List of ship names")
|
|
|
|
class Config:
|
|
schema_extra = {
|
|
"example": {
|
|
"ships": ["HMS Victory", "HMS Endeavour", "HMS Bounty"]
|
|
}
|
|
} |