Show Swagger Option only if it exists
MODIFY
src/app/app-routing.module.ts
src/app/app-routing.module.ts
@@ -12,7 +12,7 @@ import {SwaggerComponent} from './components/swagger/swagger.component';
const routes: Routes = [
{path: '', component: DeveloperComponent, canActivate: [DevportalGuard]},
{
- path: 'swagger/developer/:developerId/organizations/:orgId/apis/:apiId/versions/:version/apiKey/:apiKey',
+ path: 'swagger/developer/:developerId/organizations/:orgId/apis/:apiId/versions/:version',
component: SwaggerComponent,
canActivate: [DevportalGuard]
},

MODIFY
src/app/components/developer/api-list/api-list.component.html
src/app/components/developer/api-list/api-list.component.html
</ng-container>
<ng-container matColumnDef="endpoint">
<th mat-header-cell *matHeaderCellDef>Endpoint</th>
- <td mat-cell *matCellDef="let element"><span class="cell-wrapper"><mat-icon class="copyButton" (click)="this.copyEndpointToClipboard(element)" matTooltip="Copy to clipboard">file_copy</mat-icon> <div class="cell-content">{{element.endpoint}}</div></span></td>
+ <td mat-cell *matCellDef="let element"><span class="cell-wrapper"><mat-icon class="button" (click)="this.copyEndpointToClipboard(element)" matTooltip="Copy to clipboard">file_copy</mat-icon> <div class="cell-content">{{element.endpoint}}</div></span></td>
</ng-container>
<ng-container matColumnDef="apikey">
<th mat-header-cell *matHeaderCellDef>API Key</th>
</ng-container>
<ng-container matColumnDef="options">
<th mat-header-cell *matHeaderCellDef>Options</th>
- <td mat-cell *matCellDef="let element"> <a [routerLink]="element.swaggerURL">Swagger</a> </td>
+ <td mat-cell *matCellDef="let element"> <mat-icon class="button" *ngIf="element.swaggerDefinitionType != null" (click)="this.openSwaggerView(element)" matTooltip="Test the API">play_arrow</mat-icon> </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="columnHeaders"></tr>

MODIFY
src/app/components/developer/api-list/api-list.component.scss
src/app/components/developer/api-list/api-list.component.scss
@@ -10,7 +10,6 @@ table {
padding-top: 4px;
}
-.copyButton {
+.button {
cursor: pointer;
- margin-right: 5px;
}

MODIFY
src/app/components/developer/api-list/api-list.component.ts
src/app/components/developer/api-list/api-list.component.ts
@@ -6,6 +6,7 @@ import {element} from 'protractor';
import {emit} from 'cluster';
import {SpinnerService} from '../../../services/spinner.service';
import {Toast, ToasterService} from 'angular2-toaster';
+import {Router} from '@angular/router';
export interface ApiListElement {
id: string;
@@ -14,6 +15,7 @@ export interface ApiListElement {
endpoint: string;
organizationName: string;
apikey: string;
+ swaggerDefinitionType: string;
swaggerURL: string;
}
@@ -31,7 +33,8 @@ export class ApiListComponent implements OnChanges {
@Input('developerId') developerId;
- constructor(private apiDataService: ApiDataService,
+ constructor(private router: Router,
+ private apiDataService: ApiDataService,
private toasterService: ToasterService,
private loadingSpinnerService: SpinnerService) {
}
@@ -102,7 +105,8 @@ export class ApiListComponent implements OnChanges {
endpoint: this.buildApiEndpoint(gateway.endpoint, contract.apiOrganizationId, contract.apiId, contract.apiVersion, clientVersion.apiKey),
organizationName: contract.apiOrganizationId,
apikey: clientVersion.apiKey,
- swaggerURL: '/swagger/developer/' + this.developerId + '/organizations/' + contract.apiOrganizationId + '/apis/' + contract.apiId + '/versions/' + contract.apiVersion + '/apiKey/' + clientVersion.apiKey
+ swaggerDefinitionType: apiVersionDetails.definitionType,
+ swaggerURL: '/swagger/developer/' + this.developerId + '/organizations/' + contract.apiOrganizationId + '/apis/' + contract.apiId + '/versions/' + contract.apiVersion
};
}
@@ -127,4 +131,14 @@ export class ApiListComponent implements OnChanges {
document.body.removeChild(el);
}
+ openSwaggerView(entry: ApiListElement) {
+ this.router.navigate([entry.swaggerURL], {
+ state: {
+ data: {
+ apikey: entry.apikey
+ }
+ }
+ });
+ }
+
}

MODIFY
src/app/components/swagger/swagger.component.ts
src/app/components/swagger/swagger.component.ts
@@ -18,7 +18,14 @@ export class SwaggerComponent implements OnInit {
const apiId = this.route.snapshot.paramMap.get('apiId');
const version = this.route.snapshot.paramMap.get('version');
- const apiKey = this.route.snapshot.paramMap.get('apiKey');
+ let apiKey = history.state.data ? history.state.data.apikey : null;
+
+ if (apiKey) {
+ // save key for reloading page
+ sessionStorage.setItem('lastSwaggerApiKey', apiKey);
+ } else {
+ apiKey = sessionStorage.getItem('lastSwaggerApiKey');
+ }
const swaggerURL = this.apimanUiRestUrl + '/developers/' + developerId + '/organizations/' + organizationId + '/apis/' + apiId + '/versions/' + version + '/definition';

GW-270: Show Swagger Option only if it exists