Inaccurate reporting of duplicate parameter values when parsing schema
When parsing a schema that uses $ref
for parameters we are seeing an inaccurate parse failure reporting duplicate parameters.
minimal sample :
{
"openapi": "3.0.0",
"info": {
"title": "Test",
"version": "1.0"
},
"paths": {
"/foo": {
"post": {
"operationId": "foo",
"parameters": [
{
"in": "header",
"name": "x-something",
"schema": {
"type": "string"
},
"required": true
},
{
"in": "header",
"name": "x-something-else",
"schema": {
"type": "string"
},
"required": false
}
],
"responses": {
"201": {
"description": "Success–resource created."
}
}
}
},
"/foo/bar": {
"post": {
"operationId": "foo2",
"parameters": [
{
"$ref": "#/paths/~1foo/post/parameters/0"
},
{
"$ref": "#/paths/~1foo/post/parameters/1"
}
],
"responses": {
"201": {
"description": "Success–resources created."
}
}
}
}
}
}
Note that the parameters in the second path use $ref
to point to two different array indexes in the first path (lines 36 and 38). When attempting to parse this schema an error is returned :
Caused by: com.atlassian.oai.validator.OpenApiInteractionValidator$ApiLoadException: Unable to load API spec from provided URL or payload:
- attribute paths.'/foo/bar'(post).parameters.There are duplicate parameter values
at com.atlassian.oai.validator.util.OpenApiLoader.loadApi(OpenApiLoader.java:42)
at com.atlassian.oai.validator.OpenApiInteractionValidator$Builder.build(OpenApiInteractionValidator.java:541)
at com.atlassian.oai.validator.restassured.OpenApiValidationFilter.<init>(OpenApiValidationFilter.java:41)
at TestCatalogue.<clinit>(TestCatalogue.java:30)
If you copy/paste the referenced parameters into the 2nd path verbatim the error is corrected.
Comments (3)
-
reporter -
The named Swagger-Parser bug has been fixed in 2.0.12 and the Swagger-Request-Validator uses 2.0.20. However I’ve updated the version to 2.0.23 and nothing changed. Your Test API still fails to load.
Please raise an issue on: https://github.com/swagger-api/swagger-parser/issues
Until then this is a working workaround.
{ "openapi": "3.0.0", "info": { "title": "Test", "version": "1.0" }, "paths": { "/foo": { "post": { "operationId": "foo", "parameters": [ { "$ref": "#/components/parameters/XSomething" }, { "$ref": "#/components/parameters/XSomethingElse" } ], "responses": { "201": { "description": "Success–resource created." } } } }, "/foo/bar": { "post": { "operationId": "foo2", "parameters": [ { "$ref": "#/components/parameters/XSomething" }, { "$ref": "#/components/parameters/XSomethingElse" } ], "responses": { "201": { "description": "Success–resources created." } } } } }, "components": { "parameters": { "XSomething": { "in": "header", "name": "x-something", "schema": { "type": "string" }, "required": true }, "XSomethingElse": { "in": "header", "name": "x-something-else", "schema": { "type": "string" }, "required": false } } } }
-
reporter Thank for the update Sven, appreciate it. Regretfully I cannot use the work around as the actual file I am working with is getting dereferenced from a number of external files into a single file to be used for validation so I cannot control the manner in with the refs are handled.
Issue filed:
- Log in to comment
It looks like maybe there are some issues that were resolved in the underlying swagger parser:
https://github.com/swagger-api/swagger-parser/pull/1065