Skip to content

Commit

Permalink
Refactor: Rename blueprint variable to swagger_blueprint
Browse files Browse the repository at this point in the history
Because the blueprint variable name also be used when building blueprint
tags, rename it to avoid the confusions.
  • Loading branch information
chenjr0719 committed Jun 20, 2019
1 parent ed932cc commit d65f0bb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion sanic_openapi/__init__.py
@@ -1,4 +1,4 @@
from .swagger import blueprint as swagger_blueprint
from .swagger import swagger_blueprint

__version__ = "0.5.3"
__all__ = ["swagger_blueprint"]
18 changes: 9 additions & 9 deletions sanic_openapi/swagger.py
Expand Up @@ -10,20 +10,20 @@
from .doc import route as doc_route
from .doc import route_specs, serialize_schema

blueprint = Blueprint("swagger", url_prefix="/swagger")
swagger_blueprint = Blueprint("swagger", url_prefix="/swagger")

dir_path = os.path.dirname(os.path.realpath(__file__))
dir_path = os.path.abspath(dir_path + "/ui")


# Redirect "/swagger" to "/swagger/"
@blueprint.route("", strict_slashes=True)
@swagger_blueprint.route("", strict_slashes=True)
def index(request):
return redirect("{}/".format(blueprint.url_prefix))
return redirect("{}/".format(swagger_blueprint.url_prefix))


blueprint.static("/", dir_path + "/index.html", strict_slashes=True)
blueprint.static("/", dir_path)
swagger_blueprint.static("/", dir_path + "/index.html", strict_slashes=True)
swagger_blueprint.static("/", dir_path)


_spec = {}
Expand All @@ -38,7 +38,7 @@ def remove_nulls(dictionary, deep=True):
}


@blueprint.listener("before_server_start")
@swagger_blueprint.listener("before_server_start")
def build_spec(app, loop):
_spec["swagger"] = "2.0"
_spec["info"] = {
Expand Down Expand Up @@ -96,7 +96,7 @@ def build_spec(app, loop):
for uri, route in app.router.routes_all.items():

# Ignore routes under swagger blueprint
if route.uri.startswith(blueprint.url_prefix):
if route.uri.startswith(swagger_blueprint.url_prefix):
continue

if "static" in route.name:
Expand Down Expand Up @@ -244,13 +244,13 @@ def build_spec(app, loop):
_spec["paths"] = paths


@blueprint.route("/swagger.json")
@swagger_blueprint.route("/swagger.json")
@doc_route(exclude=True)
def spec(request):
return json(_spec)


@blueprint.route("/swagger-config")
@swagger_blueprint.route("/swagger-config")
def config(request):
options = {}

Expand Down

0 comments on commit d65f0bb

Please sign in to comment.