You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2.4 KiB
2.4 KiB
+++ title = "Implement GET /api/ — serve OpenAPI spec as JSON" priority = 5 status = "done" ticket_type = "task" dependencies = ["1f5bb5", "8892d5"] +++
The `quotesdb` API is built with Axum + Tokio, targeting Cloudflare Workers via `workers-rs`. It serves JSON at `/api/*` endpoints and persists data to Cloudflare D1 (production) or a local SQLite file via Turso (development). Source lives in `src/bin/api/`.Shared types and utilities are in src/lib.rs — code placed there must compile for both the host target and wasm32-unknown-unknown.
The GET /api/ endpoint serves the OpenAPI 3.1.0 specification as JSON. This endpoint requires no authentication and is the entry point for API documentation and client generation.
Strategy resolved in TRIAGE 2ec8b1: compile-time embed via build.rs (ticket 8892d5).
The build.rs converts api/openapi.yaml to JSON at build time and writes it to
$OUT_DIR/openapi.json. The handler serves this as a static &str:
// Embedded at compile time by build.rs — no runtime parsing, no serde_yaml in binary.
const OPENAPI_JSON: &str = include_str!(concat!(env!("OUT_DIR"), "/openapi.json"));
pub async fn get_openapi_spec() -> impl IntoResponse {
(
[(axum::http::header::CONTENT_TYPE, "application/json")],
OPENAPI_JSON,
)
}
Register the route in the Axum router as GET /api/.
cargo fmt
cargo check
cargo clippy
cargo test
`feat(quotesdb): implement GET /api/ to serve OpenAPI spec as JSON`