Skip to content

Optional and Union types break automatic API Docs #55

Open
@JoshieJay

Description

@JoshieJay

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions