Skip to content

Commit dc62b46

Browse files
committed
add specification
1 parent 6a2b04e commit dc62b46

File tree

6 files changed

+75
-0
lines changed

6 files changed

+75
-0
lines changed

projects/fusio-sdk/src/lib/component/specification/specification.component.css

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
<div class="row">
3+
<div class="col-md-12">
4+
<div id="redoc"></div>
5+
</div>
6+
</div>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import {Component, OnInit} from '@angular/core';
2+
import {FusioService} from "../../service/fusio.service";
3+
4+
@Component({
5+
selector: 'fusio-specification',
6+
templateUrl: './specification.component.html',
7+
styleUrls: ['./specification.component.css']
8+
})
9+
export class SpecificationComponent implements OnInit {
10+
11+
constructor(private fusio: FusioService) { }
12+
13+
async ngOnInit(): Promise<void> {
14+
this.loadRedoc(await this.getOpenAPILink());
15+
}
16+
17+
private async getOpenAPILink(): Promise<string|undefined> {
18+
const about = await this.fusio.getClientAnonymous().system().meta().getAbout();
19+
20+
let result = undefined;
21+
about.links?.forEach((link) => {
22+
if (link.rel === 'openapi') {
23+
result = link.href;
24+
}
25+
});
26+
27+
return result;
28+
}
29+
30+
private loadRedoc(url: string|undefined): void {
31+
if (!url) {
32+
throw new Error('Found no open api url');
33+
}
34+
35+
const el = document.getElementById('redoc-script');
36+
if (el === null) {
37+
let node = document.createElement('script');
38+
node.src = 'https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js';
39+
node.type = 'text/javascript';
40+
node.async = true;
41+
node.id = 'redoc-script';
42+
node.onload = function() {
43+
SpecificationComponent.initRedoc(url);
44+
};
45+
document.getElementsByTagName('head')[0].appendChild(node);
46+
} else {
47+
SpecificationComponent.initRedoc(url);
48+
}
49+
}
50+
51+
public static initRedoc(url: string) {
52+
const options = {
53+
scrollYOffset: 60,
54+
hideDownloadButton: true
55+
};
56+
57+
Redoc.init(url, options, document.getElementById('redoc'))
58+
}
59+
60+
}
61+
62+
declare var Redoc: any;

projects/fusio-sdk/src/lib/fusio-sdk.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {ActivateComponent} from "./component/register/activate/activate.componen
2525
import {AboutComponent} from "./component/about/about.component";
2626
import {AccountComponent} from './component/account/account.component';
2727
import {SecurityComponent} from './component/security/security.component';
28+
import {SpecificationComponent} from "./component/specification/specification.component";
2829
import {AppDetailComponent} from './component/app/detail/app-detail.component';
2930
import {AppListComponent} from './component/app/list/app-list.component';
3031
import {AppModalComponent} from './component/app/modal/app-modal.component';
@@ -44,6 +45,7 @@ import {WebhookModalComponent} from "./component/webhook/modal/webhook-modal.com
4445
@NgModule({
4546
declarations: [
4647
AboutComponent,
48+
SpecificationComponent,
4749
AccountComponent,
4850
AccountContainerComponent,
4951
BootstrapComponent,

projects/fusio-sdk/src/lib/route/account-route.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {SubscriptionComponent} from "../component/subscription/subscription.comp
66
import {CallbackComponent} from "../component/subscription/callback/callback.component";
77
import {WebhookListComponent} from "../component/webhook/list/webhook-list.component";
88
import {TokenListComponent} from "../component/token/list/token-list.component";
9+
import {SpecificationComponent} from "../component/specification/specification.component";
910
import {AboutComponent} from "../component/about/about.component";
1011
import {isAuthenticated} from "../guard/authentication.guard";
1112

@@ -23,6 +24,7 @@ export class AccountRoute {
2324
{path: 'webhook/:id', component: WebhookListComponent, canActivate: [isAuthenticated] },
2425
{path: 'token', component: TokenListComponent, canActivate: [isAuthenticated] },
2526
{path: 'token/:id', component: TokenListComponent, canActivate: [isAuthenticated] },
27+
{path: 'specification', component: SpecificationComponent, canActivate: [isAuthenticated] },
2628
{path: 'about', component: AboutComponent, canActivate: [isAuthenticated] },
2729
];
2830
}

projects/fusio-sdk/src/lib/service/config.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ export class ConfigService {
9898
title: 'Token',
9999
path: '/account/token',
100100
scope: 'consumer.token',
101+
}, {
102+
title: 'Specification',
103+
path: '/account/specification',
101104
}, {
102105
title: 'About',
103106
path: '/account/about',

0 commit comments

Comments
 (0)