flask-restx icon indicating copy to clipboard operation
flask-restx copied to clipboard

/swaggerui statics prefix configuration

Open pwilczynskiclearcode opened this issue 2 years ago • 3 comments

I wanted to serve swagger docs statics at different url prefix than /swaggerui/ at the root. Currently it's hardcoded in https://github.com/python-restx/flask-restx/blob/master/flask_restx/apidoc.py#L24 making it impossible to serve it at e.g. /api/swaggerui

pwilczynskiclearcode avatar Mar 29 '22 13:03 pwilczynskiclearcode

I have the same issue, becouse i have a load balancer and i want to serve swagger docs statics in api/v1/ this is solved or is a issue open? or do you have a some example

jcita avatar May 24 '23 16:05 jcita

No. I didn't figure out the solution... You may try some monkey-patching like:

STATIC_URL_PATH = "/"

import flask_restx
from flask import url_for

flask_restx.apidoc.apidoc = flask_restx.apidoc.Apidoc(
    "restx_doc",
    __name__,
    template_folder="templates",
    static_folder="static",
    static_url_path=STATIC_URL_PATH,
)

@flask_restx.apidoc.apidoc.add_app_template_global
def swagger_static(filename):
    return url_for("restx_doc.static", filename=filename)

(I didn't verify this code)

pwilczynskiclearcode avatar May 25 '23 07:05 pwilczynskiclearcode

actually i already tried that option and it works but i can't find a way to get it from code or replacing some decorator without having to go to the core of the library. for this solution i would have to be able to do a fork right? because I am not interested in having a new template but in using the original one from the library but served in my blueprint /api/v1/.

jcita avatar May 25 '23 15:05 jcita