From 99d0d0055ea97ef79f2ca2d48d17721b024ea947 Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Wed, 1 Jan 2020 18:07:16 +0000 Subject: [PATCH] Converted webargs decorators to classes (allowing auto-docs) --- .../common/flask_labthings/decorators.py | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/openflexure_microscope/common/flask_labthings/decorators.py b/openflexure_microscope/common/flask_labthings/decorators.py index 1ffeebed..ed0cb8b2 100644 --- a/openflexure_microscope/common/flask_labthings/decorators.py +++ b/openflexure_microscope/common/flask_labthings/decorators.py @@ -1,5 +1,5 @@ -from webargs.flaskparser import use_args, use_kwargs -from functools import wraps +from webargs import flaskparser +from functools import wraps, update_wrapper from flask import make_response @@ -43,3 +43,30 @@ class marshal_with(object): return make_response(self.schema.jsonify(resp)) return wrapper + + +class use_args(object): + def __init__(self, argmap, **kwargs): + """ + Equivalent to webargs.flask_parser.use_args + """ + self.argmap = argmap + self.wrapper = flaskparser.use_args(argmap, **kwargs) + + def __call__(self, f): + update_wrapper(self.wrapper, f) + return self.wrapper(f) + + +class use_kwargs(object): + def __init__(self, argmap, **kwargs): + """ + Equivalent to webargs.flask_parser.use_kwargs + """ + kwargs["as_kwargs"] = True + self.argmap = argmap + self.wrapper = flaskparser.use_args(argmap, **kwargs) + + def __call__(self, f): + update_wrapper(self.wrapper, f) + return self.wrapper(f)