From c383d85923c895c84790a9b1be28619ac690e0b0 Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 09:04:30 +0000 Subject: [PATCH] refactor(cmd/api): centralize spec builder config Co-Authored-By: Virgil --- cmd/api/cmd_sdk.go | 68 ++++++++++++++++++++++++++++++--------------- cmd/api/cmd_test.go | 44 ++++++++++++++--------------- 2 files changed, 66 insertions(+), 46 deletions(-) diff --git a/cmd/api/cmd_sdk.go b/cmd/api/cmd_sdk.go index ab8a1c7..528e237 100644 --- a/cmd/api/cmd_sdk.go +++ b/cmd/api/cmd_sdk.go @@ -59,7 +59,29 @@ func addSDKCommand(parent *cli.Command) { // If no spec file provided, generate one to a temp file. if specFile == "" { - builder, err := sdkSpecBuilder(title, summary, description, version, swaggerPath, graphqlPath, graphqlPlayground, ssePath, wsPath, pprofEnabled, expvarEnabled, termsURL, contactName, contactURL, contactEmail, licenseName, licenseURL, externalDocsDescription, externalDocsURL, servers, securitySchemes) + builder, err := sdkSpecBuilder(specBuilderConfig{ + title: title, + summary: summary, + description: description, + version: version, + swaggerPath: swaggerPath, + graphqlPath: graphqlPath, + graphqlPlayground: graphqlPlayground, + ssePath: ssePath, + wsPath: wsPath, + pprofEnabled: pprofEnabled, + expvarEnabled: expvarEnabled, + termsURL: termsURL, + contactName: contactName, + contactURL: contactURL, + contactEmail: contactEmail, + licenseName: licenseName, + licenseURL: licenseURL, + externalDocsDescription: externalDocsDescription, + externalDocsURL: externalDocsURL, + servers: servers, + securitySchemes: securitySchemes, + }) if err != nil { return err } @@ -136,29 +158,29 @@ func addSDKCommand(parent *cli.Command) { parent.AddCommand(cmd) } -func sdkSpecBuilder(title, summary, description, version, swaggerPath, graphqlPath string, graphqlPlayground bool, ssePath, wsPath string, pprofEnabled, expvarEnabled bool, termsURL, contactName, contactURL, contactEmail, licenseName, licenseURL, externalDocsDescription, externalDocsURL, servers, securitySchemes string) (*goapi.SpecBuilder, error) { +func sdkSpecBuilder(cfg specBuilderConfig) (*goapi.SpecBuilder, error) { return newSpecBuilder(specBuilderConfig{ - title: title, - summary: summary, - description: description, - version: version, - swaggerPath: swaggerPath, - graphqlPath: graphqlPath, - graphqlPlayground: graphqlPlayground, - ssePath: ssePath, - wsPath: wsPath, - pprofEnabled: pprofEnabled, - expvarEnabled: expvarEnabled, - termsURL: termsURL, - contactName: contactName, - contactURL: contactURL, - contactEmail: contactEmail, - licenseName: licenseName, - licenseURL: licenseURL, - externalDocsDescription: externalDocsDescription, - externalDocsURL: externalDocsURL, - servers: servers, - securitySchemes: securitySchemes, + title: cfg.title, + summary: cfg.summary, + description: cfg.description, + version: cfg.version, + swaggerPath: cfg.swaggerPath, + graphqlPath: cfg.graphqlPath, + graphqlPlayground: cfg.graphqlPlayground, + ssePath: cfg.ssePath, + wsPath: cfg.wsPath, + pprofEnabled: cfg.pprofEnabled, + expvarEnabled: cfg.expvarEnabled, + termsURL: cfg.termsURL, + contactName: cfg.contactName, + contactURL: cfg.contactURL, + contactEmail: cfg.contactEmail, + licenseName: cfg.licenseName, + licenseURL: cfg.licenseURL, + externalDocsDescription: cfg.externalDocsDescription, + externalDocsURL: cfg.externalDocsURL, + servers: cfg.servers, + securitySchemes: cfg.securitySchemes, }) } diff --git a/cmd/api/cmd_test.go b/cmd/api/cmd_test.go index f03be1b..4df3385 100644 --- a/cmd/api/cmd_test.go +++ b/cmd/api/cmd_test.go @@ -794,29 +794,27 @@ func TestAPISDKCmd_Good_TempSpecUsesMetadataFlags(t *testing.T) { api.RegisterSpecGroups(specCmdStubGroup{}) - builder, err := sdkSpecBuilder( - "Custom SDK API", - "Custom SDK overview", - "Custom SDK description", - "9.9.9", - "/docs", - "/gql", - true, - "/events", - "/ws", - true, - true, - "https://example.com/terms", - "SDK Support", - "https://example.com/support", - "support@example.com", - "EUPL-1.2", - "https://eupl.eu/1.2/en/", - "", - "", - "https://api.example.com, /, https://api.example.com", - `{"apiKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key"}}`, - ) + builder, err := sdkSpecBuilder(specBuilderConfig{ + title: "Custom SDK API", + summary: "Custom SDK overview", + description: "Custom SDK description", + version: "9.9.9", + swaggerPath: "/docs", + graphqlPath: "/gql", + graphqlPlayground: true, + ssePath: "/events", + wsPath: "/ws", + pprofEnabled: true, + expvarEnabled: true, + termsURL: "https://example.com/terms", + contactName: "SDK Support", + contactURL: "https://example.com/support", + contactEmail: "support@example.com", + licenseName: "EUPL-1.2", + licenseURL: "https://eupl.eu/1.2/en/", + servers: "https://api.example.com, /, https://api.example.com", + securitySchemes: `{"apiKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key"}}`, + }) if err != nil { t.Fatalf("unexpected error building sdk spec: %v", err) }