11'use strict' ;
22import { Component , ChangeDetectionStrategy , OnInit , ElementRef } from '@angular/core' ;
3+ import { DomSanitizer , SafeResourceUrl } from '@angular/platform-browser' ;
34import { SpecManager , BaseComponent } from '../base' ;
45import { OptionsService , Marker } from '../../services/index' ;
56
@@ -11,11 +12,13 @@ import { OptionsService, Marker } from '../../services/index';
1112} )
1213export class ApiInfo extends BaseComponent implements OnInit {
1314 info : any = { } ;
14- specUrl : String ;
15+ specUrl : String | SafeResourceUrl ;
16+ downloadFilename = '' ;
1517 constructor ( specMgr : SpecManager ,
1618 private optionsService : OptionsService ,
1719 elRef : ElementRef ,
18- marker : Marker
20+ marker : Marker ,
21+ private sanitizer : DomSanitizer
1922 ) {
2023 super ( specMgr ) ;
2124 marker . addElement ( elRef . nativeElement ) ;
@@ -24,6 +27,12 @@ export class ApiInfo extends BaseComponent implements OnInit {
2427 init ( ) {
2528 this . info = this . componentSchema . info ;
2629 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+
2736 if ( ! isNaN ( parseInt ( this . info . version . toString ( ) . substring ( 0 , 1 ) ) ) ) {
2837 this . info . version = 'v' + this . info . version ;
2938 }
0 commit comments