Skip to content

Commit

Permalink
Merge pull request #720 from tdakkota/fix/non-primitive-content
Browse files Browse the repository at this point in the history
fix(parser): check that content parameter style is primitive
  • Loading branch information
ernado authored Dec 13, 2022
2 parents 1cf9f39 + 6cb2212 commit 4c85100
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 13 deletions.
2 changes: 1 addition & 1 deletion gen/gen_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
}
}
7 changes: 2 additions & 5 deletions openapi/parser/parse_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions openapi/parser/parse_parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4c85100

Please sign in to comment.