Skip to content

Commit

Permalink
add serializated arguments and parameters to request object.
Browse files Browse the repository at this point in the history
  • Loading branch information
flask-pro committed Apr 23, 2024
1 parent e9b047d commit 391f21c
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/flask_first/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,28 +134,28 @@ def add_request_validating() -> None:
if request.method in ('OPTIONS',):
return

method = self._extract_method_from_request(request)
route = self._extract_route_from_request(request)
headers = request.headers
view_args = request.view_args
args = self._resolved_params(request.args)
cookies = self._resolved_params(request.cookies)
json = self._extract_json_from_request(request)

if route not in self._mapped_routes_from_spec:
return

route_as_in_spec = self.route_to_openapi_format(route)

method = self._extract_method_from_request(request)
params_schemas = self.spec.serialized_spec['paths'][route_as_in_spec][method].get(
'parameters'
)
args = self._resolved_params(request.args)
if params_schemas:
args_schema = params_schemas.get('args')
if args_schema:
schema_fields = args_schema().fields
args = self._arg_to_list(args, schema_fields)

headers = request.headers
view_args = request.view_args
cookies = self._resolved_params(request.cookies)
json = self._extract_json_from_request(request)

request_serializer = RequestSerializer(
self.spec,
method,
Expand All @@ -181,10 +181,7 @@ def add_request_validating() -> None:
def _register_response_validation(self) -> None:
@self.app.after_request
def add_response_validating(response: Response) -> Response:
method = self._extract_method_from_request(request)
route = self._extract_route_from_request(request)
json = response.get_json()

if route not in self._mapped_routes_from_spec:
return response

Expand All @@ -197,6 +194,7 @@ def add_response_validating(response: Response) -> Response:
f'Route <{e.args[0]}> not defined in specification.'
)

method = self._extract_method_from_request(request)
try:
method_schema: dict = route_schema[method]
except KeyError as e:
Expand Down Expand Up @@ -224,6 +222,7 @@ def add_response_validating(response: Response) -> Response:
)

if response_content_type == 'application/json':
json = response.get_json()
json_schema = content[response.content_type]['schema']
try:
if isinstance(json, list):
Expand Down

0 comments on commit 391f21c

Please sign in to comment.