-
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 wh…
…ile using oneOf in request-validator plugin. (#215) * 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. * fix: lint issue fix * fix: extended validation to anyOf schemas * fix: fixed the case when no oneOf or anyOf schemas are present * fix: lint fix * test: added testcase for >1 definitions in req-validator generation * fix: fixed logical error that did not account for the uncertainty in maps iteration order in golang
- Loading branch information
1 parent
4cc0082
commit a214fdd
Showing
5 changed files
with
247 additions
and
16 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\":[{\"$ref\":\"#/definitions/stringType\"},{\"$ref\":\"#/definitions/numberType\"}],\"type\":\"string\"},\"numberType\":{\"example\":2.5,\"type\":\"number\"},\"stringType\":{\"example\":\"10\",\"type\":\"string\"}}}", | ||
"style": "simple" | ||
}, | ||
{ | ||
"explode": false, | ||
"in": "header", | ||
"name": "secondTestHeader", | ||
"required": true, | ||
"schema": "{\"$ref\":\"#/definitions/secondHeaderType\",\"definitions\":{\"numberType\":{\"example\":2.5,\"type\":\"number\"},\"secondHeaderType\":{\"oneOf\":[{\"$ref\":\"#/definitions/stringType\"},{\"$ref\":\"#/definitions/numberType\"}],\"type\":\"string\"},\"stringType\":{\"example\":\"10\",\"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": [] | ||
} |
58 changes: 58 additions & 0 deletions
58
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,58 @@ | ||
# 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: secondTestHeader | ||
schema: | ||
$ref: '#/components/schemas/secondHeaderType' | ||
required: true | ||
components: | ||
schemas: | ||
headerType: | ||
type: string | ||
oneOf: | ||
- $ref: '#/components/schemas/stringType' | ||
- $ref: '#/components/schemas/numberType' | ||
secondHeaderType: | ||
$ref: '#/components/schemas/headerType' | ||
stringType: | ||
type: string | ||
example: "10" | ||
numberType: | ||
type: number | ||
example: 2.5 | ||
|
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