fromflask_openapi3importRawModelclassBookRaw(RawModel):mimetypes=["text/csv","application/json"]@app.post("/book")defget_book(raw:BookRaw):# raw equals to flask.requestprint(raw.data)print(raw.mimetype)return"ok"
When your 'auth decorator' injects custom kwargs, these will be passed on to the final function for you to use.
Any kwargs which are part of the 'path' will have been consumed at this point and can only be referenced using the path.
So avoid using kwarg-names which overlap with the path.
1 2 3 4 5 6 7 8 910111213141516171819202122232425
fromflask_openapi3importvalidate_requestfromfunctoolsimportwrapsdeflogin_required():defdecorator(func):@wraps(func)defwrapper(*args,**kwargs):ifnotrequest.headers.get("Authorization"):return{"error":"Unauthorized"},401kwargs["client_id"]="client1234565"returnfunc(*args,**kwargs)returnwrapperreturndecorator@app.get("/book")@login_required()@validate_request()defget_book(query:BookQuery,client_id:str=None):print(f"Current user identified as {client_id}")...