Skip to content

Commit

Permalink
Merge branch 'YaphetKG-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
PWZER committed Mar 12, 2020
2 parents 0233013 + fce8223 commit a15fbca
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
28 changes: 28 additions & 0 deletions swagger_ui/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,27 @@ def on_get(self, req, resp):
self._app.add_route(self._uri('/swagger.json'), SwaggerConfigHandler(self))
self._app.add_static_route(prefix=self._uri('/'), directory='{}/'.format(self.static_dir), downloadable=True)

def _starlette_handler(self):
from starlette.responses import HTMLResponse, JSONResponse
from starlette.staticfiles import StaticFiles

async def swagger_doc_handler(request):
return HTMLResponse(content=self.doc_html, media_type='text/html')

async def swagger_editor_handler(request):
return JSONResponse(content=self.editor_html, media_type='text/html')

async def swagger_config_handler(request):
return JSONResponse(self.get_config(request.host))
self._app.router.add_route(self._uri('/apidocs',), swagger_doc_handler, ['get'], 'swagger-ui')

if self._editor:
self._app.router.add_route(self._uri('/editor'), swagger_editor_handler,['get'], 'swagger-editor')

self._app.router.add_route(self._uri('/swagger.json'), swagger_config_handler, ['get'], 'swagger-config')
self._app.router.mount(self._uri('/'), app=StaticFiles(directory='{}/'.format(self.static_dir)), name='swagger-static-files')


def _auto_match_handler(self):
try:
import tornado.web
Expand Down Expand Up @@ -282,4 +303,11 @@ def _auto_match_handler(self):
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!')
6 changes: 6 additions & 0 deletions swagger_ui/old.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ class FalconInterface(Interface):
def __init__(self, *args, **kwargs):
kwargs['app_type'] = 'falcon'
super(FalconInterface, self).__init__(*args, **kwargs)


class StarletteInterface(Interface):
def __init__(self, *args, **kwargs):
kwargs['app_type'] = 'starlette'
super(StarletteInterface, self).__init__(*args, **kwargs)

0 comments on commit a15fbca

Please sign in to comment.