refactor(cmd/api): centralise spec builder config
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
8d92ee29d4
commit
e6f2d1286b
3 changed files with 108 additions and 59 deletions
|
|
@ -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] {
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
62
cmd/api/spec_builder.go
Normal file
62
cmd/api/spec_builder.go
Normal file
|
|
@ -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
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue