From 5eef75ab7c461c29a188522891520255ff0522a6 Mon Sep 17 00:00:00 2001 From: tdakkota Date: Tue, 13 Dec 2022 03:45:18 +0300 Subject: [PATCH 1/2] fix(parser): check that content parameter style is primitive --- .../parameters/query/combination_content.json | 35 +++++++++++++++++++ openapi/parser/parse_header.go | 7 ++-- openapi/parser/parse_parameter.go | 19 ++++++---- 3 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 openapi/parser/_testdata/negative/parameters/query/combination_content.json 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 000000000..de6d5f23f --- /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" + } + } + } + } + } +} diff --git a/openapi/parser/parse_header.go b/openapi/parser/parse_header.go index 1181f7329..7dcc85c1e 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 36c0b1d0e..6e952cdad 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 From 6cb221272b02b248c38cad66aaad3cfbade8547a Mon Sep 17 00:00:00 2001 From: tdakkota Date: Tue, 13 Dec 2022 03:45:59 +0300 Subject: [PATCH 2/2] fix(gen): check parameter `Schema` for `nil` --- gen/gen_parameters.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gen/gen_parameters.go b/gen/gen_parameters.go index 77869519c..8e4d5d62f 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"} } }