Added decorator for documenting response codes
This commit is contained in:
parent
3bcfd86ccc
commit
b3f32f2309
2 changed files with 24 additions and 1 deletions
|
|
@ -2,6 +2,7 @@ from webargs import flaskparser
|
|||
from functools import wraps, update_wrapper
|
||||
from flask import make_response
|
||||
|
||||
from .utilities import rupdate
|
||||
|
||||
def unpack(value):
|
||||
"""Return a three tuple of data, code, and headers"""
|
||||
|
|
@ -83,4 +84,25 @@ class doc(object):
|
|||
# Pass params to call function attribute for external access
|
||||
f.__apispec__ = f.__dict__.get('__apispec__', {})
|
||||
f.__apispec__.update(self.kwargs)
|
||||
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