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

feat: allow passing a validator function #6

Closed Garcel closed 2 years ago

Garcel commented 2 years ago

feat: allow passing a validator function to perform complex or customized validations on parameters.

Example:

NEIGHBORHOODS = {
    1: {'id': 1, 'name': 'Birloque'}
}

def is_valid_neighborhood_id(id: int) -> bool:
    return id in NEIGHBORHOODS

@app.route('/neighborhood/<int:id>', methods=['GET'])
@ValidateParameters()
def get_neighborhood(id: int = Route(func=is_valid_neighborhood_id)):
    return NEIGHBORHOODS.get(id)
Ge0rg3 commented 2 years ago

Looks great, thank you for the PR!