1
1
'use strict' ;
2
2
import { Component , ChangeDetectionStrategy , OnInit , ElementRef } from '@angular/core' ;
3
+ import { DomSanitizer , SafeResourceUrl } from '@angular/platform-browser' ;
3
4
import { SpecManager , BaseComponent } from '../base' ;
4
5
import { OptionsService , Marker } from '../../services/index' ;
5
6
@@ -11,11 +12,13 @@ import { OptionsService, Marker } from '../../services/index';
11
12
} )
12
13
export class ApiInfo extends BaseComponent implements OnInit {
13
14
info : any = { } ;
14
- specUrl : String ;
15
+ specUrl : String | SafeResourceUrl ;
16
+ downloadFilename = '' ;
15
17
constructor ( specMgr : SpecManager ,
16
18
private optionsService : OptionsService ,
17
19
elRef : ElementRef ,
18
- marker : Marker
20
+ marker : Marker ,
21
+ private sanitizer : DomSanitizer
19
22
) {
20
23
super ( specMgr ) ;
21
24
marker . addElement ( elRef . nativeElement ) ;
@@ -24,6 +27,12 @@ export class ApiInfo extends BaseComponent implements OnInit {
24
27
init ( ) {
25
28
this . info = this . componentSchema . info ;
26
29
this . specUrl = this . specMgr . specUrl ;
30
+ if ( ! this . specUrl && window . Blob && window . URL ) {
31
+ const blob = new Blob ( [ JSON . stringify ( this . specMgr . rawSpec , null , 2 ) ] , { type : 'application/json' } ) ;
32
+ this . specUrl = this . sanitizer . bypassSecurityTrustResourceUrl ( window . URL . createObjectURL ( blob ) ) ;
33
+ this . downloadFilename = 'swagger.json' ;
34
+ }
35
+
27
36
if ( ! isNaN ( parseInt ( this . info . version . toString ( ) . substring ( 0 , 1 ) ) ) ) {
28
37
this . info . version = 'v' + this . info . version ;
29
38
}
0 commit comments