File tree Expand file tree Collapse file tree 4 files changed +38
-6
lines changed
Expand file tree Collapse file tree 4 files changed +38
-6
lines changed Original file line number Diff line number Diff line change 1+ Disable browser cache.
2+
3+ ## Markdown
4+
5+ ``` html
6+ <swagger-ui nocache src =" ./openapi-spec/sample.yaml" />
7+ <swagger-ui nocache src =" https://petstore.swagger.io/v2/swagger.json" />
8+ ```
9+
10+ ## Swagger UI
11+
12+ <swagger-ui nocache src =" ./openapi-spec/sample.yaml " />
13+ <swagger-ui nocache src =" https://petstore.swagger.io/v2/swagger.json " />
Original file line number Diff line number Diff line change @@ -177,6 +177,7 @@ def render_template(openapi_spec_url, swagger_ui_ele):
177177 css_dir = css_dir ,
178178 extra_css_files = extra_css_files ,
179179 js_dir = js_dir ,
180+ nocache = swagger_ui_ele .has_attr ("nocache" ),
180181 background = self .config ["background" ],
181182 id = "{{ID_PLACEHOLDER}}" , # ID is unknown yet - it's the hash of the content.
182183 openapi_spec_url = openapi_spec_url ,
Original file line number Diff line number Diff line change 1717 < script src ="{{ js_dir }}swagger-ui-standalone-preset.js " charset ="UTF-8 "> </ script >
1818 < script >
1919 window . onload = function ( ) {
20+ { % if openapi_spec_url is string % }
21+ var url = "{{openapi_spec_url}}" ;
22+ { % if nocache % }
23+ url += ( url . includes ( '?' ) ? '&' : '?' ) + "nocache=" + new Date ( ) . getTime ( ) ;
24+ { % endif % }
25+ { % elif openapi_spec_url is sequence % }
26+ var urls = [
27+ { % for item in openapi_spec_url % }
28+ { url :"{{item.url}}" , name :"{{item.name}}" } ,
29+ { % endfor % }
30+ ] ;
31+ { % if nocache % }
32+ urls = urls . map ( function ( item ) {
33+ var url = item . url ;
34+ url += ( url . includes ( '?' ) ? '&' : '?' ) + "nocache=" + new Date ( ) . getTime ( ) ;
35+ return { url : url , name : item . name } ;
36+ } ) ;
37+ { % endif % }
38+ { % endif % }
2039 window . ui = SwaggerUIBundle ( {
2140 dom_id : "#swagger-ui" ,
2241 onComplete : onComplete ,
2544 SwaggerUIStandalonePreset
2645 ] ,
2746 { % if openapi_spec_url is string % }
28- url : "{{openapi_spec_url}}" ,
47+ url ,
2948 { % elif openapi_spec_url is sequence % }
30- urls : [
31- { % for item in openapi_spec_url % }
32- { url :"{{item.url}}" , name :"{{item.name}}" } ,
33- { % endfor % }
34- ] ,
49+ urls ,
3550 layout : "StandaloneLayout" ,
3651 { % endif % }
3752 { % if oauth2_redirect_url . startswith ( '.' ) % }
Original file line number Diff line number Diff line change 1+ <swagger-ui nocache src =" ./openapi-spec/sample.yaml " />
2+ <swagger-ui nocache src =" ./openapi-spec/sample-oauth2.yaml?doudou=dada " />
3+ <swagger-ui nocache src =" https://petstore.swagger.io/v2/swagger.json " />
You can’t perform that action at this time.
0 commit comments