feat: migrate receiver to Fuego framework with OpenAPI generation
Replace net/http handlers with Fuego framework for automatic OpenAPI 3.0 spec generation. Add generated Go client package, OpenAPI extraction script, and update Makefile with separate build/run targets for both binaries. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
479c13f596
commit
bc9d0dd8ea
11 changed files with 2245 additions and 252 deletions
64
scripts/extract-openapi/main.go
Normal file
64
scripts/extract-openapi/main.go
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
//go:build ignore
|
||||
|
||||
// ABOUTME: Extracts OpenAPI spec from Fuego server without running it.
|
||||
// ABOUTME: Run with: go run scripts/extract-openapi/main.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"github.com/getkin/kin-openapi/openapi3"
|
||||
"github.com/go-fuego/fuego"
|
||||
|
||||
"edp.buildth.ing/DevFW-CICD/forgejo-runner-sizer/internal/receiver"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Create a minimal handler (store is nil, won't be used)
|
||||
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
|
||||
handler := receiver.NewHandler(nil, logger, "dummy", "dummy", 0)
|
||||
|
||||
// Create Fuego server with OpenAPI config
|
||||
s := fuego.NewServer(
|
||||
fuego.WithoutStartupMessages(),
|
||||
fuego.WithEngineOptions(
|
||||
fuego.WithOpenAPIConfig(fuego.OpenAPIConfig{
|
||||
DisableLocalSave: true,
|
||||
Info: &openapi3.Info{
|
||||
Title: "Forgejo Runner Resource Collector API",
|
||||
Version: "1.0.0",
|
||||
Description: "HTTP service that receives and stores CI/CD resource metrics from collectors, providing query and sizing recommendation APIs.",
|
||||
Contact: &openapi3.Contact{
|
||||
Name: "API Support",
|
||||
URL: "https://edp.buildth.ing/DevFW-CICD/forgejo-runner-sizer",
|
||||
},
|
||||
License: &openapi3.License{
|
||||
Name: "Apache 2.0",
|
||||
URL: "http://www.apache.org/licenses/LICENSE-2.0.html",
|
||||
},
|
||||
},
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
// Register routes to populate OpenAPI spec
|
||||
handler.RegisterRoutes(s)
|
||||
|
||||
// Output OpenAPI spec as JSON
|
||||
spec, err := json.MarshalIndent(s.OpenAPI.Description(), "", " ")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error marshaling OpenAPI spec: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if err := os.WriteFile("docs/openapi.json", spec, 0644); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error writing docs/openapi.json: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Println("Generated docs/openapi.json")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue