Repository: ogen-go/ogen
Pull request #720 (2022-12-13 00:46:22)

fix(parser): check that content parameter style is primitive

codecov[bot]: # [Codecov](https://codecov.io/gh/ogen-go/ogen/pull/720?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go) Report
Base: **74.26**% // Head: **74.27**% // Increases project coverage by **`+0.01%`** :tada:
> Coverage data is based on head [(`c9e4aee`)](https://codecov.io/gh/ogen-go/ogen/pull/720?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go) compared to base [(`b577858`)](https://codecov.io/gh/ogen-go/ogen/commit/b5778585809789899a1ba99ce13cbbc25438f3ab?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go).
> Patch coverage: 85.29% of modified lines in pull request are covered.

> :exclamation: Current head c9e4aee differs from pull request most recent head 53d02ec. Consider uploading reports for the commit 53d02ec to get more accurate results

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main     #720      +/-   ##
==========================================
+ Coverage   74.26%   74.27%   +0.01%     
==========================================
  Files         175      175              
  Lines       12693    12709      +16     
==========================================
+ Hits         9426     9440      +14     
- Misses       2784     2786       +2     
  Partials      483      483              
```


| [Impacted Files](https://codecov.io/gh/ogen-go/ogen/pull/720?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go) | Coverage Δ | |
|---|---|---|
| [gen/gen\_parameters.go](https://codecov.io/gh/ogen-go/ogen/pull/720/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go#diff-Z2VuL2dlbl9wYXJhbWV0ZXJzLmdv) | `57.85% <0.00%> (ø)` | |
| [uri/object.go](https://codecov.io/gh/ogen-go/ogen/pull/720/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go#diff-dXJpL29iamVjdC5nbw==) | `79.59% <76.47%> (-3.75%)` | :arrow_down: |
| [openapi/parser/parse\_header.go](https://codecov.io/gh/ogen-go/ogen/pull/720/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go#diff-b3BlbmFwaS9wYXJzZXIvcGFyc2VfaGVhZGVyLmdv) | `100.00% <100.00%> (ø)` | |
| [openapi/parser/parse\_parameter.go](https://codecov.io/gh/ogen-go/ogen/pull/720/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go#diff-b3BlbmFwaS9wYXJzZXIvcGFyc2VfcGFyYW1ldGVyLmdv) | `94.90% <100.00%> (+0.10%)` | :arrow_up: |
| [uri/header\_param\_encoder.go](https://codecov.io/gh/ogen-go/ogen/pull/720/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go#diff-dXJpL2hlYWRlcl9wYXJhbV9lbmNvZGVyLmdv) | `78.94% <100.00%> (ø)` | |
| [uri/path\_encoder.go](https://codecov.io/gh/ogen-go/ogen/pull/720/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go#diff-dXJpL3BhdGhfZW5jb2Rlci5nbw==) | `87.50% <100.00%> (ø)` | |
| [gen/gen\_contents.go](https://codecov.io/gh/ogen-go/ogen/pull/720/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go#diff-Z2VuL2dlbl9jb250ZW50cy5nbw==) | `75.00% <0.00%> (+0.73%)` | :arrow_up: |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go)

</details>

[:umbrella: View full report at Codecov](https://codecov.io/gh/ogen-go/ogen/pull/720?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go).


Patch:
diff --git a/gen/gen_parameters.go b/gen/gen_parameters.go
index 77869519..8e4d5d62 100644
--- a/gen/gen_parameters.go
+++ b/gen/gen_parameters.go
@@ -181,7 +181,7 @@ func isSupportedParamStyle(param *openapi.Parameter) error {
 		return &ErrNotImplemented{Name: "spaceDelimited parameter style"}
 
 	case openapi.QueryStylePipeDelimited:
-		if param.Schema.Type == jsonschema.Object {
+		if s := param.Schema; s != nil && s.Type == jsonschema.Object {
 			return &ErrNotImplemented{Name: "pipeDelimited style for object parameters"}
 		}
 	}
diff --git a/openapi/parser/parse_header.go b/openapi/parser/parse_header.go
index 1181f732..7dcc85c1 100644
--- a/openapi/parser/parse_header.go
+++ b/openapi/parser/parse_header.go
@@ -83,11 +83,8 @@ func (p *parser) parseHeader(name string, header *ogen.Header, ctx *jsonpointer.
 		Pointer:     locator.Pointer(p.file(ctx)),
 	}
 
-	// TODO: Validate content?
-	if header.Content == nil {
-		if err := p.validateParamStyle(op, p.file(ctx)); err != nil {
-			return nil, err
-		}
+	if err := p.validateParamStyle(op, p.file(ctx)); err != nil {
+		return nil, err
 	}
 
 	return op, nil
diff --git a/openapi/parser/parse_parameter.go b/openapi/parser/parse_parameter.go
index 36c0b1d0..6e952cda 100644
--- a/openapi/parser/parse_parameter.go
+++ b/openapi/parser/parse_parameter.go
@@ -172,11 +172,8 @@ func (p *parser) parseParameter(param *ogen.Parameter, ctx *jsonpointer.ResolveC
 		Pointer:       locator.Pointer(p.file(ctx)),
 	}
 
-	// TODO: Validate content?
-	if param.Content == nil {
-		if err := p.validateParamStyle(op, p.file(ctx)); err != nil {
-			return nil, err
-		}
+	if err := p.validateParamStyle(op, p.file(ctx)); err != nil {
+		return nil, err
 	}
 
 	return op, nil
@@ -322,8 +319,16 @@ func (p *parser) validateParamStyle(param *openapi.Parameter, file location.File
 		return nil
 	}
 
-	if err := check(param.Schema); err != nil {
-		return wrap("schema", err)
+	switch {
+	case param.Schema != nil:
+		if err := check(param.Schema); err != nil {
+			return wrap("schema", err)
+		}
+	case param.Content != nil:
+		if !allowed(primitive) {
+			err := errors.New("content parameter should be primitive")
+			return wrap("style", err)
+		}
 	}
 
 	return nil


Test patch:
diff --git a/openapi/parser/_testdata/negative/parameters/query/combination_content.json b/openapi/parser/_testdata/negative/parameters/query/combination_content.json
new file mode 100644
index 00000000..de6d5f23
--- /dev/null
+++ b/openapi/parser/_testdata/negative/parameters/query/combination_content.json
@@ -0,0 +1,35 @@
+{
+  "openapi": "3.0.3",
+  "info": {
+    "title": "title",
+    "version": "v0.1.0"
+  },
+  "paths": {
+    "/foo": {
+      "get": {
+        "parameters": [
+          {
+            "name": "foo",
+            "in": "query",
+            "style": "pipeDelimited",
+            "content": {
+              "application/json": {
+                "schema": {
+                  "type": "array",
+                  "items": {
+                    "type": "string"
+                  }
+                }
+              }
+            }
+          }
+        ],
+        "responses": {
+          "200": {
+            "description": "User info"
+          }
+        }
+      }
+    }
+  }
+}