diff --git a/openapi_first/cli.py b/openapi_first/cli.py new file mode 100644 index 0000000..cb1b1fb --- /dev/null +++ b/openapi_first/cli.py @@ -0,0 +1,31 @@ +import shutil +import argparse +from pathlib import Path +from importlib import resources + + +def copy_health_app_template(target_dir: Path) -> None: + """ + Copy the bundled health app template into a target directory. + """ + target_dir = target_dir.resolve() + target_dir.mkdir(parents=True, exist_ok=True) + + with resources.files("fastapi_openapi_first.templates").joinpath("health_app") as src: + shutil.copytree(src, target_dir, dirs_exist_ok=True) + + +def main(): + parser = argparse.ArgumentParser( + description="FastAPI OpenAPI-first scaffolding tools" + ) + parser.add_argument( + "path", + nargs="?", + default="health-app", + help="Target directory for the health app", + ) + + args = parser.parse_args() + copy_health_app_template(Path(args.path)) + print(f"Health app created at {args.path}") diff --git a/openapi_first/templates/health_app/main.py b/openapi_first/templates/health_app/main.py new file mode 100644 index 0000000..0c8677f --- /dev/null +++ b/openapi_first/templates/health_app/main.py @@ -0,0 +1,8 @@ +from openapi_first.app import OpenAPIFirstApp +import routes + +app = OpenAPIFirstApp( + openapi_path="openapi.yaml", + routes_module=routes, + title="Health Check Service", +) diff --git a/openapi_first/templates/health_app/openapi.yaml b/openapi_first/templates/health_app/openapi.yaml new file mode 100644 index 0000000..8ae56ff --- /dev/null +++ b/openapi_first/templates/health_app/openapi.yaml @@ -0,0 +1,22 @@ +openapi: 3.0.3 +info: + title: Health Check Service + version: "1.0.0" + +paths: + /health: + get: + operationId: get_health + summary: Service health check + description: Returns basic liveness status of the service. + responses: + "200": + description: Service is healthy + content: + application/json: + schema: + type: object + properties: + status: + type: string + example: ok diff --git a/openapi_first/templates/health_app/routes.py b/openapi_first/templates/health_app/routes.py new file mode 100644 index 0000000..e155d2b --- /dev/null +++ b/openapi_first/templates/health_app/routes.py @@ -0,0 +1,2 @@ +def get_health(): + return {"status": "ok"} diff --git a/pyproject.toml b/pyproject.toml index 9584442..8ac764b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,6 +54,8 @@ dependencies = [ "pyyaml>=6.0.1", ] +[project.scripts] +openapi-first = "openapi_first.cli:main" [project.optional-dependencies] dev = [ @@ -81,6 +83,9 @@ Versions = "https://git.aetoskia.com/aetos/openapi-first/tags" [tool.setuptools] packages = { find = { include = ["openapi_first*"] } } +[tool.setuptools.package-data] +fastapi_openapi_first = ["templates/**/*"] + [tool.ruff] line-length = 100