fix(cmd/api): normalise spec export formats
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
e6f2d1286b
commit
be7616d437
3 changed files with 21 additions and 2 deletions
|
|
@ -108,7 +108,7 @@ func addSDKCommand(parent *cli.Command) {
|
|||
|
||||
cli.StringFlag(cmd, &lang, "lang", "l", "", "Target language(s), comma-separated (e.g. go,python,typescript-fetch)")
|
||||
cli.StringFlag(cmd, &output, "output", "o", "./sdk", "Output directory for generated SDKs")
|
||||
cli.StringFlag(cmd, &specFile, "spec", "s", "", "Path to existing OpenAPI spec (generates from MCP tools if not provided)")
|
||||
cli.StringFlag(cmd, &specFile, "spec", "s", "", "Path to an existing OpenAPI spec (generates a temporary spec from registered route groups and the built-in tool bridge if not provided)")
|
||||
cli.StringFlag(cmd, &packageName, "package", "p", "lethean", "Package name for generated SDK")
|
||||
cli.StringFlag(cmd, &title, "title", "t", defaultSDKTitle, "API title in generated spec")
|
||||
cli.StringFlag(cmd, &description, "description", "d", defaultSDKDescription, "API description in generated spec")
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"iter"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
|
|
@ -47,7 +48,7 @@ func ExportSpecIter(w io.Writer, format string, builder *SpecBuilder, groups ite
|
|||
}
|
||||
|
||||
func writeSpec(w io.Writer, format string, data []byte, op string) error {
|
||||
switch format {
|
||||
switch strings.ToLower(strings.TrimSpace(format)) {
|
||||
case "json":
|
||||
_, err := w.Write(data)
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -66,6 +66,24 @@ func TestExportSpec_Good_YAML(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestExportSpec_Good_NormalisesFormatInput(t *testing.T) {
|
||||
builder := &api.SpecBuilder{Title: "Test", Description: "Test API", Version: "1.0.0"}
|
||||
|
||||
var buf bytes.Buffer
|
||||
if err := api.ExportSpec(&buf, " YAML ", builder, nil); err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
var spec map[string]any
|
||||
if err := yaml.Unmarshal(buf.Bytes(), &spec); err != nil {
|
||||
t.Fatalf("output is not valid YAML: %v", err)
|
||||
}
|
||||
|
||||
if spec["openapi"] != "3.1.0" {
|
||||
t.Fatalf("expected openapi=3.1.0, got %v", spec["openapi"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestExportSpec_Bad_InvalidFormat(t *testing.T) {
|
||||
builder := &api.SpecBuilder{Title: "Test", Description: "Test API", Version: "1.0.0"}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue