def create_custom_apidoc(url=None):
    """
    Create API document object for SwaggerUI generator
    :param url: URL to store static files for documentation
    :return: APIdoc object
    """
    if url is None:
        url = '/'

    relative_name = 'restplus_relative_doc{0}'.format(url)
    custom_apidoc = apidoc.Apidoc(
        relative_name,
        __name__,
        template_folder='templates',
        static_folder=os.path.dirname(apidoc.__file__) + '/static',
        static_url_path='/swaggerui')

    @custom_apidoc.add_app_template_global
    def swagger_static(filename):
        """
        Change Swagger static file path
        :param filename: Filename from Swagger
        :return:
        """
        return url_for('{0}.static'.format(relative_name), filename=filename)

    return custom_apidoc
Beispiel #2
0
def configure_restplus(app_name):
    """
        Override flask_restplus apidoc variable passing the apps
        name as a paramenter but still pointing to the library's
        folders /template and /static

        Now swagger calls statics at /{app_name}/swaggerui/{static_file}
    """
    from flask_restplus import apidoc

    apidoc.apidoc = apidoc.Apidoc(
        "restplus_doc",
        __name__,
        template_folder=os.path.dirname(apidoc.__file__) + "/templates",
        static_folder=os.path.dirname(apidoc.__file__) + "/static",
        static_url_path=f"/{app_name}/swaggerui",
    )
    # redefine swagger_static
    @apidoc.apidoc.add_app_template_global
    def swagger_static(filename):
        return url_for("restplus_doc.static", filename=filename)
Beispiel #3
0
def initialize_app(flask_app):
    configure_app(flask_app)

    blueprint = Blueprint('api', __name__, url_prefix='/pyapi')
    api.init_app(blueprint)
    api.add_namespace(jenkins_job_namespace)
    api.add_namespace(health_namespace)
    flask_app.register_blueprint(blueprint)

    custom_apidoc = apidoc.Apidoc(
        'restplus_custom_doc',
        __name__,
        template_folder='templates',
        static_folder=os.path.dirname(apidoc.__file__) + '/static',
        static_url_path='/')

    @custom_apidoc.add_app_template_global
    def swagger_static(filename):
        return url_for('restplus_custom_doc.static', filename=filename)

    flask_app.register_blueprint(custom_apidoc, url_prefix='/pyapi/ui')
Beispiel #4
0
from flask import Flask, url_for
from set_destiny_web.api import api
from flask_restplus import apidoc
from os.path import dirname, join


custom_apidoc = apidoc.Apidoc('restplus_custom_doc', __name__,
                              template_folder='templates',
                              static_folder=join(dirname(apidoc.__file__), 'static'),
                              static_url_path='swaggerui')


@custom_apidoc.add_app_template_global
def swagger_static(filename):
    return url_for('restplus_doc.static', filename=filename)


def create_app():
    app = Flask(__name__)
    app.register_blueprint(api, url_prefix='/api')
    app.register_blueprint(custom_apidoc, url_prefix='/api')

    return app
Beispiel #5
0
app.config.SWAGGER_UI_JSONEDITOR = True

if environment.DEVELOPER_MODE:
    app.debug = True

# Prevent flask-restplus from registering docs so we
# can customize the route
app.extensions.setdefault("restplus", {"apidoc_registered": True})

# Register the URL route blueprints
register_blueprints(app, "hello")

# Setup route redirect for the documentation
redirect_apidoc = apidoc.Apidoc('restplus_doc',
                                apidoc.__name__,
                                template_folder='templates',
                                static_folder='static',
                                static_url_path='/hello/swaggerui')


@redirect_apidoc.add_app_template_global
def swagger_static(filename):
    static_url = url_for('restplus_doc.static', filename=filename)
    logger.critical("filename: %s" % filename)
    return static_url


app.register_blueprint(redirect_apidoc)


# =================================================================