@@ -136,7 +136,7 @@ def validate_iframe(html_content, iframe_src_dir):
136136 iframe_src = iframe_tag .attrs .get ("src" )
137137 assert iframe_id is not None
138138 assert iframe_src is not None
139- assert f"swagger-{ iframe_id } .html" == iframe_src
139+ assert f"swagger-{ iframe_id } .html" in iframe_src
140140 iframe_file = iframe_src_dir / iframe_src
141141 assert iframe_file .exists ()
142142 iframe_content = iframe_file .read_text (encoding = "utf8" )
@@ -199,7 +199,7 @@ def test_basic(tmp_path):
199199
200200 # validate OpenAPI spec exist
201201 regex_obj = re .search (
202- r'url: "(.*)"' ,
202+ r'var url = "(.*)"' ,
203203 iframe_contents ,
204204 )
205205 assert regex_obj
@@ -224,7 +224,7 @@ def test_basic_sub_dir(tmp_path):
224224
225225 # validate OpenAPI spec exists
226226 regex_obj = re .search (
227- r'url: "(.*)"' ,
227+ r'var url = "(.*)"' ,
228228 iframe_contents ,
229229 )
230230 assert regex_obj
@@ -251,7 +251,7 @@ def test_use_directory_urls(tmp_path):
251251
252252 # validate OpenAPI spec exist
253253 regex_obj = re .search (
254- r'url: "(.*)"' ,
254+ r'var url = "(.*)"' ,
255255 iframe_contents ,
256256 )
257257 assert regex_obj
@@ -278,7 +278,7 @@ def test_use_directory_urls_sub_dir(tmp_path):
278278
279279 # validate OpenAPI spec exist
280280 regex_obj = re .search (
281- r'url: "(.*)"' ,
281+ r'var url = "(.*)"' ,
282282 iframe_contents ,
283283 )
284284 assert regex_obj
@@ -305,7 +305,7 @@ def test_material(tmp_path):
305305
306306 # validate OpenAPI spec exist
307307 regex_obj = re .search (
308- r'url: "(.*)"' ,
308+ r'var url = "(.*)"' ,
309309 iframe_contents ,
310310 )
311311 assert regex_obj
@@ -340,7 +340,7 @@ def test_url(tmp_path):
340340
341341 # validate OpenAPI spec exist
342342 regex_obj = re .search (
343- r'url: "(.*)"' ,
343+ r'var url = "(.*)"' ,
344344 iframe_contents ,
345345 )
346346 assert regex_obj
@@ -361,7 +361,7 @@ def test_multiple(tmp_path):
361361 for ind , iframe_contents in enumerate (iframe_content_list ):
362362 # validate OpenAPI spec exist
363363 regex_obj = re .search (
364- r'url: "(.*)"' ,
364+ r'var url = "(.*)"' ,
365365 iframe_contents ,
366366 )
367367 assert regex_obj
@@ -372,6 +372,35 @@ def test_multiple(tmp_path):
372372 assert regex_obj .group (1 ) == "https://petstore.swagger.io/v2/swagger.json"
373373
374374
375+ def test_nocache (tmp_path ):
376+ """
377+ Validate nocache url in multiple Swagger UI in the same page
378+ """
379+ mkdocs_file = "mkdocs.yml"
380+ testproject_path = validate_mkdocs_file (tmp_path , f"tests/fixtures/{ mkdocs_file } " )
381+ file = testproject_path / "site/nocache/index.html"
382+ contents = file .read_text (encoding = "utf8" )
383+
384+ iframe_content_list = validate_iframe (contents , file .parent )
385+ assert len (iframe_content_list ) == 3
386+ for ind , iframe_contents in enumerate (iframe_content_list ):
387+ # validate nocache detected
388+ assert "nocache=" in iframe_contents
389+ # validate OpenAPI spec exist
390+ regex_obj = re .search (
391+ r'var url = "(.*)"' ,
392+ iframe_contents ,
393+ )
394+ assert regex_obj
395+ openapi_spec_url = regex_obj .group (1 )
396+ if ind == 0 :
397+ assert "./openapi-spec/sample.yaml" in openapi_spec_url
398+ elif ind == 1 :
399+ assert "./openapi-spec/sample.yaml?doudou=doudou" in openapi_spec_url
400+ elif ind == 2 :
401+ assert "https://petstore.swagger.io/v2/swagger.json" in openapi_spec_url
402+
403+
375404def test_build_in_multiple (tmp_path ):
376405 """
377406 Validate Swagger UI build-in multiple feature
@@ -396,7 +425,7 @@ def test_build_in_multiple(tmp_path):
396425 assert (file .parent / spec_url ).resolve ().exists ()
397426 elif ind == 1 :
398427 regex_obj = re .search (
399- r'url: "(.*)"' ,
428+ r'var url = "(.*)"' ,
400429 iframe_contents ,
401430 )
402431 assert regex_obj
0 commit comments