Repository: ogen-go/ogen
Pull request #466 (2022-07-07 10:18:28)

fix(gen): handle cryptic parameter name

codecov[bot]: # [Codecov](https://codecov.io/gh/ogen-go/ogen/pull/466?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go) Report
> Merging [#466](https://codecov.io/gh/ogen-go/ogen/pull/466?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go) (29eed3c) into [main](https://codecov.io/gh/ogen-go/ogen/commit/8ace62d46bae1091473c11a332d8001ec93422ea?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go) (8ace62d) will **decrease** coverage by `0.46%`.
> The diff coverage is `100.00%`.

```diff
@@            Coverage Diff             @@
##             main     #466      +/-   ##
==========================================
- Coverage   70.88%   70.41%   -0.47%     
==========================================
  Files         144      143       -1     
  Lines       10227    10530     +303     
==========================================
+ Hits         7249     7415     +166     
- Misses       2552     2672     +120     
- Partials      426      443      +17     
```


| [Impacted Files](https://codecov.io/gh/ogen-go/ogen/pull/466?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go) | Coverage Δ | |
|---|---|---|
| [gen/names.go](https://codecov.io/gh/ogen-go/ogen/pull/466/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go#diff-Z2VuL25hbWVzLmdv) | `89.47% <100.00%> (+7.45%)` | :arrow_up: |
| [gen/jsonpointer.go](https://codecov.io/gh/ogen-go/ogen/pull/466/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go#diff-Z2VuL2pzb25wb2ludGVyLmdv) | `53.84% <0.00%> (-46.16%)` | :arrow_down: |
| [spec.go](https://codecov.io/gh/ogen-go/ogen/pull/466/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go#diff-c3BlYy5nbw==) | `68.27% <0.00%> (-18.09%)` | :arrow_down: |
| [schema.go](https://codecov.io/gh/ogen-go/ogen/pull/466/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go#diff-c2NoZW1hLmdv) | `63.06% <0.00%> (-11.07%)` | :arrow_down: |
| [json/location.go](https://codecov.io/gh/ogen-go/ogen/pull/466/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go#diff-anNvbi9sb2NhdGlvbi5nbw==) | `82.14% <0.00%> (-5.19%)` | :arrow_down: |
| [gen/genctx.go](https://codecov.io/gh/ogen-go/ogen/pull/466/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go#diff-Z2VuL2dlbmN0eC5nbw==) | `80.00% <0.00%> (-5.00%)` | :arrow_down: |
| [gen/utils.go](https://codecov.io/gh/ogen-go/ogen/pull/466/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go#diff-Z2VuL3V0aWxzLmdv) | `80.00% <0.00%> (-4.79%)` | :arrow_down: |
| [ogen.go](https://codecov.io/gh/ogen-go/ogen/pull/466/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go#diff-b2dlbi5nbw==) | `45.45% <0.00%> (-4.55%)` | :arrow_down: |
| [jsonschema/raw\_schema.go](https://codecov.io/gh/ogen-go/ogen/pull/466/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go#diff-anNvbnNjaGVtYS9yYXdfc2NoZW1hLmdv) | `80.50% <0.00%> (-2.75%)` | :arrow_down: |
| [openapi/parser/parse\_parameter.go](https://codecov.io/gh/ogen-go/ogen/pull/466/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go#diff-b3BlbmFwaS9wYXJzZXIvcGFyc2VfcGFyYW1ldGVyLmdv) | `91.54% <0.00%> (-1.96%)` | :arrow_down: |
| ... and [28 more](https://codecov.io/gh/ogen-go/ogen/pull/466/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/ogen-go/ogen/pull/466?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/ogen-go/ogen/pull/466?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go). Last update [8ace62d...29eed3c](https://codecov.io/gh/ogen-go/ogen/pull/466?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go).


Patch:
diff --git a/_testdata/positive/empty_property_name.json b/_testdata/positive/property_naming.json
similarity index 100%
rename from _testdata/positive/empty_property_name.json
rename to _testdata/positive/property_naming.json
diff --git a/gen/names.go b/gen/names.go
index a01ad5c4..d56dc74c 100644
--- a/gen/names.go
+++ b/gen/names.go
@@ -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 {
@@ -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
 	}
 


Test patch:
diff --git a/_testdata/positive/parameter_naming.json b/_testdata/positive/parameter_naming.json
new file mode 100644
index 00000000..0ca88f19
--- /dev/null
+++ b/_testdata/positive/parameter_naming.json
@@ -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"
+          }
+        }
+      }
+    }
+  }
+}