Added decorator for documenting response codes
This commit is contained in:
parent
3bcfd86ccc
commit
b3f32f2309
2 changed files with 24 additions and 1 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
from openflexure_microscope.api.utilities import get_bool, JsonResponse
|
from openflexure_microscope.api.utilities import get_bool, JsonResponse
|
||||||
from openflexure_microscope.common.flask_labthings.resource import Resource
|
from openflexure_microscope.common.flask_labthings.resource import Resource
|
||||||
from openflexure_microscope.common.flask_labthings.find import find_device
|
from openflexure_microscope.common.flask_labthings.find import find_device
|
||||||
from openflexure_microscope.common.flask_labthings.decorators import use_args, marshal_with, doc
|
from openflexure_microscope.common.flask_labthings.decorators import use_args, marshal_with, doc, response
|
||||||
from openflexure_microscope.common.flask_labthings import fields
|
from openflexure_microscope.common.flask_labthings import fields
|
||||||
from openflexure_microscope.utilities import filter_dict
|
from openflexure_microscope.utilities import filter_dict
|
||||||
|
|
||||||
|
|
@ -28,6 +28,7 @@ class CaptureAPI(Resource):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@marshal_with(capture_schema)
|
@marshal_with(capture_schema)
|
||||||
|
@response(200, "Capture successful")
|
||||||
def post(self, args):
|
def post(self, args):
|
||||||
microscope = find_device("openflexure_microscope")
|
microscope = find_device("openflexure_microscope")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ from webargs import flaskparser
|
||||||
from functools import wraps, update_wrapper
|
from functools import wraps, update_wrapper
|
||||||
from flask import make_response
|
from flask import make_response
|
||||||
|
|
||||||
|
from .utilities import rupdate
|
||||||
|
|
||||||
def unpack(value):
|
def unpack(value):
|
||||||
"""Return a three tuple of data, code, and headers"""
|
"""Return a three tuple of data, code, and headers"""
|
||||||
|
|
@ -84,3 +85,24 @@ class doc(object):
|
||||||
f.__apispec__ = f.__dict__.get('__apispec__', {})
|
f.__apispec__ = f.__dict__.get('__apispec__', {})
|
||||||
f.__apispec__.update(self.kwargs)
|
f.__apispec__.update(self.kwargs)
|
||||||
return f
|
return f
|
||||||
|
|
||||||
|
|
||||||
|
class response(object):
|
||||||
|
def __init__(self, code, description, **kwargs):
|
||||||
|
self.code = code
|
||||||
|
self.description = description
|
||||||
|
self.kwargs = kwargs
|
||||||
|
|
||||||
|
def __call__(self, f):
|
||||||
|
# Pass params to call function attribute for external access
|
||||||
|
f.__apispec__ = f.__dict__.get('__apispec__', {})
|
||||||
|
d = {
|
||||||
|
"responses": {
|
||||||
|
self.code: {
|
||||||
|
"description": self.description,
|
||||||
|
**self.kwargs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rupdate(f.__apispec__, d)
|
||||||
|
return f
|
||||||
Loading…
Add table
Add a link
Reference in a new issue