Skip to content

Commit 1f980e4

Browse files
bricefclaude
andcommitted
Add interactive API docs at /docs using Scalar
Serves a Scalar API reference UI that renders the OpenAPI spec from /openapi.json. Single embedded HTML page, loads Scalar from CDN. Landing page updated to link to /docs instead of raw /openapi.json. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ade3e16 commit 1f980e4

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

internal/http/apidocs.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>TaskFlow API</title>
7+
</head>
8+
<body>
9+
<script id="api-reference" data-url="/openapi.json"></script>
10+
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
11+
</body>
12+
</html>

internal/http/landing.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ <h1>TaskFlow</h1>
7676
<p class="tagline">Kanban boards with workflow state machines, built for human + AI collaboration.</p>
7777
<div class="links">
7878
<a class="primary" href="/dashboard">Dashboard</a>
79-
<a class="secondary" href="/openapi.json">API Spec</a>
79+
<a class="secondary" href="/docs">API Docs</a>
8080
<a class="secondary" href="/health">Health</a>
8181
<a class="secondary" href="https://github.com/bricef/taskflow">GitHub</a>
8282
</div>

internal/http/routes.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import (
1818
//go:embed landing.html
1919
var landingPage []byte
2020

21+
//go:embed apidocs.html
22+
var apiDocsPage []byte
23+
2124
// Route is the HTTP-layer representation of a domain resource or operation.
2225
type Route struct {
2326
Name string
@@ -213,6 +216,10 @@ func (s *Server) registerRoutes() {
213216
w.Header().Set("Content-Type", "application/json")
214217
w.Write(s.openAPISpec)
215218
})
219+
r.Get("/docs", func(w http.ResponseWriter, _ *http.Request) {
220+
w.Header().Set("Content-Type", "text/html; charset=utf-8")
221+
w.Write(apiDocsPage)
222+
})
216223

217224
// Authenticated routes — derived from resources and operations.
218225
r.Group(func(r chi.Router) {

0 commit comments

Comments
 (0)