def test_security_scheme2(self): self.reset_settings() swirl.describe(title='My API', description='My description') swirl.add_security_scheme("test_basic", security.HTTP("bearer", bearerFormat="JWT")) @swirl.restapi("/test") class Handler(RequestHandler): def post(self): """This is the simple description. With a second line. Long description. With a second line. Security: test_basic Request Body: user (User) -- sample user. """ pass self.get_app().add_handlers(r".*", api_routes()) response = yield self.http_client.fetch(self.get_url('/swagger/spec')) obj = json.loads(response.body.decode('utf-8')) assert obj['paths'] assert obj['paths']['/test'] assert obj['paths']['/test']['post'] assert obj['paths']['/test']['post']['security'] assert obj['paths']['/test']['post']['security'][0] assert 'test_basic' in obj['paths']['/test']['post']['security'][0] assert obj['components'] assert obj['components']['securitySchemes'] assert obj['components']['securitySchemes']['test_basic'] assert obj['components']['securitySchemes']['test_basic'][ 'type'] == 'http' assert obj['components']['securitySchemes']['test_basic'][ 'scheme'] == 'bearer' assert obj['components']['securitySchemes']['test_basic'][ 'bearerFormat'] == 'JWT'
def test_describe_1(self): self.reset_settings() swirl.describe(title='title', description='description', servers=[{ 'url': 'http://test/', 'description': 'test', 'foo': 'foo' }]) @swirl.restapi("/test") class Handler(RequestHandler): def post(self): """This is the simple description. With a second line. Long description. With a second line. Request Body: file (file:image/png) -- Required. Image file. name (string) -- Required. Name. """ pass self._app.add_handlers(r".*", api_routes()) response = yield self.http_client.fetch(self.get_url('/swagger/spec')) obj = json.loads(response.body.decode('utf-8')) assert obj.get("openapi", None) == "3.0.0" assert obj["info"] assert obj["info"]["title"] assert obj["info"]["title"] == "title" assert obj["info"]["description"] assert obj["info"]["description"] == "description" assert obj["servers"] assert len(obj["servers"]) == 1 assert obj["servers"][0] assert obj["servers"][0]["url"] assert obj["servers"][0]["url"] == "http://test/" assert obj["servers"][0].get("foo") is None
def test_enabled_methods(self): self.reset_settings() swirl.describe(title='My API', description='My description', enabled_methods=['head']) @swirl.restapi("/test") class Handler(RequestHandler): def head(self): """This is a head method. Test Head only method Response: out (string) -- Hello World string """ pass def post(self): """This is the simple description. With a second line. Long description. With a second line. [DEPRECATED] Request Body: user (User) -- sample user. """ pass self.get_app().add_handlers(r".*", api_routes()) response = yield self.http_client.fetch(self.get_url('/swagger/spec')) obj = json.loads(response.body.decode('utf-8')) assert obj['paths'] assert obj['paths']['/test'] assert obj['paths']['/test']['head'] assert obj['paths']['/test'].get('post') == None
import tornado.ioloop import tornado.web from tornado.gen import coroutine from tornado_swirl import api_routes from tornado_swirl.swagger import Application, describe, restapi, schema, add_global_tag, add_security_scheme from tornado_swirl.openapi import security describe(title='Test API', description='Just things to test', swagger_ui_handlers_headers=[('Cache-Control', 'public'), ('Cache-Control', 'max-age=300')]) add_global_tag("internal", "Internal Use Only", "http://foo.com/tags") add_security_scheme("test_api_key", security.HTTP('bearer', 'JWT')) add_security_scheme("api_key", security.APIKey('X-API-KEY')) # @restapi(url="/test") # class MainHandler(tornado.web.RequestHandler): # """Foo""" # async def get(self): # """Test summary # Test description # Query Params: # param1 (integer) -- required. test # minimum: 1 maximum: 200 exclusiveMaximum: true # Response: # x (enum[a,b,c]) -- Foomanchu
import tornado.ioloop import tornado.web from tornado_swirl import api_routes from tornado_swirl.swagger import Application, describe, restapi, schema, add_global_tag describe(title='Test API', description='Just things to test') add_global_tag("internal", "Internal Use Only", "http://foo.com/tags") # @restapi(url="/test") # class MainHandler(tornado.web.RequestHandler): # """Foo""" # async def get(self): # """Test summary # Test description # Query Params: # param1 (integer) -- required. test # minimum: 1 maximum: 200 exclusiveMaximum: true # Response: # x (enum[a,b,c]) -- Foomanchu # """ # self.finish() # @restapi("/test/(?P<emp_uid>\d+)/(?P<date>[\w-]+)") # class TestHandler(tornado.web.RequestHandler): # """Mother ship"""
import tornado.ioloop import tornado.web from urls import urlpatterns from db.db import Database from config.config import Settings from tornado_swirl.swagger import Application, describe from tornado_swirl import api_routes from tornado.options import define, options settings = Settings() describe(title='UMS API', description='Manages User Operations') define('mongo_host', default='127.0.0.1:') class MyApplication(object): def __init__(self): self.database = Database() self.initiateApp() def initiateApp(self): app = self.make_app() app.listen(8888) def make_app(self): db = self.database.get_motor_connection() return Application(api_routes(), db=db, cookie_secret=settings.CookieSecret, debug=settings.Debug, key_version=settings.KeyVersion,