Repository: go-swagger/go-swagger (go)

Issue:
0.26.0 - Enum constants are not unique for some special characters
## Problem statement

Same issue as in #2050; however the fix in #2051 did not cover the characters `=` `*`, and `/`, and I am seeing the same issue where there are multiple generated constants using the same name. I am using go-swagger v0.26.0.

Example generated client code:

```golang
const (

	// ModificationSourceOperation captures enum value "="
	ModificationSourceOperation string = "="

	// ModificationSourceOperationPlus captures enum value "+"
	ModificationSourceOperationPlus string = "+"

	// ModificationSourceOperationDash captures enum value "-"
	ModificationSourceOperationDash string = "-"

	// ModificationSourceOperation captures enum value "*"
	ModificationSourceOperation string = "*"

	// ModificationSourceOperation captures enum value "/"
	ModificationSourceOperation string = "/"
)
```

swagger.json for reproducing the bug:

```json
{
  "definitions": {
    "ModificationSource": {
      "type": "object",
      "properties": {
        "operation": {
          "type": "string",
          "enum": ["=", "+", "-", "*", "/"]
        }
      }
    }
  }
}
```

Pull request description:
Generator: Handle special characters *, /, and =
Fixes #2501

I re-ran `swagger generate client` using this version and verified that it fixed the issue. The generator now correctly outputs:

```golang
const (

	// ModificationSourceOperationEqualSign captures enum value "="
	ModificationSourceOperationEqualSign string = "="

	// ModificationSourceOperationPlus captures enum value "+"
	ModificationSourceOperationPlus string = "+"

	// ModificationSourceOperationDash captures enum value "-"
	ModificationSourceOperationDash string = "-"

	// ModificationSourceOperationAsterisk captures enum value "*"
	ModificationSourceOperationAsterisk string = "*"

	// ModificationSourceOperationForwardSlash captures enum value "/"
	ModificationSourceOperationForwardSlash string = "/"
)
```

Patch:
diff --git a/cmd/swagger/commands/generate/spec.go b/cmd/swagger/commands/generate/spec.go
index ccb9b57e..abe60a1a 100644
--- a/cmd/swagger/commands/generate/spec.go
+++ b/cmd/swagger/commands/generate/spec.go
@@ -37,7 +37,7 @@ type SpecFile struct {
 	ScanModels  bool           `long:"scan-models" short:"m" description:"includes models that were annotated with 'swagger:model'"`
 	Compact     bool           `long:"compact" description:"when present, doesn't prettify the json"`
 	Output      flags.Filename `long:"output" short:"o" description:"the file to write to"`
-	Input       flags.Filename `long:"input" short:"i" description:"the file to use as input"`
+	Input       flags.Filename `long:"input" short:"i" description:"an input swagger file with which to merge"`
 	Include     []string       `long:"include" short:"c" description:"include packages matching pattern"`
 	Exclude     []string       `long:"exclude" short:"x" description:"exclude packages matching pattern"`
 	IncludeTags []string       `long:"include-tag" short:"" description:"include routes having specified tags (can be specified many times)"`
diff --git a/cmd/swagger/commands/generate/spec_go111.go b/cmd/swagger/commands/generate/spec_go111.go
index 72162ba2..ab6c90b2 100644
--- a/cmd/swagger/commands/generate/spec_go111.go
+++ b/cmd/swagger/commands/generate/spec_go111.go
@@ -24,7 +24,7 @@ type SpecFile struct {
 	ScanModels  bool           `long:"scan-models" short:"m" description:"includes models that were annotated with 'swagger:model'"`
 	Compact     bool           `long:"compact" description:"when present, doesn't prettify the json"`
 	Output      flags.Filename `long:"output" short:"o" description:"the file to write to"`
-	Input       flags.Filename `long:"input" short:"i" description:"the file to use as input"`
+	Input       flags.Filename `long:"input" short:"i" description:"an input swagger file with which to merge"`
 	Include     []string       `long:"include" short:"c" description:"include packages matching pattern"`
 	Exclude     []string       `long:"exclude" short:"x" description:"exclude packages matching pattern"`
 	IncludeTags []string       `long:"include-tag" short:"" description:"include routes having specified tags (can be specified many times)"`
diff --git a/cmd/swagger/completion/swagger.zsh-completion b/cmd/swagger/completion/swagger.zsh-completion
index 2bbe5a38..2c9530ea 100644
--- a/cmd/swagger/completion/swagger.zsh-completion
+++ b/cmd/swagger/completion/swagger.zsh-completion
@@ -115,7 +115,7 @@ __generate_spec() {
     '(-m,--scan-models)'{-m,--scan-models}"[includes models that were annotated with 'swagger:model']" \
     "(--compact)--compact[when present, doesn't prettify the the json]" \
     '(-o,--output)'{-o,--output}"[the file to write to]:output" \
-    '(-i,--input)'{-i,--input}"[the file to use as input]:input" && return 0
+    '(-i,--input)'{-i,--input}"[an input swagger file with which to merge]:input" && return 0
 }
 
 __generate_support() {
diff --git a/docs/generate/spec.md b/docs/generate/spec.md
index e09e6a13..cbb619fc 100644
--- a/docs/generate/spec.md
+++ b/docs/generate/spec.md
@@ -19,7 +19,7 @@ Help Options:
       -m, --scan-models        includes models that were annotated with 'swagger:model'
           --compact            when present, doesn't prettify the json
       -o, --output=            the file to write to
-      -i, --input=             the file to use as input
+      -i, --input=             an input swagger file with which to merge
       -c, --include=           include packages matching pattern
       -x, --exclude=           exclude packages matching pattern
           --include-tag=       include routes having specified tags (can be specified many times)
diff --git a/generator/template_repo.go b/generator/template_repo.go
index 9ea18470..50f08099 100644
--- a/generator/template_repo.go
+++ b/generator/template_repo.go
@@ -635,7 +635,7 @@ func pascalize(arg string) string {
 		return "Empty"
 	case 1: // handle special case when we have a single rune that is not handled by swag.ToGoName
 		switch runes[0] {
-		case '+', '-', '#', '_': // those cases are handled differently than swag utility
+		case '+', '-', '#', '_', '*', '/', '=': // those cases are handled differently than swag utility
 			return prefixForName(arg)
 		}
 	}
@@ -654,6 +654,12 @@ func prefixForName(arg string) string {
 		return "Minus"
 	case '#':
 		return "HashTag"
+	case '*':
+		return "Asterisk"
+	case '/':
+		return "ForwardSlash"
+	case '=':
+		return "EqualSign"
 		// other cases ($,@ etc..) handled by swag.ToGoName
 	}
 	return "Nr"


Test patch:
diff --git a/generator/template_repo_test.go b/generator/template_repo_test.go
index 923157cf..42f88402 100644
--- a/generator/template_repo_test.go
+++ b/generator/template_repo_test.go
@@ -555,6 +555,9 @@ func TestFuncMap_Pascalize(t *testing.T) {
 	assert.Equal(t, "Minus1", pascalize("-1"))
 	assert.Equal(t, "Minus", pascalize("-"))
 	assert.Equal(t, "Nr8", pascalize("8"))
+	assert.Equal(t, "Asterisk", pascalize("*"))
+	assert.Equal(t, "ForwardSlash", pascalize("/"))
+	assert.Equal(t, "EqualSign", pascalize("="))
 
 	assert.Equal(t, "Hello", pascalize("+hello"))