@@ -300,83 +300,6 @@ func TestUIConfigOptions(t *testing.T) {
300
300
exp string
301
301
}
302
302
303
- hdr := `
304
- <!DOCTYPE html>
305
- <html lang="en">
306
- <head>
307
- <meta charset="UTF-8">
308
- <title>Swagger UI</title>
309
- <link rel="stylesheet" type="text/css" href="./swagger-ui.css" >
310
- <link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
311
- <link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
312
- <style>
313
- html
314
- {
315
- box-sizing: border-box;
316
- overflow: -moz-scrollbars-vertical;
317
- overflow-y: scroll;
318
- }
319
- *,
320
- *:before,
321
- *:after
322
- {
323
- box-sizing: inherit;
324
- }
325
-
326
- body {
327
- margin:0;
328
- background: #fafafa;
329
- }
330
- </style>
331
- </head>
332
-
333
- <body>
334
-
335
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="position:absolute;width:0;height:0">
336
- <defs>
337
- <symbol viewBox="0 0 20 20" id="unlocked">
338
- <path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path>
339
- </symbol>
340
-
341
- <symbol viewBox="0 0 20 20" id="locked">
342
- <path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z"/>
343
- </symbol>
344
-
345
- <symbol viewBox="0 0 20 20" id="close">
346
- <path d="M14.348 14.849c-.469.469-1.229.469-1.697 0L10 11.819l-2.651 3.029c-.469.469-1.229.469-1.697 0-.469-.469-.469-1.229 0-1.697l2.758-3.15-2.759-3.152c-.469-.469-.469-1.228 0-1.697.469-.469 1.228-.469 1.697 0L10 8.183l2.651-3.031c.469-.469 1.228-.469 1.697 0 .469.469.469 1.229 0 1.697l-2.758 3.152 2.758 3.15c.469.469.469 1.229 0 1.698z"/>
347
- </symbol>
348
-
349
- <symbol viewBox="0 0 20 20" id="large-arrow">
350
- <path d="M13.25 10L6.109 2.58c-.268-.27-.268-.707 0-.979.268-.27.701-.27.969 0l7.83 7.908c.268.271.268.709 0 .979l-7.83 7.908c-.268.271-.701.27-.969 0-.268-.269-.268-.707 0-.979L13.25 10z"/>
351
- </symbol>
352
-
353
- <symbol viewBox="0 0 20 20" id="large-arrow-down">
354
- <path d="M17.418 6.109c.272-.268.709-.268.979 0s.271.701 0 .969l-7.908 7.83c-.27.268-.707.268-.979 0l-7.908-7.83c-.27-.268-.27-.701 0-.969.271-.268.709-.268.979 0L10 13.25l7.418-7.141z"/>
355
- </symbol>
356
-
357
- <symbol viewBox="0 0 24 24" id="jump-to">
358
- <path d="M19 7v4H5.83l3.58-3.59L8 6l-6 6 6 6 1.41-1.41L5.83 13H21V7z"/>
359
- </symbol>
360
-
361
- <symbol viewBox="0 0 24 24" id="expand">
362
- <path d="M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z"/>
363
- </symbol>
364
- </defs>
365
- </svg>
366
-
367
- <div id="swagger-ui"></div>
368
-
369
- <script src="./swagger-ui-bundle.js"> </script>
370
- <script src="./swagger-ui-standalone-preset.js"> </script>
371
- <script>
372
- `
373
- ftr := `
374
- </script>
375
- </body>
376
-
377
- </html>
378
- `
379
-
380
303
fixtures := []fixture {
381
304
{
382
305
desc : "default configuration" ,
@@ -389,14 +312,15 @@ func TestUIConfigOptions(t *testing.T) {
389
312
Layout : StandaloneLayout ,
390
313
DefaultModelsExpandDepth : ShowModel ,
391
314
},
392
- exp : `window.onload = function() {
393
-
315
+ exp : `
316
+ window.onload = function() {
317
+ // Build a system
394
318
const ui = SwaggerUIBundle({
395
319
url: "doc.json",
396
- deepLinking: true ,
320
+ deepLinking: true,
397
321
docExpansion: "list",
398
322
dom_id: "#swagger-ui",
399
- persistAuthorization: false ,
323
+ persistAuthorization: false,
400
324
validatorUrl: null,
401
325
presets: [
402
326
SwaggerUIBundle.presets.apis,
@@ -406,11 +330,13 @@ func TestUIConfigOptions(t *testing.T) {
406
330
SwaggerUIBundle.plugins.DownloadUrl
407
331
],
408
332
layout: "StandaloneLayout",
409
- defaultModelsExpandDepth: 1
333
+ defaultModelsExpandDepth: 1,
334
+ showExtensions: false
410
335
})
411
336
412
337
window.ui = ui
413
- }` ,
338
+ }
339
+ ` ,
414
340
},
415
341
{
416
342
desc : "script configuration" ,
@@ -440,18 +366,19 @@ func TestUIConfigOptions(t *testing.T) {
440
366
},
441
367
DefaultModelsExpandDepth : HideModel ,
442
368
},
443
- exp : `window.onload = function() {
444
- const SomePlugin = (system) => ({
369
+ exp : `
370
+ window.onload = function() {
371
+ const SomePlugin = (system) => ({
445
372
// Some plugin
446
373
});
447
374
448
-
375
+ // Build a system
449
376
const ui = SwaggerUIBundle({
450
377
url: "swagger.json",
451
- deepLinking: false ,
378
+ deepLinking: false,
452
379
docExpansion: "none",
453
380
dom_id: "#swagger-ui-id",
454
- persistAuthorization: true ,
381
+ persistAuthorization: true,
455
382
validatorUrl: null,
456
383
presets: [
457
384
SwaggerUIBundle.presets.apis,
@@ -462,36 +389,38 @@ func TestUIConfigOptions(t *testing.T) {
462
389
SomePlugin,
463
390
AnotherPlugin
464
391
],
465
- defaultModelRendering: " model" ,
466
- onComplete: () => { window.ui.setBasePath('v3' ); },
392
+ defaultModelRendering: " model" ,
393
+ onComplete: () => { window.ui.setBasePath('v3' ); },
467
394
showExtensions: true,
468
395
layout: "StandaloneLayout",
469
- defaultModelsExpandDepth: -1
396
+ defaultModelsExpandDepth: -1,
397
+ showExtensions: false
470
398
})
471
399
472
400
window.ui = ui
473
401
const someOtherCode = function(){
474
402
// Do something
475
403
};
476
404
someOtherCode();
477
- }` ,
405
+ }
406
+ ` ,
478
407
},
479
408
}
480
409
481
410
for _ , fix := range fixtures {
482
411
t .Run (fix .desc , func (t * testing.T ) {
483
- tmpl := template .New ("swagger_index.html " )
484
- index , err := tmpl .Parse (indexTempl )
412
+ tmpl := template .New ("swagger_index.js " )
413
+ indexJs , err := tmpl .Parse (indexJsTempl )
485
414
if err != nil {
486
415
t .Fatal (err )
487
416
}
488
417
489
418
buf := bytes .NewBuffer (nil )
490
- if err := index .Execute (buf , fix .cfg ); err != nil {
419
+ if err := indexJs .Execute (buf , fix .cfg ); err != nil {
491
420
t .Fatal (err )
492
421
}
493
422
494
- exp := hdr + fix .exp + ftr
423
+ exp := fix .exp
495
424
496
425
// Compare line by line
497
426
explns := strings .Split (exp , "\n " )
@@ -559,3 +488,16 @@ func TestDefaultModelsExpandDepth(t *testing.T) {
559
488
DefaultModelsExpandDepth (ShowModel )(cfg )
560
489
assert .Equal (t , ShowModel , cfg .DefaultModelsExpandDepth )
561
490
}
491
+
492
+ func TestShowExtensions (t * testing.T ) {
493
+ var cfg * Config
494
+
495
+ cfg = newConfig ()
496
+ assert .False (t , cfg .ShowExtensions )
497
+
498
+ cfg = newConfig (ShowExtensions (true ))
499
+ assert .True (t , cfg .ShowExtensions )
500
+
501
+ cfg = newConfig (ShowExtensions (false ))
502
+ assert .False (t , cfg .ShowExtensions )
503
+ }
0 commit comments