// Command gen writes docs/reference.md from the configuration structs, and // docs/admin-api.openapi.json from the admin API route table. // // Run by `go generate ./...`, and checked by a test, so the reference cannot // quietly stop describing the code. package main import ( "fmt" "os" "path/filepath" "runtime" "gitea.mynodes.xyz/ilker/llmgw/internal/control/adminapi" "gitea.mynodes.xyz/ilker/llmgw/internal/docgen" "gitea.mynodes.xyz/ilker/llmgw/internal/docgen/openapi" ) func main() { // The repository root, found from this file rather than from the working // directory, so `go generate ./...` produces the same document wherever // it is run from. _, self, _, ok := runtime.Caller(0) if !ok { fmt.Fprintln(os.Stderr, "error: cannot locate the generator") os.Exit(1) } root := filepath.Join(filepath.Dir(self), "..", "..", "..") paths := make([]string, len(docgen.Sources)) for i, s := range docgen.Sources { paths[i] = filepath.Join(root, s) } blocks, err := docgen.Collect(paths) if err != nil { fmt.Fprintln(os.Stderr, "error:", err) os.Exit(1) } if err := os.WriteFile(filepath.Join(root, "docs", "reference.md"), []byte(docgen.Render(blocks)), 0o644); err != nil { fmt.Fprintln(os.Stderr, "error:", err) os.Exit(1) } if err := os.WriteFile(filepath.Join(root, "internal", "docgen", "reference_gen.go"), []byte(docgen.RenderGo(blocks)), 0o644); err != nil { fmt.Fprintln(os.Stderr, "error:", err) os.Exit(1) } fmt.Printf("docs/reference.md and internal/docgen/reference_gen.go: %d blocks\n", len(blocks)) spec, err := openapi.Generate(root, adminapi.Routes, adminapi.PathParams) if err != nil { fmt.Fprintln(os.Stderr, "error:", err) os.Exit(1) } if err := os.WriteFile(filepath.Join(root, "docs", "admin-api.openapi.json"), spec, 0o644); err != nil { fmt.Fprintln(os.Stderr, "error:", err) os.Exit(1) } fmt.Printf("docs/admin-api.openapi.json: %d routes\n", len(adminapi.Routes)) }