Skip to content

Commit

Permalink
Merge pull request #1 from stortiz-lifeworks/Not-validate-undefined-e…
Browse files Browse the repository at this point in the history
…ndpoints

Not validate undefined endpoints
  • Loading branch information
dkraczkowski authored Nov 9, 2021
2 parents 34588af + 07750ad commit 489d020
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion chocs_middleware/openapi/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _get_validators_for_uri(self, route: str, method: HttpMethod, content_type:
try:
open_api_uri_schema = self.openapi.query(f"/paths/{path}")
open_api_method_schema = open_api_uri_schema[method_name]
except KeyError:
except (KeyError, LookupError):
return validators

if self.validators["body"]:
Expand Down
21 changes: 21 additions & 0 deletions tests/openapi/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,24 @@ def _next(request: HttpRequest) -> HttpResponse:

# then
assert response == success_response


def test_request_with_no_openapi_definition_is_valid() -> None:
# given
dirname = path.dirname(__file__)
middleware = OpenApiMiddleware(path.join(dirname, "../fixtures/openapi.yml"))
request = HttpRequest(
HttpMethod.GET,
"/non_existent_endpoint_XYZ",
)
request.route = Route("/non_existent_endpoint_XYZ")
success_response = HttpResponse()

def _next(request: HttpRequest) -> HttpResponse:
return success_response

# when
response = middleware.handle(request, _next)

# then
assert response == success_response

0 comments on commit 489d020

Please sign in to comment.