Skip to content
Snippets Groups Projects
Commit 0e4a3901 authored by Clayton, Brandon Scott's avatar Clayton, Brandon Scott
Browse files

check endpoint first

parent fa0e236e
No related branches found
No related tags found
1 merge request!565Check Swagger
import {HttpClient} from '@angular/common/http';
import {
Component,
ElementRef,
......@@ -11,8 +12,10 @@ import {
NshmpLibNgAlertComponent,
NshmpLibNgSpinnerComponent,
NshmpLibNgTemplateComponent,
NshmpService,
SpinnerService,
} from '@ghsc/nshmp-lib-ng/nshmp';
import {catchError} from 'rxjs';
import {Spec, SwaggerUIBundle} from 'swagger-ui-dist';
import {NavigationService} from '../navigation.service';
......@@ -37,6 +40,8 @@ export class AppComponent implements OnInit {
constructor(
public navigationService: NavigationService,
private spinnerService: SpinnerService,
private httpClient: HttpClient,
private nshmpService: NshmpService,
) {}
ngOnInit(): void {
......@@ -45,23 +50,36 @@ export class AppComponent implements OnInit {
const contextPath = location.pathname;
const url = `${location.href}/swagger`;
SwaggerUIBundle({
deepLinking: false,
defaultModelsExpandDepth: 0,
domNode: this.swagger().nativeElement,
layout: 'BaseLayout',
plugins: [
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
SwaggerUIBundle?.plugins?.DownloadUrl,
this.updateContextPath(contextPath),
],
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
presets: [SwaggerUIBundle?.presets?.apis],
tagsSorter: 'alpha',
tryItOutEnabled: true,
url,
validatorUrl: null,
});
// Check swagger endpoint first
this.httpClient
.get(url)
.pipe(
catchError((error: Error) => {
this.spinnerRef.close();
return this.nshmpService.throwError$(
new Error(`Failed to get swagger endpoint. ${error.message}`),
);
}),
)
.subscribe(() => {
SwaggerUIBundle({
deepLinking: false,
defaultModelsExpandDepth: 0,
domNode: this.swagger().nativeElement,
layout: 'BaseLayout',
plugins: [
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
SwaggerUIBundle?.plugins?.DownloadUrl,
this.updateContextPath(contextPath),
],
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
presets: [SwaggerUIBundle?.presets?.apis],
tagsSorter: 'alpha',
tryItOutEnabled: true,
url,
validatorUrl: null,
});
});
}
updateContextPath(contextPath: string) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment