Skip to content

Commit

Permalink
feat: add metadata for api(auto-versioning)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vyvy-vi committed Sep 20, 2021
1 parent 6a601a3 commit 8cd366a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 37 deletions.
30 changes: 1 addition & 29 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ itsdangerous = "^2.0.1"
python-dotenv = "^0.19.0"
pre-commit = "^2.13.0"
requests = "^2.26.0"
toml = "^0.10.2"

[tool.poetry.dev-dependencies]
flake8 = "^3.9.2"
Expand Down
18 changes: 18 additions & 0 deletions src/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
import json

import toml


def get_json(file):
with open(f"src/data/{file}.json", "r") as f:
return json.load(f)[file]


def get_meta():
with open("pyproject.toml", "r") as f:
f = toml.load(f)["tool"]["poetry"]
return {
"name": f["name"],
"version": "v" + f["version"],
"description": f["description"],
"license": {
"name": f["license"],
"url": "https://github.com/Heptagram-Bot/api/blob/master/LICENSE.md",
},
"repo": f["repository"],
"author": {"name": "Vyvy-vi", "url": "https://github.com/Vyvy-vi"},
}
18 changes: 10 additions & 8 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import uvicorn
from fastapi import FastAPI, responses

# from pydantic import BaseModel
from .dependencies import get_meta
from .routes import coinflip, diceroll, jokes, quotes

# from pydantic import BaseModel

META = get_meta()

app = FastAPI(
title="heptagram-api",
description="An API for the Heptagram Bot",
contact={"name": "Vyvy-vi", "url": "https://github.com/Vyvy-vi"},
license_info={
"name": "BSD-3-Clause",
"url": "https://github.com/Heptagram-Bot/api/blob/master/LICENSE.md",
},
title=META["name"],
description=META["description"],
contact=META["author"],
license_info=META["license"],
version=META["version"],
)
app.include_router(coinflip.router)
app.include_router(jokes.router)
Expand Down

0 comments on commit 8cd366a

Please sign in to comment.