Skip to content

Commit a8d7d9b

Browse files
author
Gerhard Weis
committed
very simple and hacky path item parameter override test
1 parent 4ac4baf commit a8d7d9b

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

tests/integration/test_validators.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def test_get_pet(self, validator):
235235
class TestPathItemParamsValidator(object):
236236

237237
@pytest.fixture
238-
def spec_dict(self, factory):
238+
def spec_dict(self):
239239
return {
240240
"openapi": "3.0.0",
241241
"info": {
@@ -305,6 +305,49 @@ def test_request_valid_param(self, validator):
305305
assert result.body is None
306306
assert result.parameters == {'query': {'resId': 10}}
307307

308+
@pytest.mark.xfail
309+
def test_request_override_param(self, spec_dict):
310+
# override parameter path parameter on operation (name and in property must match)
311+
spec_dict["paths"]["/resource"]["get"]["parameters"] = [
312+
{
313+
# full valid parameter object required
314+
"name": "resId",
315+
"in": "query",
316+
"required": False,
317+
"schema": {
318+
"type": "integer",
319+
},
320+
}
321+
]
322+
validator = RequestValidator(create_spec(spec_dict))
323+
request = MockRequest('http://example.com', 'get', '/resource')
324+
result = validator.validate(request)
325+
326+
assert len(result.errors) == 0
327+
assert result.body is None
328+
assert result.parameters == {}
329+
330+
@pytest.mark.xfail
331+
def test_request_override_invalid_param(self, spec_dict):
332+
# override parameter path parameter on operation
333+
# This here should result in an invalid spec object, because there are
334+
# now two parameters with the same name, but different location.
335+
# (The openapi3 spec is also not very explicit about this case)
336+
spec_dict["paths"]["/resource"]["get"]["parameters"] = [
337+
{
338+
# full valid parameter object required
339+
"name": "resId",
340+
"in": "path",
341+
"required": False,
342+
"schema": {
343+
"type": "integer",
344+
},
345+
}
346+
]
347+
from openapi_spec_validator.exceptions import OpenAPIValidationError
348+
with pytest.raises(OpenAPIValidationError):
349+
spec = create_spec(spec_dict)
350+
308351

309352
class TestResponseValidator(object):
310353

0 commit comments

Comments
 (0)