Skip to content

Commit

Permalink
patch : Json_schema extras
Browse files Browse the repository at this point in the history
  • Loading branch information
Simatwa committed Apr 12, 2024
1 parent 8d82652 commit 6e0843f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1 align="center">smartbetsAPI</h1>
<p align="center">
<a href="https://github.com/Simatwa/smartbetsAPI"><img alt="Github" src="https://img.shields.io/static/v1?logo=github&color=blueviolet&label=Test&message=Passing"/></a> <a href="LICENSE"><img alt="License" src="https://img.shields.io/static/v1?logo=GPL&color=Blue&message=GPL-v3&label=License"/></a> <a href="https://pypi.org/project/smartbetsAPI"><img alt="PyPi" src="https://img.shields.io/static/v1?logo=pypi&label=Pypi&message=v1.2.6&color=green"/></a> <a href="https://github.com/psf/black"><img alt="Black" src="https://img.shields.io/static/v1?logo=Black&label=Code-style&message=Black"/></a> <a href="#"><img alt="Accuracy" src="https://img.shields.io/static/v1?logo=accuracy&label=Accuracy&message=55%&color=yellow"/></a> <a href="#"><img alt="Passing" src="https://img.shields.io/static/v1?logo=Docs&label=Docs&message=Passing&color=green"/></a> <a href="#"><img alt="coverage" src="https://img.shields.io/static/v1?logo=Coverage&label=Coverage&message=100%&color=yellowgreen"/></a> <a href="#" alt="progress"><img alt="Progress" src="https://img.shields.io/static/v1?logo=Progress&label=Progress&message=95%&color=green"/></a> <a href="https://pepy.tech/project/smartbetsapi"><img src="https://static.pepy.tech/personalized-badge/smartbetsapi?period=total&units=international_system&left_color=grey&left_text=Downloads" alt="Downloads"></a></p><br>
<a href="https://github.com/Simatwa/smartbetsAPI"><img alt="Github" src="https://img.shields.io/static/v1?logo=github&color=blueviolet&label=Test&message=Passing"/></a> <a href="LICENSE"><img alt="License" src="https://img.shields.io/static/v1?logo=GPL&color=Blue&message=GPL-v3&label=License"/></a> <a href="https://pypi.org/project/smartbetsAPI"><img alt="PyPi" src="https://img.shields.io/pypi/v/smartbetsAPI?color=green"/></a> <a href="https://github.com/psf/black"><img alt="Black" src="https://img.shields.io/static/v1?logo=Black&label=Code-style&message=Black"/></a> <a href="#"><img alt="Accuracy" src="https://img.shields.io/static/v1?logo=accuracy&label=Accuracy&message=55%&color=yellow"/></a> <a href="#"><img alt="Passing" src="https://img.shields.io/static/v1?logo=Docs&label=Docs&message=Passing&color=green"/></a> <a href="#"><img alt="coverage" src="https://img.shields.io/static/v1?logo=Coverage&label=Coverage&message=100%&color=yellowgreen"/></a> <a href="#" alt="progress"><img alt="Progress" src="https://img.shields.io/static/v1?logo=Progress&label=Progress&message=95%&color=green"/></a> <a href="https://pepy.tech/project/smartbetsapi"><img src="https://static.pepy.tech/personalized-badge/smartbetsapi?period=total&units=international_system&left_color=grey&left_text=Downloads" alt="Downloads"></a></p><br>

> "Punter's choice"
Expand Down
2 changes: 1 addition & 1 deletion smartbets_API/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.2.6"
__version__ = "1.2.7"
__author__ = "Smartwa Caleb"
from .bet_at_rest_api_level import predictor as rest_api
from .predictor import predictor
Expand Down
50 changes: 40 additions & 10 deletions smartbets_API/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ def parse_handler():
"name": "Smartwa",
"url": "https://github.com/Simatwa",
"email": "simatwacaleb@proton.me",
},
docs_url="/v1/docs",
redoc_url="/v1/redoc",
# openapi_prefix="/v1",
}
)

v1_router = APIRouter(prefix="/v1", tags=["v1"])
Expand All @@ -113,6 +110,17 @@ class Match(BaseModel):
away: str
net: bool = False

model_config = {
"json_schema_extra": {
"examples": [
{
"home": "Arsenal",
"away": "Manchester United",
"net": False
}
]
}
}

class Prediction(BaseModel):
"""Match prediction
Expand All @@ -135,6 +143,22 @@ class Prediction(BaseModel):
result: str
pick: str

model_config = {
"json_schema_extra": {
"examples": [
{
"g": 10,
"gg": 70,
"ov15": 75,
"ov25": 40,
"ov35": 25,
"choice": 55.56,
"result": "1",
"pick": "ov15"
}
]
}
}

class ServerStatus(BaseModel):
"""Checks server's running status
Expand All @@ -145,6 +169,14 @@ class ServerStatus(BaseModel):
is_alive: bool = True
as_at: datetime = datetime.utcnow()

class TokenAuth(BaseModel):
"""
- `access_token` : Token value.
- `token_type` : bearer
"""
access_token:str
token_type:str


def verify_token(token: Annotated[str, Depends(v1_auth_scheme)]):
"""Ensures token passed match the one set"""
Expand All @@ -171,13 +203,11 @@ def server_status() -> ServerStatus:


@v1_router.post("/token")
def fetch_token(form_data: Annotated[OAuth2PasswordRequestForm, Depends()]):
"""Fetch api token"""
def fetch_token(form_data: Annotated[OAuth2PasswordRequestForm, Depends()]) -> TokenAuth:
"""Fetch api token
"""
if form_data.username == args.username and form_data.password == args.token:
return {
"access_token": args.token,
"token_type": "bearer",
}
return TokenAuth(**{"access_token": args.token,"token_type": "bearer",})
else:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
Expand Down

0 comments on commit 6e0843f

Please sign in to comment.