feat(cli): add bundled health app scaffold and init command
- ship OpenAPI-first health check template as package data - add CLI to copy scaffold into new project directories - include OpenAPI spec, routes, and bootstrap example - enable fast startup for OpenAPI-first services
This commit is contained in:
31
openapi_first/cli.py
Normal file
31
openapi_first/cli.py
Normal file
@@ -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}")
|
||||
8
openapi_first/templates/health_app/main.py
Normal file
8
openapi_first/templates/health_app/main.py
Normal file
@@ -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",
|
||||
)
|
||||
22
openapi_first/templates/health_app/openapi.yaml
Normal file
22
openapi_first/templates/health_app/openapi.yaml
Normal file
@@ -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
|
||||
2
openapi_first/templates/health_app/routes.py
Normal file
2
openapi_first/templates/health_app/routes.py
Normal file
@@ -0,0 +1,2 @@
|
||||
def get_health():
|
||||
return {"status": "ok"}
|
||||
Reference in New Issue
Block a user