<commit_before>from flask.ext.restful import Resource, fields
from flask import request, abort, Response
import inspect
import functools
import re
from flask_restful_swagger import registry, registered, api_spec_endpoint
from jinja2 import Template
import os

resource_listing_endpoint = None

def docs(api, apiVersion='0.0', swaggerVersion='1.2',
         basePath='http://localhost:5000',
         resourcePath='/',
         produces=["application/json"],
         api_spec_url='/api/spec'):

  api_add_resource = api.add_resource

  def add_resource(resource, path, *args, **kvargs):
    endpoint = swagger_endpoint(resource, path)
    # Add a .help.json help url
    swagger_path = extract_swagger_path(path)
    endpoint_path = "%s_help_json" % resource.__name__
    api_add_resource(endpoint, "%s.help.json" % swagger_path,
                     endpoint=endpoint_path)
    # Add a .help.html help url
    endpoint_path = "%s_help_html" % resource.__name__
    api_add_resource(endpoint, "%s.help.html" % swagger_path,
                     endpoint=endpoint_path)
    register_once(api_add_resource, apiVersion, swaggerVersion, basePath,
                  resourcePath, produces, api_spec_url)
    return api_add_resource(resource, path, *args, **kvargs)

  api.add_resource = add_resource

  return api

rootPath = os.path.dirname(__file__)

def register_once(add_resource_func, apiVersion, swaggerVersion, basePath,
                  resourcePath, produces, endpoint):
  global registered<commit_msg>Allow passing class instances to api.add_resource in a similar way that flask-restful does. Fix https://github.com/rantav/flask-restful-swagger/issues/30<commit_after>from flask.ext.restful import Resource, fields
from flask import request, abort, Response
import inspect
import functools
import re
from flask_restful_swagger import registry, registered, api_spec_endpoint
from jinja2 import Template
import os
import inspect

resource_listing_endpoint = None

def docs(api, apiVersion='0.0', swaggerVersion='1.2',
         basePath='http://localhost:5000',
         resourcePath='/',
         produces=["application/json"],
         api_spec_url='/api/spec'):

  api_add_resource = api.add_resource

  def add_resource(resource, path, *args, **kvargs):
    resource = make_class(resource)
    endpoint = swagger_endpoint(resource, path)
    # Add a .help.json help url
    swagger_path = extract_swagger_path(path)
    endpoint_path = "%s_help_json" % resource.__name__
    api_add_resource(endpoint, "%s.help.json" % swagger_path,
                     endpoint=endpoint_path)
    # Add a .help.html help url
    endpoint_path = "%s_help_html" % resource.__name__
    api_add_resource(endpoint, "%s.help.html" % swagger_path,
                     endpoint=endpoint_path)
    register_once(api_add_resource, apiVersion, swaggerVersion, basePath,
                  resourcePath, produces, api_spec_url)
    return api_add_resource(resource, path, *args, **kvargs)

  api.add_resource = add_resource

  return api

rootPath = os.path.dirname(__file__)


def make_class(class_or_instance):
  if inspect.isclass(class_or_instance):
    return class_or_instance
  return class_or_instance.__class__


def register_once(add_resource_func, apiVersion, swaggerVersion, basePath,
                  resourcePath, produces, endpoint):
  global registered
{'fraction_non_alphanumeric': 0.09074626865671642, 'fraction_numerical': 0.005970149253731343, 'mean_word_length': 3.920704845814978, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7127721', 'n_tokens_mistral': 1016, 'n_tokens_neox': 979, 'n_words': 231}