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

Validating both Post and Get #43

Closed peterkronenberg closed 3 months ago

peterkronenberg commented 4 months ago

Is there a way I can have a function which works with both Post and Get, where it finds the value in the appropriate place depending on the method?

Basically, something like this:

func(
    variable: str = Json(min_str_length=1) or Query(min_str_length=1)
):
smt5541 commented 4 months ago

The only way this is currently possible is by first defining a helper function that handles the method's logic and calling it from two separate routes. This could possibly be changed, would likely need a Parameter subclass (AnyOf, or some other name) that takes in a list of the locations it should accept parameters from in the order of precedence.