title: Dynamically generate Flask-RESTPlus routes
body: <p>I am trying to abstract away some of the route class logic (i.e. I am looking to dynamically generate routes).  <code>api.add_resource</code> seemed like the right place to do this.</p>
  
  <p>So this is what I am trying to do:</p>
  
  <pre><code># app.py
  
  from flask import Flask
  from flask_restplus import Api, Resource, fields
  from mylib import MyPost
  
  # Define my model
  json_model = api.schema_model(...)
  
  api.add_resource(
      MyPost,
      '/acme',
      resource_class_kwargs={"json_model": json_model}
  )
  </code></pre>
  
  <p>And then in mylib:</p>
  
  <pre><code># mylib.py
  
  def validate_endpoint(f):
      def wrapper(*args, **kwargs):
          return api.expect(json_fprint)(f(*args, **kwargs))
      return wrapper
  
  class MyPost(Resource):
      def __init__(self, *args, **kwargs):
          # Passed in via api.add_resource
          self.api = args[0]
          self.json_model = kwargs['json_model']
  
      # I can't do this because I don't have access to 'api' here...
      # @api.expect(json_model)
  
      # So I am trying to make this work
      @validate_endpoint
      def post(self):
          return {"data":'some data'}, 200
  </code></pre>
  
  <p>I don’t have access to the global api object here so I can’t call <code>@api.expect(json_model)</code>.  But I do have access to <code>api</code> and <code>json_model</code> inside of the post method.  Which is why I am trying to create my own <code>validate_endpoint</code> decorator.</p>
  
  <p>This does not work though.  Is what I am trying to do here even possible?  Is there a better approach I should be taking?</p>