package api import ( "net/http" "os" "path/filepath" "runtime" ) // openAPISpecPath returns the path to the OpenAPI spec file func openAPISpecPath() string { // Get the directory of this source file _, filename, _, _ := runtime.Caller(0) dir := filepath.Dir(filename) // Navigate to repo root and then to api/ return filepath.Join(dir, "..", "..", "api", "openapi.yaml") } // ServeOpenAPISpec serves the OpenAPI specification as YAML func ServeOpenAPISpec(w http.ResponseWriter, _ *http.Request) { specPath := openAPISpecPath() data, err := os.ReadFile(specPath) if err != nil { http.Error(w, "Failed to read OpenAPI spec", http.StatusInternalServerError) return } w.Header().Set("Content-Type", "application/yaml") w.WriteHeader(http.StatusOK) _, _ = w.Write(data) }