Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions openapi_spec_validator/validation/keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,20 @@ def __call__(
if path_parameters is not None:
names += list(self._get_path_param_names(path_parameters))

all_params = list(set(names))
all_params = set(names)
url_params = set(self._get_path_params_from_url(url))

for path in self._get_path_params_from_url(url):
for path in sorted(url_params):
if path not in all_params:
yield UnresolvableParameterError(
f"Path parameter '{path}' for '{name}' operation in '{url}' was not resolved"
)

for path in sorted(all_params):
if path not in url_params:
yield UnresolvableParameterError(
f"Path parameter '{path}' for '{name}' operation in '{url}' was not resolved"
)
return

def _get_path_param_names(self, params: SchemaPath) -> Iterator[str]:
Expand Down
40 changes: 40 additions & 0 deletions tests/integration/validation/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,46 @@ def test_undocumented_parameter(self):
"'/test/{param1}/{param2}' was not resolved"
)

def test_extra_path_parameter_not_present_in_path(self):
spec = {
"openapi": "3.0.0",
"info": {
"title": "Test Api",
"version": "0.0.1",
},
"paths": {
"/test": {
"get": {
"responses": {
"default": {
"description": "default response",
},
},
"parameters": [
{
"name": "param1",
"in": "path",
"required": True,
"schema": {
"type": "integer",
},
},
],
},
},
},
}

errors = OpenAPIV30SpecValidator(spec).iter_errors()

errors_list = list(errors)
assert len(errors_list) == 1
assert errors_list[0].__class__ == UnresolvableParameterError
assert errors_list[0].message == (
"Path parameter 'param1' for 'get' operation in '/test' "
"was not resolved"
)

def test_default_value_wrong_type(self):
spec = {
"openapi": "3.0.0",
Expand Down