11import asyncio
22import json
3+ import pathlib
34import pytest
45import yaml
56from os .path import join , dirname , abspath
@@ -50,7 +51,8 @@ def test_swagger_file_url(test_client, loop):
5051
5152 app = web .Application (loop = loop )
5253 setup_swagger (app ,
53- swagger_from_file = TESTS_PATH + "/data/example_swagger.yaml" )
54+ swagger_from_file = TESTS_PATH + "/data/example_swagger.yaml" ,
55+ json_only = True )
5456
5557 client = yield from test_client (app )
5658 resp1 = yield from client .get ('/api/doc/swagger.json' )
@@ -66,7 +68,7 @@ def test_swagger_file_url(test_client, loop):
6668def test_partial_swagger_file (test_client , loop ):
6769 app = web .Application (loop = loop )
6870 app .router .add_route ('GET' , "/ping-partial" , ping_partial )
69- setup_swagger (app )
71+ setup_swagger (app , json_only = True )
7072
7173 client = yield from test_client (app )
7274 resp1 = yield from client .get ('/api/doc/swagger.json' )
@@ -86,7 +88,8 @@ def test_custom_swagger(test_client, loop):
8688 description = description ,
8789 title = "Test Custom Title" ,
8890 api_version = "1.0.0" ,
89- contact = "my.custom.contact@example.com" )
91+ contact = "my.custom.contact@example.com" ,
92+ json_only = True )
9093
9194 client = yield from test_client (app )
9295 resp1 = yield from client .get ('/api/v1/doc/swagger.json' )
@@ -108,7 +111,8 @@ def test_swagger_home_decorator(test_client, loop):
108111 title = "Test Custom Title" ,
109112 api_version = "1.0.0" ,
110113 contact = "my.custom.contact@example.com" ,
111- swagger_home_decor = lambda x : x )
114+ swagger_home_decor = lambda x : x ,
115+ json_only = True )
112116
113117 client = yield from test_client (app )
114118 resp1 = yield from client .get ('/api/v1/doc/swagger.json' )
@@ -130,7 +134,8 @@ def test_swagger_def_decorator(test_client, loop):
130134 title = "Test Custom Title" ,
131135 api_version = "1.0.0" ,
132136 contact = "my.custom.contact@example.com" ,
133- swagger_def_decor = lambda x : x )
137+ swagger_def_decor = lambda x : x ,
138+ json_only = True )
134139
135140 client = yield from test_client (app )
136141 resp1 = yield from client .get ('/api/v1/doc/swagger.json' )
@@ -154,7 +159,8 @@ def test_swagger_info(test_client, loop, swagger_info):
154159 description = "Test Custom Swagger"
155160 setup_swagger (app ,
156161 swagger_url = "/api/v1/doc" ,
157- swagger_info = swagger_info )
162+ swagger_info = swagger_info ,
163+ json_only = True )
158164
159165 client = yield from test_client (app )
160166 resp1 = yield from client .get ('/api/v1/doc/swagger.json' )
@@ -164,3 +170,22 @@ def test_swagger_info(test_client, loop, swagger_info):
164170 assert '/example1' in result ['paths' ]
165171 assert '/example2' in result ['paths' ]
166172 assert 'API Title' in result ['info' ]['title' ]
173+
174+
175+ @asyncio .coroutine
176+ def test_swagger_defined_paths (test_client , loop ):
177+ app1 = web .Application (loop = loop )
178+ setup_swagger (app1 , json_only = True )
179+ urls1 = [r .get_info () for r in app1 .router .resources ()]
180+ assert urls1 == [{'path' : '/api/doc/swagger.json' }]
181+
182+ app2 = web .Application (loop = loop )
183+ setup_swagger (app2 )
184+ urls2 = [r .get_info () for r in app2 .router .resources ()]
185+ assert urls2 == [
186+ {'path' : '/api/doc/swagger.json' },
187+ {'path' : '/api/doc' },
188+ {'path' : '/api/doc/' },
189+ {'directory' : pathlib .Path ('aiohttp_swagger/swagger_ui' ).absolute (),
190+ 'prefix' : '/api/doc/swagger_static' },
191+ ]
0 commit comments