diff --git a/cmd/api/cmd_sdk.go b/cmd/api/cmd_sdk.go index caa6b74..da85d75 100644 --- a/cmd/api/cmd_sdk.go +++ b/cmd/api/cmd_sdk.go @@ -135,37 +135,28 @@ func addSDKCommand(parent *cli.Command) { } 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, securitySchemes string) (*goapi.SpecBuilder, error) { - builder := &goapi.SpecBuilder{ - Title: title, - Description: description, - Version: version, - SwaggerPath: swaggerPath, - GraphQLPath: graphqlPath, - GraphQLPlayground: graphqlPlayground, - SSEPath: ssePath, - WSPath: wsPath, - PprofEnabled: pprofEnabled, - ExpvarEnabled: expvarEnabled, - TermsOfService: termsURL, - ContactName: contactName, - ContactURL: contactURL, - ContactEmail: contactEmail, - Servers: parseServers(servers), - LicenseName: licenseName, - LicenseURL: licenseURL, - ExternalDocsDescription: externalDocsDescription, - ExternalDocsURL: externalDocsURL, - } - - if securitySchemes != "" { - schemes, err := parseSecuritySchemes(securitySchemes) - if err != nil { - return nil, err - } - builder.SecuritySchemes = schemes - } - - return builder, nil + return newSpecBuilder(specBuilderConfig{ + title: title, + 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, + }) } func sdkSpecGroupsIter() iter.Seq[goapi.RouteGroup] { diff --git a/cmd/api/cmd_spec.go b/cmd/api/cmd_spec.go index 5c657c0..617653c 100644 --- a/cmd/api/cmd_spec.go +++ b/cmd/api/cmd_spec.go @@ -41,34 +41,30 @@ func addSpecCommand(parent *cli.Command) { cmd := cli.NewCommand("spec", "Generate OpenAPI specification", "", func(cmd *cli.Command, args []string) error { // Build spec from all route groups registered for CLI generation. - builder := &goapi.SpecBuilder{ - Title: title, - Description: description, - Version: version, - SwaggerPath: swaggerPath, - GraphQLPath: graphqlPath, - GraphQLPlayground: graphqlPlayground, - SSEPath: ssePath, - WSPath: wsPath, - PprofEnabled: pprofEnabled, - ExpvarEnabled: expvarEnabled, - TermsOfService: termsURL, - ContactName: contactName, - ContactURL: contactURL, - ContactEmail: contactEmail, - Servers: parseServers(servers), - LicenseName: licenseName, - LicenseURL: licenseURL, - ExternalDocsDescription: externalDocsDescription, - ExternalDocsURL: externalDocsURL, - } - - if securitySchemes != "" { - schemes, err := parseSecuritySchemes(securitySchemes) - if err != nil { - return err - } - builder.SecuritySchemes = schemes + builder, err := newSpecBuilder(specBuilderConfig{ + title: title, + 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 } bridge := goapi.NewToolBridge("/tools") diff --git a/cmd/api/spec_builder.go b/cmd/api/spec_builder.go new file mode 100644 index 0000000..9e66559 --- /dev/null +++ b/cmd/api/spec_builder.go @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: EUPL-1.2 + +package api + +import goapi "dappco.re/go/core/api" + +type specBuilderConfig struct { + title string + description string + version string + swaggerPath string + graphqlPath string + graphqlPlayground bool + ssePath string + wsPath string + pprofEnabled bool + expvarEnabled bool + termsURL string + contactName string + contactURL string + contactEmail string + licenseName string + licenseURL string + externalDocsDescription string + externalDocsURL string + servers string + securitySchemes string +} + +func newSpecBuilder(cfg specBuilderConfig) (*goapi.SpecBuilder, error) { + builder := &goapi.SpecBuilder{ + Title: cfg.title, + 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, + TermsOfService: cfg.termsURL, + ContactName: cfg.contactName, + ContactURL: cfg.contactURL, + ContactEmail: cfg.contactEmail, + Servers: parseServers(cfg.servers), + LicenseName: cfg.licenseName, + LicenseURL: cfg.licenseURL, + ExternalDocsDescription: cfg.externalDocsDescription, + ExternalDocsURL: cfg.externalDocsURL, + } + + if cfg.securitySchemes != "" { + schemes, err := parseSecuritySchemes(cfg.securitySchemes) + if err != nil { + return nil, err + } + builder.SecuritySchemes = schemes + } + + return builder, nil +}