Skip to content

Commit 6253528

Browse files
committed
Implement use of UUID prepended to function signature to ensure that each registered flask route can be associated with its function declaration
1 parent e287345 commit 6253528

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

flask_parameter_validation/docs_blueprint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def get_function_docs(func):
3434
"""
3535
fn_list = ValidateParameters().get_fn_list()
3636
for fsig, fdocs in fn_list.items():
37-
if fsig.endswith(func.__name__):
37+
if hasattr(func, "__fpv_discriminated_sig__") and func.__fpv_discriminated_sig__ == fsig:
3838
return {
3939
"docstring": format_docstring(fdocs.get("docstring")),
4040
"decorators": fdocs.get("decorators"),

flask_parameter_validation/parameter_validation.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import functools
33
import inspect
44
import re
5+
import uuid
56
from inspect import signature
67
from flask import request, Response
78
from werkzeug.datastructures import ImmutableMultiDict
@@ -28,6 +29,11 @@ def __call__(self, f):
2829
Parent flow for validating each required parameter
2930
"""
3031
fsig = f.__module__ + "." + f.__name__
32+
# Add a discriminator to the function signature, store it in the properties of the function
33+
# This is used in documentation generation to associate the info gathered from inspecting the
34+
# function with the properties passed to the ValidateParameters decorator
35+
f.__fpv_discriminated_sig__ = f"{uuid.uuid4()}_{fsig}"
36+
fsig = f.__fpv_discriminated_sig__
3137
argspec = inspect.getfullargspec(f)
3238
source = inspect.getsource(f)
3339
index = source.find("def ")

0 commit comments

Comments
 (0)