Skip to content

Commit

Permalink
bumped coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
daveshanley committed Sep 30, 2024
1 parent 3dc6133 commit b3f00de
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
49 changes: 49 additions & 0 deletions parameters/query_parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2748,3 +2748,52 @@ paths:
assert.Equal(t, "lemons 'pizza' is defined as an object, "+
"however it failed to be decoded as an object", errs[0].Reason)
}

// https://github.com/pb33f/wiretap/issues/83
func TestNewValidator_QueryParamValidateStyle_EmptyDeepObject(t *testing.T) {
spec := `openapi: 3.1.0
info:
title: Test
version: 0.1.0
security:
- apiKeyAuth: []
paths:
/anything/queryParams/deepObject/obj:
get:
operationId: deepObjectQueryParamsObject
parameters:
- name: objParam
in: query
style: deepObject
schema:
type: object
properties:
cake:
type: string
required: true
responses:
"200":
description: OK
components:
securitySchemes:
apiKeyAuth:
type: apiKey
in: header
name: Authorization
description: Authenticate using an API Key generated via our platform.`

doc, _ := libopenapi.NewDocument([]byte(spec))

m, err := doc.BuildV3Model()
assert.Len(t, err, 0) // no patch build here

v := NewParameterValidator(&m.Model)

request, _ := http.NewRequest(http.MethodGet,
"http://localhost:9090/anything/queryParams/deepObject/obj?objParam", nil)

valid, errors := v.ValidateQueryParams(request)
assert.True(t, valid)
assert.Len(t, errors, 0)

}
2 changes: 1 addition & 1 deletion parameters/validate_parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func ValidateParameterSchema(
p := decodedObj
if rawIsMap {
if g, ko := rawObject.(map[string]interface{}); ko {
if len(g) == 0 {
if len(g) == 0 || g[""] != nil {
p = nil
}
}
Expand Down

0 comments on commit b3f00de

Please sign in to comment.