Skip to content

Commit

Permalink
Merge pull request #466 from tdakkota/fix/parameter-naming
Browse files Browse the repository at this point in the history
fix(gen): handle cryptic parameter name
  • Loading branch information
ernado authored Jul 7, 2022
2 parents 6a6d8e0 + 0e32c54 commit 3b4e430
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 11 deletions.
60 changes: 60 additions & 0 deletions _testdata/positive/parameter_naming.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"openapi": "3.0.3",
"info": {
"title": "title",
"version": "v0.1.0"
},
"paths": {
"/healthz": {
"get": {
"parameters": [
{
"name": "=",
"in": "query",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "+",
"in": "query",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "question?",
"in": "query",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "and&",
"in": "query",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "percent%",
"in": "query",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "User info"
}
}
}
}
}
}
File renamed without changes.
15 changes: 4 additions & 11 deletions gen/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,9 @@ func (g *nameGen) clean() string {
}

func (g *nameGen) isAllowed(r rune) bool {
const alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"
for _, c := range alphabet {
if c == unicode.ToLower(r) {
return true
}
}
return false
r = unicode.ToLower(r)
return (r >= 'a' && r <= 'z') ||
(r >= '0' && r <= '9')
}

func (g *nameGen) checkPart(part string) string {
Expand Down Expand Up @@ -167,10 +163,7 @@ func pascalSpecial(strs ...string) (string, error) {

func pascalNonEmpty(strs ...string) (string, error) {
r, err := pascal(strs...)
if err != nil {
return "", err
}
if r != "" {
if err == nil && r != "" {
return r, nil
}

Expand Down

0 comments on commit 3b4e430

Please sign in to comment.