cli/cmd/api/cmd_spec.go
Snider d6eec4d240
Some checks are pending
Security Scan / Go Vulnerability Check (push) Waiting to run
Security Scan / Dependency & Config Scan (push) Waiting to run
Security Scan / Secret Detection (push) Waiting to run
feat(api): add core api spec and core api sdk commands
New command group for OpenAPI spec generation and SDK codegen:
- `core api spec` generates OpenAPI 3.1 spec (JSON/YAML) from route groups
- `core api sdk` generates client SDKs via openapi-generator-cli
- Adds go-api dependency for SpecBuilder, ExportSpec, SDKGenerator

Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 01:28:58 +00:00

54 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)
}