Skip to content

Commit

Permalink
v0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
PWZER committed Apr 27, 2020
1 parent 199fa0d commit c8796ca
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 99 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ Only support Python3.
Open `http://<host>:<port>/api/doc` view api doc.

## Swagger UI
Swagger UI version is `3.24.3`. see [https://github.com/swagger-api/swagger-ui](https://github.com/swagger-api/swagger-ui).
Swagger UI version is `3.25.1`. see [https://github.com/swagger-api/swagger-ui](https://github.com/swagger-api/swagger-ui).

## Swagger Editor
Swagger Editor version is `3.7.1`. see [https://github.com/swagger-api/swagger-editor](https://github.com/swagger-api/swagger-editor).
Swagger Editor version is `3.8.1`. see [https://github.com/swagger-api/swagger-editor](https://github.com/swagger-api/swagger-editor).

## Update
You can update swagger ui and swagger editor version with
Expand Down
2 changes: 1 addition & 1 deletion examples/falcon_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def on_get(self, req, resp):

from swagger_ui import api_doc

api_doc(app, config_path=config_path)
api_doc(app, config_path=config_path, url_prefix='/api/doc')

httpd = simple_server.make_server('0.0.0.0', 8989, app)
httpd.serve_forever()
98 changes: 48 additions & 50 deletions swagger_ui/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import re
import sys
import urllib.request
from distutils.version import StrictVersion
from pathlib import Path
Expand All @@ -18,7 +17,7 @@ def __init__(self, app, app_type=None, config_path=None, config_url=None,

self._app = app
self._title = title
self._url_prefix = url_prefix
self._url_prefix = url_prefix.rstrip('/')
self._config_url = config_url
self._config_path = config_path
self._editor = editor
Expand All @@ -37,7 +36,7 @@ def __init__(self, app, app_type=None, config_path=None, config_url=None,

@property
def static_dir(self):
return CURRENT_DIR.joinpath('static')
return str(CURRENT_DIR.joinpath('static'))

@property
def doc_html(self):
Expand Down Expand Up @@ -104,6 +103,7 @@ def get(self, *args, **kwargs):

handlers = [
(self._uri(), DocHandler),
(self._uri('/'), DocHandler),
(self._uri('/swagger.json'), ConfigHandler),
(self._uri('/(.+)'), StaticFileHandler, {'path': self.static_dir}),
]
Expand All @@ -119,13 +119,17 @@ def _flask_handler(self):

swagger_blueprint = Blueprint(
'swagger_blueprint', __name__, url_prefix=self._url_prefix,
static_folder=str(self.static_dir), static_url_path='/'
static_folder=self.static_dir, static_url_path='/'
)

@swagger_blueprint.route(r'/')
@swagger_blueprint.route(r'')
def swagger_blueprint_doc_handler():
return self.doc_html

@swagger_blueprint.route(r'/')
def swagger_blueprint_doc_v2_handler():
return self.doc_html

@swagger_blueprint.route(r'/swagger.json')
def swagger_blueprint_config_handler():
return jsonify(self.get_config(request.host))
Expand All @@ -150,6 +154,7 @@ async def swagger_config_handler(request):
return web.json_response(self.get_config(request.host))

self._app.router.add_get(self._uri(), swagger_doc_handler)
self._app.router.add_get(self._uri('/'), swagger_doc_handler)

if self._editor:
self._app.router.add_get(self._uri('/editor'), swagger_editor_handler)
Expand All @@ -160,6 +165,7 @@ async def swagger_config_handler(request):
def _bottle_handler(self):
from bottle import static_file, request

@self._app.get(self._uri())
@self._app.get(self._uri(r'/'))
def index():
return self.doc_html
Expand Down Expand Up @@ -225,37 +231,29 @@ async def swagger_blueprint_config_handler():

def _falcon_handler(self):
import json
interface = self

class SwaggerDocHandler:
def __init__(self, interface):
self._doc_html = interface.doc_html

def on_get(self, req, resp):
resp.content_type = 'text/html'
resp.body = self._doc_html
resp.body = interface.doc_html

class SwaggerEditorHandler:
def __init__(self, interface):
self._editor_html = interface.editor_html

def on_get(self, req, resp):
resp.content_type = 'text/html'
resp.body = self._editor_html
resp.body = interface.editor_html

class SwaggerConfigHandler:
def __init__(self, interface):
self._interface = interface

def on_get(self, req, resp):
resp.content_type = 'application/json'
resp.body = json.dumps(self._interface.get_config(f'{req.host}:{req.port}'))
resp.body = json.dumps(interface.get_config(f'{req.host}:{req.port}'))

self._app.add_route(self._uri(), SwaggerDocHandler(self))
self._app.add_route(self._uri('/'), SwaggerDocHandler())

if self._editor:
self._app.add_route(self._uri('/editor'), SwaggerEditorHandler(self))
self._app.add_route(self._uri('/editor'), SwaggerEditorHandler())

self._app.add_route(self._uri('/swagger.json'), SwaggerConfigHandler(self))
self._app.add_route(self._uri('/swagger.json'), SwaggerConfigHandler())
self._app.add_static_route(prefix=self._uri(
'/'), directory='{}/'.format(self.static_dir), downloadable=True)

Expand All @@ -273,7 +271,8 @@ async def swagger_config_handler(request):
host = '{}:{}'.format(request.url.hostname, request.url.port)
return JSONResponse(self.get_config(host))

self._app.router.add_route(self._uri('/',), swagger_doc_handler, ['get'], 'swagger-ui')
self._app.router.add_route(self._uri(''), swagger_doc_handler, ['get'], 'swagger-ui')
self._app.router.add_route(self._uri('/'), swagger_doc_handler, ['get'], 'swagger-ui')

if self._editor:
self._app.router.add_route(
Expand All @@ -300,6 +299,34 @@ def _auto_match_handler(self):
except ImportError:
pass

try:
import sanic
if isinstance(self._app, sanic.Sanic):
return self._sanic_handler()
except ImportError:
pass

try:
import aiohttp.web
if isinstance(self._app, aiohttp.web.Application):
return self._aiohttp_handler()
except ImportError:
pass

try:
import quart
if isinstance(self._app, quart.Quart):
return self._quart_handler()
except ImportError:
pass

try:
import starlette.applications
if isinstance(self._app, starlette.applications.Starlette):
return self._starlette_handler()
except ImportError:
pass

try:
import falcon
if isinstance(self._app, falcon.API):
Expand All @@ -314,33 +341,4 @@ def _auto_match_handler(self):
except ImportError:
pass

if sys.version_info >= (3, 0):
try:
import sanic
if isinstance(self._app, sanic.Sanic):
return self._sanic_handler()
except ImportError:
pass

try:
import aiohttp.web
if isinstance(self._app, aiohttp.web.Application):
return self._aiohttp_handler()
except ImportError:
pass

try:
import quart
if isinstance(self._app, quart.Quart):
return self._quart_handler()
except ImportError:
pass

try:
import starlette.applications
if isinstance(self._app, starlette.applications.Starlette):
return self._starlette_handler()
except ImportError:
pass

raise Exception('No match application isinstance type!')
30 changes: 16 additions & 14 deletions swagger_ui/static/swagger-editor-bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-editor-bundle.js.map

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions swagger_ui/static/swagger-editor-standalone-preset.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-editor-standalone-preset.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-editor.js.map

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions swagger_ui/static/swagger-ui-bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-ui-bundle.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-ui-standalone-preset.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-ui-standalone-preset.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions swagger_ui/static/swagger-ui.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-ui.js.map

Large diffs are not rendered by default.

0 comments on commit c8796ca

Please sign in to comment.