|
1 | 1 | """OpenAPI core validation request validators module""" |
| 2 | +from itertools import chain |
2 | 3 | from six import iteritems |
3 | 4 |
|
4 | 5 | from openapi_core.schema.exceptions import OpenAPIMappingError |
@@ -28,30 +29,34 @@ def validate(self, request): |
28 | 29 |
|
29 | 30 | try: |
30 | 31 | path = self.spec[operation_pattern] |
31 | | - # don't process if operation errors |
32 | | - except OpenAPIMappingError as exc: |
33 | | - return RequestValidationResult([exc, ], None, None) |
34 | | - |
35 | | - path_params, path_params_errors = self._get_parameters(request, path) |
36 | | - |
37 | | - try: |
38 | 32 | operation = self.spec.get_operation( |
39 | 33 | operation_pattern, request.method) |
40 | 34 | # don't process if operation errors |
41 | 35 | except OpenAPIMappingError as exc: |
42 | 36 | return RequestValidationResult([exc, ], None, None) |
43 | 37 |
|
44 | | - op_params, op_params_errors = self._get_parameters(request, operation) |
| 38 | + params, params_errors = self._get_parameters( |
| 39 | + request, chain( |
| 40 | + iteritems(operation.parameters), |
| 41 | + iteritems(path.parameters) |
| 42 | + ) |
| 43 | + ) |
| 44 | + |
45 | 45 | body, body_errors = self._get_body(request, operation) |
46 | 46 |
|
47 | | - errors = path_params_errors + op_params_errors + body_errors |
48 | | - return RequestValidationResult(errors, body, path_params + op_params) |
| 47 | + errors = params_errors + body_errors |
| 48 | + return RequestValidationResult(errors, body, params) |
49 | 49 |
|
50 | | - def _get_parameters(self, request, operation): |
| 50 | + def _get_parameters(self, request, params): |
51 | 51 | errors = [] |
52 | | - |
| 52 | + seen = set() |
53 | 53 | parameters = RequestParameters() |
54 | | - for param_name, param in iteritems(operation.parameters): |
| 54 | + for param_name, param in params: |
| 55 | + if (param_name, param.location.value) in seen: |
| 56 | + # skip parameter already seen |
| 57 | + # e.g. overriden path item paremeter on operation |
| 58 | + continue |
| 59 | + seen.add((param_name, param.location.value)) |
55 | 60 | try: |
56 | 61 | raw_value = param.get_value(request) |
57 | 62 | except MissingParameter: |
|
0 commit comments