Skip to content

Commit

Permalink
Add: Example Swagger Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
happycastle114 committed Nov 16, 2023
1 parent 5cea864 commit 14eceed
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 5 deletions.
64 changes: 64 additions & 0 deletions model/ResponseType.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class LocalInfo(BaseModel):
name : str
id : int


class RegionInfo(BaseModel):
name : str
id : int
Expand All @@ -14,24 +15,87 @@ class PartyInfo(BaseModel):
name : str
color : int

model_config = {
"json_schema_extra": {
"example" : {
"name": "정상이당",
"count": 10
}
}
}



class Diversity(BaseModel):
action_type : str
value : float

model_config = {
"json_schema_extra": {
"example" : {
"action_type": "sex",
"value": 0.5
}
}
}



class AgeInfo(BaseModel):
minAge: int
maxAge: int
count: int

model_config = {
"json_schema_extra": {
"example" : {
"minAge": 10,
"maxAge": 20,
"count": 10
}
}
}

class PartyInfo(BaseModel):
party : str
count : int

model_config = {
"json_schema_extra": {
"example" : {
"party": "숭구리당당",
"count": 10
}
}
}

class SexInfo(BaseModel):
sex: str
count: int

model_config = {
"json_schema_extra": {
"example" : {
"sex": "male",
"count": 10
}
}
}

T = TypeVar("T", SexInfo, PartyInfo, AgeInfo)

class ChartResponse(BaseModel, Generic[T]):
data : list[T]

model_config = {
"json_schema_extra": {
"example" : {
"data": [
{
"sex": "male",
"count": 10
}
]
}
}
}
36 changes: 31 additions & 5 deletions routers/scrapResult.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
from fastapi import APIRouter

router = APIRouter()
from model.ResponseType import *

@router.get("/")
async def getScrapResult():
router = APIRouter(prefix="/localCouncil", tags=["localCouncil"])

@router.get("/regionInfo", response_model=RegionInfo)
async def getRegionInfo():
try:
return []
except Exception as e:
print(e)
return []

@router.get("/partyInfo", response_model=PartyInfo)
async def getPartyInfo():
try:
return []
except Exception as e:
print(e)
return []

@router.get("/template-data/{metroId}/{localId}/{factor}", response_model=Diversity)
async def getTemplateData(metroId: int, localId: int, factor: str):
try:
return []
except Exception as e:
print(e)
return []

@router.get("/chart-data/{metroId}/{localId}/{factor}", response_model=ChartResponse)
async def getTemplateData(metroId: int, localId: int, factor: str):
try:
return {"message": "No World"}
return []
except Exception as e:
print(e)
return {"message": "Error"}
return []

0 comments on commit 14eceed

Please sign in to comment.