59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
package health
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/veylant/ia-gateway/docs"
|
|
)
|
|
|
|
// DocsYAMLHandler serves the raw OpenAPI 3.1 YAML spec at /docs/openapi.yaml.
|
|
func DocsYAMLHandler(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "application/yaml")
|
|
w.WriteHeader(http.StatusOK)
|
|
_, _ = w.Write(docs.OpenAPIYAML)
|
|
}
|
|
|
|
// DocsHTMLHandler serves a Swagger UI page at /docs.
|
|
// The UI is loaded from the official CDN — no npm build required.
|
|
func DocsHTMLHandler(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
w.WriteHeader(http.StatusOK)
|
|
_, _ = w.Write([]byte(swaggerHTML))
|
|
}
|
|
|
|
// swaggerHTML is an inline Swagger UI page that loads the spec from /docs/openapi.yaml.
|
|
const swaggerHTML = `<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Veylant IA API — Documentation</title>
|
|
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@5/swagger-ui.css">
|
|
<style>
|
|
body { margin: 0; padding: 0; }
|
|
.topbar { display: none !important; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="swagger-ui"></div>
|
|
<script src="https://unpkg.com/swagger-ui-dist@5/swagger-ui-bundle.js"></script>
|
|
<script>
|
|
window.onload = function () {
|
|
SwaggerUIBundle({
|
|
url: "/docs/openapi.yaml",
|
|
dom_id: '#swagger-ui',
|
|
presets: [
|
|
SwaggerUIBundle.presets.apis,
|
|
SwaggerUIBundle.SwaggerUIStandalonePreset
|
|
],
|
|
layout: "BaseLayout",
|
|
deepLinking: true,
|
|
tryItOutEnabled: true,
|
|
filter: true
|
|
});
|
|
};
|
|
</script>
|
|
</body>
|
|
</html>
|
|
`
|