Ge0rg3 / flask-parameter-validation

Get and validate all Flask input parameters with ease.
https://pypi.org/project/Flask-Parameter-Validation/
29 stars 12 forks source link

Type Optional[List[str]] rejects all requests #31

Closed jramseygreen closed 11 months ago

jramseygreen commented 11 months ago

When setting a parameter type to Optional[List[str]], whether I send it in the payload or not it will return error response "Parameter must be type 'typing.Optional[typing.List[str]]'"

jramseygreen commented 11 months ago

line 167 of parameter_validation.py

# In python3.7+, typing.Optional is used instead of typing.Union[..., None]
        if expected_input_type_str.startswith("typing.Optional"):
            new_type = expected_input_type.__args__[0]
            expected_input_type = new_type

Change to

        # In python3.7+, typing.Optional is used instead of typing.Union[..., None]
        if expected_input_type_str.startswith("typing.Optional"):
            new_type = expected_input_type.__args__[0]
            expected_input_type = new_type
            expected_input_type_str = str(new_type)

fixes the issue

Ge0rg3 commented 11 months ago

Closed by #33, thanks again!