-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added support for path-params outside methods for request-valid…
…ation (#216) * feat: added support for path-params outside methods for request-validation. This change allows the deck file openapi2kong command to create request validation configuration for path parameters directly under a route, not nested under an operation/method. Till now, we supported path parameters nested under a method. Fixes: #207 * fix: if path and operation params have same name and location, prioritise operation param * addressed PR comment * fix: fixed escaping of curly braces using fix script
- Loading branch information
1 parent
475b3aa
commit b9e8b45
Showing
8 changed files
with
235 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,4 +113,4 @@ | |
} | ||
], | ||
"upstreams": [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -233,4 +233,4 @@ | |
} | ||
], | ||
"upstreams": [] | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...api2kong/oas3_testfiles/18-request-validator-plugin-path-params-outside-ops.expected.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{ | ||
"_format_version": "3.0", | ||
"services": [ | ||
{ | ||
"host": "backend.com", | ||
"id": "730d612d-914b-5fe8-8ead-e6aa654318ef", | ||
"name": "example", | ||
"path": "/path", | ||
"plugins": [], | ||
"port": 80, | ||
"protocol": "http", | ||
"routes": [ | ||
{ | ||
"id": "bee0be08-646a-562a-91b9-71737169585b", | ||
"methods": [ | ||
"GET" | ||
], | ||
"name": "example_test-common-param-common-param_get", | ||
"paths": [ | ||
"~/test/common-param/(?<common_param>[^#?/]+)$" | ||
], | ||
"plugins": [ | ||
{ | ||
"config": { | ||
"parameter_schema": [ | ||
{ | ||
"explode": false, | ||
"in": "path", | ||
"name": "common_param", | ||
"required": true, | ||
"schema": "{\"type\":\"integer\"}", | ||
"style": "simple" | ||
}, | ||
{ | ||
"explode": true, | ||
"in": "query", | ||
"name": "metadata", | ||
"required": false, | ||
"schema": "{\"type\":\"boolean\"}", | ||
"style": "form" | ||
} | ||
], | ||
"verbose_response": true, | ||
"version": "draft4" | ||
}, | ||
"enabled": true, | ||
"id": "3bcb9a87-847d-5ccf-93dc-b2aa1b32b77d", | ||
"name": "request-validator", | ||
"tags": [ | ||
"OAS3_import", | ||
"OAS3file_18-request-validator-plugin-path-params-outside-ops.yaml" | ||
] | ||
} | ||
], | ||
"regex_priority": 100, | ||
"strip_path": false, | ||
"tags": [ | ||
"OAS3_import", | ||
"OAS3file_18-request-validator-plugin-path-params-outside-ops.yaml" | ||
] | ||
} | ||
], | ||
"tags": [ | ||
"OAS3_import", | ||
"OAS3file_18-request-validator-plugin-path-params-outside-ops.yaml" | ||
] | ||
} | ||
], | ||
"upstreams": [] | ||
} |
36 changes: 36 additions & 0 deletions
36
openapi2kong/oas3_testfiles/18-request-validator-plugin-path-params-outside-ops.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# When the request-validator is added with path and operation parameters, | ||
# the generator should automatically generate it. | ||
|
||
openapi: 3.0.2 | ||
|
||
info: | ||
title: Example | ||
version: 1.0.0 | ||
|
||
servers: | ||
- url: http://backend.com/path | ||
|
||
x-kong-plugin-request-validator: {} | ||
|
||
paths: | ||
/test/common-param/{common-param}: | ||
parameters: | ||
- in: path | ||
name: common-param | ||
schema: | ||
type: integer | ||
required: true | ||
get: | ||
parameters: | ||
- in: query | ||
name: metadata | ||
schema: | ||
type: boolean | ||
required: false | ||
responses: | ||
'200': | ||
description: OK | ||
x-kong-plugin-request-validator: | ||
enabled: true | ||
config: | ||
verbose_response: true |
62 changes: 62 additions & 0 deletions
62
...g/oas3_testfiles/19-request-validator-plugin-op-params-override-path-params.expected.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"_format_version": "3.0", | ||
"services": [ | ||
{ | ||
"host": "backend.com", | ||
"id": "730d612d-914b-5fe8-8ead-e6aa654318ef", | ||
"name": "example", | ||
"path": "/path", | ||
"plugins": [], | ||
"port": 80, | ||
"protocol": "http", | ||
"routes": [ | ||
{ | ||
"id": "bee0be08-646a-562a-91b9-71737169585b", | ||
"methods": [ | ||
"GET" | ||
], | ||
"name": "example_test-common-param-common-param_get", | ||
"paths": [ | ||
"~/test/common-param/(?<common_param>[^#?/]+)$" | ||
], | ||
"plugins": [ | ||
{ | ||
"config": { | ||
"parameter_schema": [ | ||
{ | ||
"explode": false, | ||
"in": "path", | ||
"name": "common_param", | ||
"required": true, | ||
"schema": "{\"type\":\"integer\"}", | ||
"style": "simple" | ||
} | ||
], | ||
"verbose_response": true, | ||
"version": "draft4" | ||
}, | ||
"enabled": true, | ||
"id": "3bcb9a87-847d-5ccf-93dc-b2aa1b32b77d", | ||
"name": "request-validator", | ||
"tags": [ | ||
"OAS3_import", | ||
"OAS3file_19-request-validator-plugin-op-params-override-path-params.yaml" | ||
] | ||
} | ||
], | ||
"regex_priority": 100, | ||
"strip_path": false, | ||
"tags": [ | ||
"OAS3_import", | ||
"OAS3file_19-request-validator-plugin-op-params-override-path-params.yaml" | ||
] | ||
} | ||
], | ||
"tags": [ | ||
"OAS3_import", | ||
"OAS3file_19-request-validator-plugin-op-params-override-path-params.yaml" | ||
] | ||
} | ||
], | ||
"upstreams": [] | ||
} |
36 changes: 36 additions & 0 deletions
36
openapi2kong/oas3_testfiles/19-request-validator-plugin-op-params-override-path-params.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# When the request-validator is added with path and operation parameters, | ||
# with both sharing same name and location, operation parameters override the path parameters. | ||
|
||
openapi: 3.0.2 | ||
|
||
info: | ||
title: Example | ||
version: 1.0.0 | ||
|
||
servers: | ||
- url: http://backend.com/path | ||
|
||
x-kong-plugin-request-validator: {} | ||
|
||
paths: | ||
/test/common-param/{common-param}: | ||
parameters: | ||
- in: path | ||
name: common-param | ||
schema: | ||
type: string | ||
required: true | ||
get: | ||
parameters: | ||
- in: path | ||
name: common-param | ||
schema: | ||
type: integer | ||
required: true | ||
responses: | ||
'200': | ||
description: OK | ||
x-kong-plugin-request-validator: | ||
enabled: true | ||
config: | ||
verbose_response: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters