Skip to content

Incorrectly generated empty array for security requirements  #946

Description

@yuriamw

Thank you very much for this tool!

Here is a small easy to fix issue

v1.12.4 and master

security:
  - JWT: []

result into code

c.Set(JWTScopes, []string{""})

instead of

c.Set(JWTScopes, []string{})

The fix is trivial

diff --git a/pkg/codegen/template_helpers.go b/pkg/codegen/template_helpers.go
index 7585a26..16671fb 100644
--- a/pkg/codegen/template_helpers.go
+++ b/pkg/codegen/template_helpers.go
@@ -263,7 +263,11 @@ func getConditionOfResponseName(statusCodeVar, responseName string) string {
 
 // This outputs a string array
 func toStringArray(sarr []string) string {
-	return `[]string{"` + strings.Join(sarr, `","`) + `"}`
+	s := strings.Join(sarr, `","`)
+	if len(s) > 0 {
+		s = `"` + s + `"`
+	}
+	return `[]string{` + s + `}`
 }
 
 func stripNewLines(s string) string {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions