chore: remove head request for api definitions to improve page loading performance
MODIFY
src/app/components/api-card-list/api-card-list.component.ts
src/app/components/api-card-list/api-card-list.component.ts
@@ -187,20 +187,17 @@ export class ApiCardListComponent implements OnInit {
return this.apiService
.getLatestApiVersion(apiSummary.organizationId, apiSummary.id)
.pipe(
- switchMap((latestApiVersion) => {
- return this.apiService.isApiDocAvailable(latestApiVersion).pipe(
- map((docsAvailable) => {
+ map((latestApiVersion) => {
return {
...apiSummary,
latestApiVersion: latestApiVersion,
- docsAvailable: docsAvailable
+ docsAvailable:
+ this.apiService.isApiDocAvailable(latestApiVersion)
} as IApiSummaryExt;
})
);
})
);
- })
- );
} else {
return of([]) as Observable<IApiSummaryExt[]>;
}

MODIFY
src/app/components/marketplace-api-details/marketplace-api-details.component.ts
src/app/components/marketplace-api-details/marketplace-api-details.component.ts
@@ -18,9 +18,12 @@ import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ApiService } from '../../services/api/api.service';
import { HeroService } from '../../services/hero/hero.service';
-import { map, switchMap } from 'rxjs/operators';
-import { forkJoin } from 'rxjs';
-import { IApiVersion } from '../../interfaces/ICommunication';
+import { switchMap } from 'rxjs/operators';
+import { forkJoin, Observable, of } from 'rxjs';
+import {
+ IApiVersion,
+ IApiVersionSummary
+} from '../../interfaces/ICommunication';
import { SpinnerService } from '../../services/spinner/spinner.service';
import { IApiVersionExt } from '../../interfaces/IApiVersionExt';
@@ -58,9 +61,9 @@ export class MarketplaceApiDetailsComponent implements OnInit {
this.apiService
.getApiVersionSummaries(orgId, apiId)
.pipe(
- switchMap((apiVersionSummaries) => {
+ switchMap((apiVersionSummaries: IApiVersionSummary[]) => {
return forkJoin(
- apiVersionSummaries.map((apiVersionSummary) => {
+ apiVersionSummaries.map((apiVersionSummary: IApiVersionSummary) => {
return this.apiService.getApiVersion(
apiVersionSummary.organizationId,
apiVersionSummary.id,
@@ -71,20 +74,16 @@ export class MarketplaceApiDetailsComponent implements OnInit {
}),
switchMap((apiVersions: IApiVersion[]) => {
return forkJoin(
- apiVersions.map((apiVersion) => {
- return this.apiService.isApiDocAvailable(apiVersion).pipe(
- map((docsAvailable) => {
- return {
+ apiVersions.map((apiVersion: IApiVersion) => {
+ return of({
...apiVersion,
- docsAvailable: docsAvailable
- } as IApiVersionExt;
- })
- );
+ docsAvailable: this.apiService.isApiDocAvailable(apiVersion)
+ }) as Observable<IApiVersionExt>;
})
);
})
)
- .subscribe((apiVersions) => {
+ .subscribe((apiVersions: IApiVersionExt[]) => {
this.spinnerService.stopWaiting();
this.apis = apiVersions;
this.setUpHero();

MODIFY
src/app/components/my-apps/my-apps.component.ts
src/app/components/my-apps/my-apps.component.ts
@@ -158,10 +158,9 @@ export class MyAppsComponent implements OnInit {
orgId,
contract.api.api.id,
contract.api.version
- ),
- this.apiService.isApiDocAvailable(contract.api)
+ )
]).pipe(
- map(([planPolicies, endpoint, docsAvailable]) => {
+ map(([planPolicies, endpoint]) => {
planPolicies.forEach((planPolicy) => {
this.policyService.initPolicy(planPolicy);
});
@@ -171,7 +170,9 @@ export class MyAppsComponent implements OnInit {
policies: planPolicies,
section: 'summary',
managedEndpoint: endpoint.managedEndpoint,
- docsAvailable: docsAvailable,
+ docsAvailable: this.apiService.isApiDocAvailable(
+ contract.api
+ ),
deletable: this.isDeleteAllowed(contract)
} as IContractExt;
})

MODIFY
src/app/services/api/api.service.ts
src/app/services/api/api.service.ts
import { Injectable } from '@angular/core';
import { BackendService } from '../backend/backend.service';
-import { Observable, of, throwError } from 'rxjs';
-import { catchError, map, retry, switchMap } from 'rxjs/operators';
+import { Observable, throwError } from 'rxjs';
+import { catchError, retry, switchMap } from 'rxjs/operators';
import {
IApiSummary,
IApiVersion,
@@ -82,18 +82,10 @@ export class ApiService {
);
}
- isApiDocAvailable(apiSummary: IApiVersion): Observable<boolean> {
- return this.backendService
- .headApiDefinition(
- apiSummary.api.organization.id,
- apiSummary.api.id,
- apiSummary.version
- )
- .pipe(
- map(() => {
- return true;
- }),
- catchError(() => of(false))
+ isApiDocAvailable(apiVersion: IApiVersion): boolean {
+ return (
+ apiVersion.definitionType === 'SwaggerYAML' ||
+ apiVersion.definitionType === 'SwaggerJSON'
);
}

MODIFY
src/app/services/backend/backend.service.ts
src/app/services/backend/backend.service.ts
@@ -292,18 +292,6 @@ export class BackendService {
return this.http.get<IPolicy>(this.generateUrl(path), this.httpOptions);
}
- public headApiDefinition(
- organizationId: string,
- apiId: string,
- apiVersion: string
- ): Observable<never> {
- const path = `devportal/organizations/${organizationId}/apis/${apiId}/versions/${apiVersion}/definition`;
- return this.http.head(
- this.generateUrl(path),
- this.httpOptions
- ) as Observable<never>;
- }
-
public getApiDefinition(
organizationId: string,
apiId: string,

chore: remove head request for api definitions to improve page loading performance