flask-parameter-validation icon indicating copy to clipboard operation
flask-parameter-validation copied to clipboard

Optional and Union types break automatic API Docs

Open JoshieJay opened this issue 1 year ago • 3 comments

Using an Optional or Union type with the @ValidateParameters decorator works for validation purposes, but it causes a 500 error when accessing the /docs route.

It looks like it may be this function that is causing the issue.

def get_arg_type_hint(fdocs, arg_name): """ Extract the type hint for a specific argument. """ arg_type = fdocs["argspec"].annotations[arg_name] if hasattr(arg_type, "__args__"): return ( f"{arg_type.__name__}[{', '.join([a.__name__ for a in arg_type.__args__])}]" ) return arg_type.__name__

Specifically the arg_type.__name__ seems to not exist for Optional and Union types.

It looks like there is a note about Optional parameters in 2.3.0 (https://github.com/Ge0rg3/flask-parameter-validation/releases/tag/v2.3.0), but I think this may just be for validation.

JoshieJay avatar Sep 06 '24 14:09 JoshieJay