-
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.
fix: added fix to validate for top-level type in parameter
schemas while using oneOf in request-validator plugin. As of now, deck file openapi2kong command was not checking for multiple types used while creating parameter schemas with oneOf, which is not supported by Kong request- validator plugin. Thus, we are forcing for defining a top-level type property and erroring out in case it is not present.
- Loading branch information
1 parent
e0a80fc
commit 45ac9b7
Showing
5 changed files
with
212 additions
and
15 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
78 changes: 78 additions & 0 deletions
78
openapi2kong/oas3_testfiles/17-request-validator-plugin-oneOf-usage.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,78 @@ | ||
{ | ||
"_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": "1446ecde-7037-5f9c-8537-8217e2a12bfa", | ||
"methods": [ | ||
"GET" | ||
], | ||
"name": "example_params-test_get", | ||
"paths": [ | ||
"~/params/test$" | ||
], | ||
"plugins": [ | ||
{ | ||
"config": { | ||
"body_schema": "{}", | ||
"parameter_schema": [ | ||
{ | ||
"explode": true, | ||
"in": "query", | ||
"name": "queryid", | ||
"required": true, | ||
"schema": "{\"oneOf\":[{\"example\":10,\"type\":\"integer\"},{\"example\":2.5,\"type\":\"number\"}],\"type\":\"number\"}", | ||
"style": "form" | ||
}, | ||
{ | ||
"explode": false, | ||
"in": "header", | ||
"name": "testHeader", | ||
"required": true, | ||
"schema": "{\"$ref\":\"#/definitions/headerType\",\"definitions\":{\"headerType\":{\"oneOf\":[{\"example\":\"10\",\"type\":\"string\"},{\"example\":2.5,\"type\":\"number\"}],\"type\":\"string\"}}}", | ||
"style": "simple" | ||
}, | ||
{ | ||
"explode": false, | ||
"in": "header", | ||
"name": "testHeader", | ||
"required": true, | ||
"schema": "{\"$ref\":\"#/definitions/secondHeaderType\",\"definitions\":{\"secondHeaderType\":{\"oneOf\":[{\"example\":\"10\",\"type\":\"string\"},{\"example\":2.5,\"type\":\"number\"}],\"type\":\"string\"}}}", | ||
"style": "simple" | ||
} | ||
], | ||
"version": "draft4" | ||
}, | ||
"enabled": true, | ||
"id": "8bd60198-9b34-5f0b-9240-4826c7c331a0", | ||
"name": "request-validator", | ||
"tags": [ | ||
"OAS3_import", | ||
"OAS3file_17-request-validator-plugin-oneOf-usage.yaml" | ||
] | ||
} | ||
], | ||
"regex_priority": 200, | ||
"strip_path": false, | ||
"tags": [ | ||
"OAS3_import", | ||
"OAS3file_17-request-validator-plugin-oneOf-usage.yaml" | ||
] | ||
} | ||
], | ||
"tags": [ | ||
"OAS3_import", | ||
"OAS3file_17-request-validator-plugin-oneOf-usage.yaml" | ||
] | ||
} | ||
], | ||
"upstreams": [] | ||
} |
53 changes: 53 additions & 0 deletions
53
openapi2kong/oas3_testfiles/17-request-validator-plugin-oneOf-usage.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,53 @@ | ||
# When the request-validator is added without a body or parameter schema | ||
# 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: | ||
/params/test: | ||
get: | ||
x-kong-plugin-request-validator: | ||
enabled: true | ||
config: | ||
body_schema: '{}' | ||
parameters: | ||
- in: query | ||
name: queryid | ||
schema: | ||
type: number | ||
oneOf: | ||
- type: integer | ||
example: 10 | ||
- type: number | ||
example: 2.5 | ||
required: true | ||
- in: header | ||
name: testHeader | ||
schema: | ||
$ref: '#/components/schemas/headerType' | ||
required: true | ||
- in: header | ||
name: testHeader | ||
schema: | ||
$ref: '#/components/schemas/secondHeaderType' | ||
required: true | ||
components: | ||
schemas: | ||
headerType: | ||
type: string | ||
oneOf: | ||
- type: string | ||
example: "10" | ||
- type: number | ||
example: 2.5 | ||
secondHeaderType: | ||
$ref: '#/components/schemas/headerType' |
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