From b8fd020bb2b8445cf50e70b07b1bf1dab9679aae Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 06:26:01 +0000 Subject: [PATCH] refactor(cmd/api): thread swagger path through sdk spec builder Co-Authored-By: Virgil --- cmd/api/cmd_sdk.go | 6 +++--- cmd/api/cmd_test.go | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd/api/cmd_sdk.go b/cmd/api/cmd_sdk.go index 7c8568e..d632af1 100644 --- a/cmd/api/cmd_sdk.go +++ b/cmd/api/cmd_sdk.go @@ -57,8 +57,7 @@ func addSDKCommand(parent *cli.Command) { // If no spec file provided, generate one to a temp file. if specFile == "" { - builder := sdkSpecBuilder(title, description, version, graphqlPath, graphqlPlayground, ssePath, wsPath, pprofEnabled, expvarEnabled, termsURL, contactName, contactURL, contactEmail, licenseName, licenseURL, externalDocsDescription, externalDocsURL, servers) - builder.SwaggerPath = swaggerPath + builder := sdkSpecBuilder(title, description, version, swaggerPath, graphqlPath, graphqlPlayground, ssePath, wsPath, pprofEnabled, expvarEnabled, termsURL, contactName, contactURL, contactEmail, licenseName, licenseURL, externalDocsDescription, externalDocsURL, servers) groups := sdkSpecGroupsIter() tmpFile, err := os.CreateTemp("", "openapi-*.json") @@ -127,11 +126,12 @@ func addSDKCommand(parent *cli.Command) { parent.AddCommand(cmd) } -func sdkSpecBuilder(title, description, version, graphqlPath string, graphqlPlayground bool, ssePath, wsPath string, pprofEnabled, expvarEnabled bool, termsURL, contactName, contactURL, contactEmail, licenseName, licenseURL, externalDocsDescription, externalDocsURL, servers string) *goapi.SpecBuilder { +func sdkSpecBuilder(title, description, version, swaggerPath, graphqlPath string, graphqlPlayground bool, ssePath, wsPath string, pprofEnabled, expvarEnabled bool, termsURL, contactName, contactURL, contactEmail, licenseName, licenseURL, externalDocsDescription, externalDocsURL, servers string) *goapi.SpecBuilder { return &goapi.SpecBuilder{ Title: title, Description: description, Version: version, + SwaggerPath: swaggerPath, GraphQLPath: graphqlPath, GraphQLPlayground: graphqlPlayground, SSEPath: ssePath, diff --git a/cmd/api/cmd_test.go b/cmd/api/cmd_test.go index dd8c659..aee5630 100644 --- a/cmd/api/cmd_test.go +++ b/cmd/api/cmd_test.go @@ -700,6 +700,7 @@ func TestAPISDKCmd_Good_TempSpecUsesMetadataFlags(t *testing.T) { "Custom SDK API", "Custom SDK description", "9.9.9", + "/docs", "/gql", true, "/events", @@ -754,6 +755,9 @@ func TestAPISDKCmd_Good_TempSpecUsesMetadataFlags(t *testing.T) { if _, ok := paths["/gql"]; !ok { t.Fatal("expected GraphQL path to be included in generated spec") } + if got := builder.SwaggerPath; got != "/docs" { + t.Fatalf("expected swagger path to be preserved in sdk spec builder, got %v", got) + } if _, ok := paths["/gql/playground"]; !ok { t.Fatal("expected GraphQL playground path to be included in generated spec") }