diff --git a/cmd/api/cmd_sdk.go b/cmd/api/cmd_sdk.go index da85d75..1ea0949 100644 --- a/cmd/api/cmd_sdk.go +++ b/cmd/api/cmd_sdk.go @@ -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") diff --git a/export.go b/export.go index d5d68d8..3095a6c 100644 --- a/export.go +++ b/export.go @@ -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 diff --git a/export_test.go b/export_test.go index 1288381..926b5c3 100644 --- a/export_test.go +++ b/export_test.go @@ -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"}