diff --git a/openapi2kong/oas3_testfiles/13-request-validator-plugin.yaml b/openapi2kong/oas3_testfiles/13-request-validator-plugin.yaml index 47c5667..2d5c287 100644 --- a/openapi2kong/oas3_testfiles/13-request-validator-plugin.yaml +++ b/openapi2kong/oas3_testfiles/13-request-validator-plugin.yaml @@ -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: diff --git a/openapi2kong/validator.go b/openapi2kong/validator.go index 4f2f3f8..378764e 100644 --- a/openapi2kong/validator.go +++ b/openapi2kong/validator.go @@ -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 @@ -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 { @@ -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) {