flask-restful-swagger icon indicating copy to clipboard operation
flask-restful-swagger copied to clipboard

Dynamic responseClass in the swagger.operation decorator

Open shikasta-net opened this issue 10 years ago • 1 comments

I have a restful resource that takes an argument specifying the database table that it should query. The tables are each also set up as swagger models and the resource correctly returns results based on which one I choose to access. The problem is that I can find no way to access the function's variables from the decorator so cannot assign a responseClass.

I am very new to understanding how decorators work: is it possible to override the decorator so that the function variables can be accessed? Is there another means to access them (it knows about the required arguments somehow when it generates the documentation)?

shikasta-net avatar Jan 05 '15 19:01 shikasta-net

In a different context I believe I found the solution, although I still need to implement this in swagger somehow.

def decorator(f):
  @wraps(f)
  def decorated(*args, **kwargs):
    if not kwargs['parameter']:
      return problem()
    return f(*args, **kwargs)
  return decorated

shikasta-net avatar Jan 09 '15 01:01 shikasta-net