Skip to content

Commit

Permalink
fix: moved to warning log, rather than error for cookie params
Browse files Browse the repository at this point in the history
  • Loading branch information
Prashansa-K committed Nov 13, 2024
1 parent 854f110 commit cf85ec6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
8 changes: 8 additions & 0 deletions openapi2kong/oas3_testfiles/13-request-validator-plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ paths:
schema:
type: integer
required: true
# This would not be added to the req-validator plugin config
# as cookie type is not supported yet.
# A warning would be logged and this parameter would be ignored.
- in: cookie
name: User-Id
schema:
type: integer
required: true
- in: path
name: path_id
schema:
Expand Down
19 changes: 13 additions & 6 deletions openapi2kong/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,19 @@ func generateParameterSchema(operation *v3.Operation, path *v3.PathItem,

result := make([]map[string]interface{}, len(combinedParameters))
i := 0
invalidParamCounts := 0

for _, parameter := range combinedParameters {
if parameter != nil {
if parameter.In == "cookie" {
logbasics.Info(`cookie parameters are not supported for request-validator plugin;
choose either path, query or header`)

invalidParamCounts++

continue
}

style := getDefaultParamStyle(parameter.Style, parameter.In)

var explode bool
Expand All @@ -82,11 +92,6 @@ func generateParameterSchema(operation *v3.Operation, path *v3.PathItem,
paramConf["explode"] = explode
paramConf["in"] = parameter.In

if parameter.In == "cookie" {
return nil, fmt.Errorf(`cookie parameters are not supported for request-validator plugin;
choose either path, query or header`)
}

if parameter.In == "path" {
paramConf["name"] = sanitizeRegexCapture(parameter.Name, insoCompat)
} else {
Expand Down Expand Up @@ -115,7 +120,9 @@ func generateParameterSchema(operation *v3.Operation, path *v3.PathItem,
}
}

return result, nil
// This ensures that we don't return nulls in the map, in case of invalid parameters
// indexing makes sure that order is maintained and nulls are in the end
return result[:len(result)-invalidParamCounts], nil
}

func parseMediaType(mediaType string) (string, string, error) {
Expand Down

0 comments on commit cf85ec6

Please sign in to comment.