refactor(cmd/api): centralize spec builder config
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
4fc93612e4
commit
c383d85923
2 changed files with 66 additions and 46 deletions
|
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue