Skip to content

Commit f64236d

Browse files
authoredNov 16, 2023
Merge pull request #28 from summersz/async
feat: support async view functions
2 parents a03ad91 + 3e02b86 commit f64236d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed
 

‎flask_parameter_validation/parameter_validation.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import asyncio
2+
import functools
13
import inspect
24
import re
35
from inspect import signature
@@ -40,7 +42,8 @@ def __call__(self, f):
4042
}
4143
fn_list[fsig] = fdocs
4244

43-
def nested_func(**kwargs):
45+
@functools.wraps(f)
46+
async def nested_func(**kwargs):
4447
# Step 1 - Combine all flask input types to one dict
4548
json_input = None
4649
if request.headers.get("Content-Type") is not None:
@@ -78,7 +81,11 @@ def nested_func(**kwargs):
7881
except Exception as e:
7982
return self.custom_error_handler(e)
8083
validated_inputs[expected.name] = new_input
81-
return f(**validated_inputs)
84+
85+
if asyncio.iscoroutinefunction(f):
86+
return await f(**validated_inputs)
87+
else:
88+
return f(**validated_inputs)
8289

8390
nested_func.__name__ = f.__name__
8491
return nested_func

‎setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
platforms='any',
2929
install_requires=[
3030
'Flask',
31+
'flask[async]',
3132
'python-dateutil',
3233
],
3334
classifiers=[

0 commit comments

Comments
 (0)
Please sign in to comment.