Add OpenAPI/Swagger docs at /api/docs

Full OpenAPI 3.0.3 spec with all 30+ endpoints, schemas, and query params.
Swagger UI served from unpkg CDN at /api/docs, raw spec at /api/openapi.yaml.
This commit is contained in:
2026-03-16 03:15:56 +01:00
parent e79e1d1736
commit 83ab8c4cf9
2 changed files with 2033 additions and 0 deletions
File diff suppressed because it is too large Load Diff
+43
View File
@@ -0,0 +1,43 @@
use axum::http::{header, HeaderValue};
use axum::response::{Html, IntoResponse};
const OPENAPI_SPEC: &str = include_str!("../../openapi.yaml");
pub async fn openapi_yaml() -> impl IntoResponse {
(
[(header::CONTENT_TYPE, HeaderValue::from_static("text/yaml; charset=utf-8"))],
OPENAPI_SPEC,
)
}
pub async fn swagger_ui() -> impl IntoResponse {
Html(r#"<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HerbAPI — API Documentation</title>
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@5/swagger-ui.css">
<style>
html { box-sizing: border-box; overflow-y: scroll; }
*, *::before, *::after { box-sizing: inherit; }
body { margin: 0; background: #fafafa; }
</style>
</head>
<body>
<div id="swagger-ui"></div>
<script src="https://unpkg.com/swagger-ui-dist@5/swagger-ui-bundle.js"></script>
<script>
SwaggerUIBundle({
url: '/api/openapi.yaml',
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIBundle.SwaggerUIStandalonePreset,
],
layout: 'BaseLayout',
});
</script>
</body>
</html>"#)
}