diff --git a/openapi2kong/oas3_testfiles/26-request-validator-plugin-operation-parameter-schema.expected.json b/openapi2kong/oas3_testfiles/26-request-validator-plugin-operation-parameter-schema.expected.json new file mode 100644 index 0000000..5ba7f50 --- /dev/null +++ b/openapi2kong/oas3_testfiles/26-request-validator-plugin-operation-parameter-schema.expected.json @@ -0,0 +1,78 @@ +{ + "_format_version": "3.0", + "services": [ + { + "host": "localhost", + "id": "b69ec2b7-0b2b-5e52-8e37-7126b9237f56", + "name": "test-service", + "path": "/", + "plugins": [], + "port": 443, + "protocol": "https", + "routes": [ + { + "id": "04fe9734-c93d-59bc-8723-528a778996c3", + "methods": [ + "GET" + ], + "name": "test-service_sample-group-sample-service-sample-api-v1-get-result_get", + "paths": [ + "~/sample-group/sample-service/sample-api/v1/get-result$" + ], + "plugins": [ + { + "config": { + "parameter_schema": [ + { + "explode": false, + "in": "header", + "name": "env", + "required": true, + "schema": "{\"type\":\"string\"}", + "style": "simple" + } + ], + "version": "draft4" + }, + "enabled": true, + "id": "8384b338-2d12-5035-902c-a20fd9ddd6fb", + "name": "request-validator", + "tags": [ + "OAS3_import", + "OAS3file_26-request-validator-plugin-operation-parameter-schema.yaml" + ] + } + ], + "regex_priority": 200, + "strip_path": false, + "tags": [ + "OAS3_import", + "OAS3file_26-request-validator-plugin-operation-parameter-schema.yaml" + ] + }, + { + "id": "a9452a70-c0fe-5a3b-8446-c329ba5c55e2", + "methods": [ + "OPTIONS" + ], + "name": "test-service_sample-group-sample-service-sample-api-v1-get-result_options", + "paths": [ + "~/sample-group/sample-service/sample-api/v1/get-result$" + ], + "plugins": [], + "regex_priority": 200, + "strip_path": false, + "tags": [ + "OAS3_import", + "OAS3file_26-request-validator-plugin-operation-parameter-schema.yaml" + ] + } + ], + "tags": [ + "OAS3_import", + "OAS3file_26-request-validator-plugin-operation-parameter-schema.yaml" + ] + } + ], + "upstreams": [] +} diff --git a/openapi2kong/oas3_testfiles/26-request-validator-plugin-operation-parameter-schema.yaml b/openapi2kong/oas3_testfiles/26-request-validator-plugin-operation-parameter-schema.yaml new file mode 100644 index 0000000..dfbed2e --- /dev/null +++ b/openapi2kong/oas3_testfiles/26-request-validator-plugin-operation-parameter-schema.yaml @@ -0,0 +1,30 @@ +openapi: 3.0.0 + +info: + description: Test service + version: 1.0.0 + title: Test Service + +x-kong-plugin-request-validator: + enabled: true + +paths: + /sample-group/sample-service/sample-api/v1/get-result: + get: + parameters: + - in: header + name: env + required: true + schema: + type: string + enum: + - qa + summary: Get Results + description: Get Results. + responses: + "200": + description: The request has succeeded. + options: + responses: + "200": + description: Generic OPTIONS response diff --git a/openapi2kong/oas3_testfiles/26-request-validator-plugin-path-operation-parameter-schema.expected.json b/openapi2kong/oas3_testfiles/26-request-validator-plugin-path-operation-parameter-schema.expected.json new file mode 100644 index 0000000..36a5b95 --- /dev/null +++ b/openapi2kong/oas3_testfiles/26-request-validator-plugin-path-operation-parameter-schema.expected.json @@ -0,0 +1,111 @@ +{ + "_format_version": "3.0", + "services": [ + { + "host": "localhost", + "id": "b69ec2b7-0b2b-5e52-8e37-7126b9237f56", + "name": "test-service", + "path": "/", + "plugins": [], + "port": 443, + "protocol": "https", + "routes": [ + { + "headers": { + "env": [ + "qa" + ] + }, + "id": "4c11d945-2325-5817-9249-2a1973c229af", + "methods": [ + "GET" + ], + "name": "test-service_sample-group-sample-service-sample-api-v1-get-result_get_0", + "paths": [ + "~/sample-group/sample-service/sample-api/v1/get-result$" + ], + "plugins": [ + { + "config": { + "parameter_schema": [ + { + "explode": false, + "in": "header", + "name": "env", + "required": true, + "schema": "{\"enum\":[\"qa\"],\"type\":\"string\"}", + "style": "simple" + } + ], + "version": "draft4" + }, + "enabled": true, + "id": "8384b338-2d12-5035-902c-a20fd9ddd6fb", + "name": "request-validator", + "tags": [ + "OAS3_import", + "OAS3file_26-request-validator-plugin-path-operation-parameter-schema.yaml" + ] + } + ], + "regex_priority": 200, + "strip_path": false, + "tags": [ + "OAS3_import", + "OAS3file_26-request-validator-plugin-path-operation-parameter-schema.yaml" + ] + }, + { + "headers": { + "env": [ + "dev" + ] + }, + "id": "13fe35c4-9665-5433-8d0b-a840713d32db", + "methods": [ + "OPTIONS" + ], + "name": "test-service_sample-group-sample-service-sample-api-v1-get-result_options_0", + "paths": [ + "~/sample-group/sample-service/sample-api/v1/get-result$" + ], + "plugins": [ + { + "config": { + "parameter_schema": [ + { + "explode": false, + "in": "header", + "name": "env", + "required": true, + "schema": "{\"enum\":[\"dev\"],\"type\":\"string\"}", + "style": "simple" + } + ], + "version": "draft4" + }, + "enabled": true, + "id": "eb7440df-3f27-5647-bab9-fec82845e2b9", + "name": "request-validator", + "tags": [ + "OAS3_import", + "OAS3file_26-request-validator-plugin-path-operation-parameter-schema.yaml" + ] + } + ], + "regex_priority": 200, + "strip_path": false, + "tags": [ + "OAS3_import", + "OAS3file_26-request-validator-plugin-path-operation-parameter-schema.yaml" + ] + } + ], + "tags": [ + "OAS3_import", + "OAS3file_26-request-validator-plugin-path-operation-parameter-schema.yaml" + ] + } + ], + "upstreams": [] +} diff --git a/openapi2kong/oas3_testfiles/26-request-validator-plugin-path-operation-parameter-schema.yaml b/openapi2kong/oas3_testfiles/26-request-validator-plugin-path-operation-parameter-schema.yaml new file mode 100644 index 0000000..eef3fce --- /dev/null +++ b/openapi2kong/oas3_testfiles/26-request-validator-plugin-path-operation-parameter-schema.yaml @@ -0,0 +1,38 @@ +openapi: 3.0.0 + +info: + description: Test service + version: 1.0.0 + title: Test Service + +x-kong-plugin-request-validator: + enabled: true + +paths: + /sample-group/sample-service/sample-api/v1/get-result: + parameters: + - in: header + name: env + required: true + schema: + type: string + enum: + - dev + get: + parameters: + - in: header + name: env + required: true + schema: + type: string + enum: + - qa + summary: Get Results + description: Get Results. + responses: + "200": + description: The request has succeeded. + options: + responses: + "200": + description: Generic OPTIONS response diff --git a/openapi2kong/oas3_testfiles/26-request-validator-plugin-path-parameter-schema.expected.json b/openapi2kong/oas3_testfiles/26-request-validator-plugin-path-parameter-schema.expected.json new file mode 100644 index 0000000..d0a0452 --- /dev/null +++ b/openapi2kong/oas3_testfiles/26-request-validator-plugin-path-parameter-schema.expected.json @@ -0,0 +1,111 @@ +{ + "_format_version": "3.0", + "services": [ + { + "host": "localhost", + "id": "b69ec2b7-0b2b-5e52-8e37-7126b9237f56", + "name": "test-service", + "path": "/", + "plugins": [], + "port": 443, + "protocol": "https", + "routes": [ + { + "headers": { + "env": [ + "qa" + ] + }, + "id": "8377d503-1bba-522a-a206-f91323442674", + "methods": [ + "GET" + ], + "name": "test-service_sample-group-sample-service-sample-api-v2-get-result_get_0", + "paths": [ + "~/sample-group/sample-service/sample-api/v2/get-result$" + ], + "plugins": [ + { + "config": { + "parameter_schema": [ + { + "explode": false, + "in": "header", + "name": "env", + "required": true, + "schema": "{\"enum\":[\"qa\"],\"type\":\"string\"}", + "style": "simple" + } + ], + "version": "draft4" + }, + "enabled": true, + "id": "ddb9f3cc-b11a-58f2-87e0-e47d8eca0242", + "name": "request-validator", + "tags": [ + "OAS3_import", + "OAS3file_26-request-validator-plugin-path-parameter-schema.yaml" + ] + } + ], + "regex_priority": 200, + "strip_path": false, + "tags": [ + "OAS3_import", + "OAS3file_26-request-validator-plugin-path-parameter-schema.yaml" + ] + }, + { + "headers": { + "env": [ + "qa" + ] + }, + "id": "c7f298fd-0673-5232-838c-d51a17edb71e", + "methods": [ + "OPTIONS" + ], + "name": "test-service_sample-group-sample-service-sample-api-v2-get-result_options_0", + "paths": [ + "~/sample-group/sample-service/sample-api/v2/get-result$" + ], + "plugins": [ + { + "config": { + "parameter_schema": [ + { + "explode": false, + "in": "header", + "name": "env", + "required": true, + "schema": "{\"enum\":[\"qa\"],\"type\":\"string\"}", + "style": "simple" + } + ], + "version": "draft4" + }, + "enabled": true, + "id": "1da08580-9237-584f-8213-9d64c1a87782", + "name": "request-validator", + "tags": [ + "OAS3_import", + "OAS3file_26-request-validator-plugin-path-parameter-schema.yaml" + ] + } + ], + "regex_priority": 200, + "strip_path": false, + "tags": [ + "OAS3_import", + "OAS3file_26-request-validator-plugin-path-parameter-schema.yaml" + ] + } + ], + "tags": [ + "OAS3_import", + "OAS3file_26-request-validator-plugin-path-parameter-schema.yaml" + ] + } + ], + "upstreams": [] +} diff --git a/openapi2kong/oas3_testfiles/26-request-validator-plugin-path-parameter-schema.yaml b/openapi2kong/oas3_testfiles/26-request-validator-plugin-path-parameter-schema.yaml new file mode 100644 index 0000000..25583b3 --- /dev/null +++ b/openapi2kong/oas3_testfiles/26-request-validator-plugin-path-parameter-schema.yaml @@ -0,0 +1,30 @@ +openapi: 3.0.0 + +info: + description: Test service + version: 1.0.0 + title: Test Service + +x-kong-plugin-request-validator: + enabled: true + +paths: + /sample-group/sample-service/sample-api/v2/get-result: + parameters: + - in: header + name: env + required: true + schema: + type: string + enum: + - qa + get: + summary: Get Results + description: Get Results. + responses: + "200": + description: The request has succeeded. + options: + responses: + "200": + description: Generic OPTIONS response diff --git a/openapi2kong/validator.go b/openapi2kong/validator.go index de60d4f..d363ec3 100644 --- a/openapi2kong/validator.go +++ b/openapi2kong/validator.go @@ -61,7 +61,11 @@ func generateParameterSchema(operation *v3.Operation, path *v3.PathItem, } } - combinedParameters = append(combinedParameters, operationParameters...) + if operationParameters != nil { + combinedParameters = append(combinedParameters, operationParameters...) + } else { + combinedParameters = append(combinedParameters, pathParameters...) + } result := make([]map[string]interface{}, len(combinedParameters)) i := 0