55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
|
|
// SPDX-License-Identifier: EUPL-1.2
|
||
|
|
|
||
|
|
package api
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"os"
|
||
|
|
|
||
|
|
"forge.lthn.ai/core/go/pkg/cli"
|
||
|
|
|
||
|
|
goapi "forge.lthn.ai/core/go-api"
|
||
|
|
)
|
||
|
|
|
||
|
|
func addSpecCommand(parent *cli.Command) {
|
||
|
|
var (
|
||
|
|
output string
|
||
|
|
format string
|
||
|
|
title string
|
||
|
|
version string
|
||
|
|
)
|
||
|
|
|
||
|
|
cmd := cli.NewCommand("spec", "Generate OpenAPI specification", "", func(cmd *cli.Command, args []string) error {
|
||
|
|
// Build spec from registered route groups.
|
||
|
|
// Additional groups can be added here as the platform grows.
|
||
|
|
builder := &goapi.SpecBuilder{
|
||
|
|
Title: title,
|
||
|
|
Description: "Lethean Core API",
|
||
|
|
Version: version,
|
||
|
|
}
|
||
|
|
|
||
|
|
// Start with the default tool bridge — future versions will
|
||
|
|
// auto-populate from the MCP tool registry once the bridge
|
||
|
|
// integration lands in the local go-ai module.
|
||
|
|
bridge := goapi.NewToolBridge("/tools")
|
||
|
|
groups := []goapi.RouteGroup{bridge}
|
||
|
|
|
||
|
|
if output != "" {
|
||
|
|
if err := goapi.ExportSpecToFile(output, format, builder, groups); err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
fmt.Fprintf(os.Stderr, "Spec written to %s\n", output)
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
return goapi.ExportSpec(os.Stdout, format, builder, groups)
|
||
|
|
})
|
||
|
|
|
||
|
|
cli.StringFlag(cmd, &output, "output", "o", "", "Write spec to file instead of stdout")
|
||
|
|
cli.StringFlag(cmd, &format, "format", "f", "json", "Output format: json or yaml")
|
||
|
|
cli.StringFlag(cmd, &title, "title", "t", "Lethean Core API", "API title in spec")
|
||
|
|
cli.StringFlag(cmd, &version, "version", "V", "1.0.0", "API version in spec")
|
||
|
|
|
||
|
|
parent.AddCommand(cmd)
|
||
|
|
}
|