bauerji / flask-pydantic

flask extension for integration with the awesome pydantic package
MIT License
368 stars 58 forks source link

Request change: passing the validated results to the route as parameters #22

Closed OmarThinks closed 3 years ago

OmarThinks commented 3 years ago

Request change: passing the validated results to the route as parameters


I can make this change.
After the data have been validated by the decorator,
Now the developer has to validate them again inside the route.


What if I could pass them after they have clean and validated into the route.
They will be passed from the decorator to the route automatically.
And the user will not have to validate them again in the route.

So the code will look like this:

@app.route("/", methods=["POST"])
@validate(body=BodyModel, query=QueryModel)
def post(requested):
    #Requested is validated
    body = requested.body
    # This is body after validation
    query = requested.query
    # This is query after validation
    name = body["name"]
    nickname = body["nickname"]
    age = query["age"]

This is all what the developer will have to write. Cleaner code.


If God willed, I can make this change. I request your permission to make this change Thank you!

bauerji commented 3 years ago

Hi Omar,

I do not quite know what you meant by After the data have been validated by the decorator, Now the developer has to validate them again inside the route.

There are two ways of how to pass validated parameters into your route function.

I thing the latter one is what you are looking for.

Jirka

OmarThinks commented 3 years ago

Hi Jirka! That was exactly what I have meant. If God willed, When I update the README.md, I will make sure that this is very clear. Because this is what exactly what I came here to this package looking for as a developer. And I believe that other developers need this feature too. I will make very clear to them, so the package will be more usable. I will try to do my best to represent the package in the README.md file. Thank you so much.