Skip to content

Commit

Permalink
Merge pull request #2 from kodemore/improve-content-type-recognition
Browse files Browse the repository at this point in the history
Improve content type recognition
  • Loading branch information
dkraczkowski authored Nov 11, 2021
2 parents c489102 + c56df81 commit 0c6f6f4
Show file tree
Hide file tree
Showing 6 changed files with 306 additions and 179 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Open api integration can be used to:
- validate request's headers
- validate request's query parameters
- validate request's cookies
- json references
- generate dtos from openapi file

## Installation

Expand Down
4 changes: 4 additions & 0 deletions chocs_middleware/openapi/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def handle(self, request: HttpRequest, next: MiddlewareHandler) -> HttpResponse:
if not route:
return next(request)

if route and "skip_validation" in route.attributes and route.attributes["skip_validation"]:
return next(request)

validator_cache_key = f"{request.method} {route.route}".lower()
if validator_cache_key not in self._validators:
self._validators[validator_cache_key] = self._get_validators_for_uri(
Expand All @@ -53,6 +56,7 @@ def _get_validators_for_uri(self, route: str, method: HttpMethod, content_type:
path = route.replace("/", "\\/")
method_name = str(method).lower()
validators: List[Callable] = []
content_type = content_type.split(";")[0].strip() # e.g. application/json ; encoding=utf8

try:
open_api_uri_schema = self.openapi.query(f"/paths/{path}")
Expand Down
Loading

0 comments on commit 0c6f6f4

Please sign in to comment.