Skip to content
This repository was archived by the owner on Jun 18, 2023. It is now read-only.

Commit c95e14a

Browse files
timonbackstavshamir
authored andcommitted
feat: Add download link for async api doc
1 parent c668233 commit c95e14a

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/app/info/info.component.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
<h1>{{ info?.title }}</h1>
2-
<h5>API VERSION {{ info?.version }}</h5>
3-
<p *ngIf="info?.description">{{ info.description }}</p>
2+
<h5>
3+
API VERSION {{ info?.version }}
4+
-
5+
<a href="#" (click)="download()">AsyncAPI JSON file</a>
6+
</h5>
7+
<p *ngIf="info?.description">{{ info.description }}</p>

src/app/info/info.component.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Component, OnInit } from '@angular/core';
2+
import { AsyncApi } from '../shared/models/asyncapi.model';
23
import { Info } from '../shared/models/info.model';
34
import { AsyncApiService } from '../shared/asyncapi.service';
45
import { Subscription } from 'rxjs';
@@ -10,15 +11,29 @@ import { Subscription } from 'rxjs';
1011
})
1112
export class InfoComponent implements OnInit {
1213

14+
asyncApiData: AsyncApi;
1315
info: Info;
1416
nameSubscription: Subscription;
1517

1618
constructor(private asyncApiService: AsyncApiService) { }
1719

1820
ngOnInit(): void {
1921
this.nameSubscription = this.asyncApiService.getCurrentAsyncApiName().subscribe(name => {
20-
this.asyncApiService.getAsyncApis().subscribe(asyncapi => this.info = asyncapi.get(name).info);
22+
this.asyncApiService.getAsyncApis().subscribe(asyncapi => {
23+
this.asyncApiData = asyncapi.get(name);
24+
this.info = asyncapi.get(name).info;
25+
});
2126
});
2227
}
2328

29+
async download(): Promise<Boolean> {
30+
var json = JSON.stringify(this.asyncApiData, null, 2);
31+
var bytes = new TextEncoder().encode(json);
32+
var blob = new Blob([bytes], { type: 'application/json' });
33+
var url = window.URL.createObjectURL(blob);
34+
window.open(url);
35+
36+
return false;
37+
}
38+
2439
}

0 commit comments

Comments
 (0)