2015-10-08 23:21:51 +03:00
|
|
|
'use strict';
|
2016-12-25 15:24:58 +03:00
|
|
|
import { Input, HostBinding, Component, OnInit, ChangeDetectionStrategy, ElementRef } from '@angular/core';
|
2016-05-25 18:34:31 +03:00
|
|
|
import JsonPointer from '../../utils/JsonPointer';
|
2016-08-22 12:12:13 +03:00
|
|
|
import { BaseComponent, SpecManager } from '../base';
|
2016-07-01 17:24:59 +03:00
|
|
|
import { SchemaHelper } from '../../services/schema-helper.service';
|
2017-02-27 14:13:06 +03:00
|
|
|
import { OptionsService, MenuService } from '../../services/';
|
2017-04-18 16:46:19 +03:00
|
|
|
import { SwaggerBodyParameter } from '../../utils/swagger-typings';
|
2015-10-08 23:21:51 +03:00
|
|
|
|
2017-04-18 16:46:19 +03:00
|
|
|
export interface OperationInfo {
|
2017-02-26 00:38:19 +03:00
|
|
|
verb: string;
|
2016-12-25 15:24:58 +03:00
|
|
|
path: string;
|
|
|
|
info: {
|
|
|
|
tags: string[];
|
|
|
|
description: string;
|
|
|
|
};
|
|
|
|
bodyParam: any;
|
2017-03-29 11:25:30 +03:00
|
|
|
summary: string;
|
|
|
|
anchor: string;
|
|
|
|
externalDocs?: {
|
2017-02-03 00:08:04 +03:00
|
|
|
url: string;
|
|
|
|
description?: string;
|
|
|
|
}
|
2016-12-25 15:24:58 +03:00
|
|
|
}
|
|
|
|
|
2016-08-22 12:12:13 +03:00
|
|
|
@Component({
|
2017-03-30 15:17:08 +03:00
|
|
|
selector: 'operation',
|
|
|
|
templateUrl: './operation.html',
|
|
|
|
styleUrls: ['./operation.css'],
|
2016-08-30 17:07:54 +03:00
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
2015-10-08 23:21:51 +03:00
|
|
|
})
|
2017-03-30 15:17:08 +03:00
|
|
|
export class Operation extends BaseComponent implements OnInit {
|
2016-12-25 15:24:58 +03:00
|
|
|
@Input() pointer :string;
|
|
|
|
@Input() parentTagId :string;
|
2016-11-23 02:23:32 +03:00
|
|
|
|
2016-12-25 15:24:58 +03:00
|
|
|
@HostBinding('attr.operation-id') operationId;
|
2016-08-22 12:12:13 +03:00
|
|
|
|
2017-03-30 15:17:08 +03:00
|
|
|
operation: OperationInfo;
|
2017-04-23 15:39:36 +03:00
|
|
|
pathInMiddlePanel: boolean;
|
2016-08-22 12:12:13 +03:00
|
|
|
|
2017-02-27 14:13:06 +03:00
|
|
|
constructor(
|
|
|
|
specMgr:SpecManager,
|
|
|
|
private optionsService: OptionsService,
|
|
|
|
private menu: MenuService) {
|
2016-06-23 17:36:38 +03:00
|
|
|
super(specMgr);
|
2017-04-23 15:39:36 +03:00
|
|
|
|
|
|
|
this.pathInMiddlePanel = optionsService.options.pathInMiddlePanel;
|
2015-10-08 23:21:51 +03:00
|
|
|
}
|
|
|
|
|
2016-07-20 11:07:08 +03:00
|
|
|
init() {
|
2016-12-25 15:24:58 +03:00
|
|
|
this.operationId = this.componentSchema.operationId;
|
|
|
|
|
2017-03-30 15:17:08 +03:00
|
|
|
this.operation = {
|
2017-02-26 00:38:19 +03:00
|
|
|
verb: JsonPointer.baseName(this.pointer),
|
2016-12-25 15:24:58 +03:00
|
|
|
path: JsonPointer.baseName(this.pointer, 2),
|
|
|
|
info: {
|
|
|
|
description: this.componentSchema.description,
|
|
|
|
tags: this.filterMainTags(this.componentSchema.tags)
|
|
|
|
},
|
|
|
|
bodyParam: this.findBodyParam(),
|
2017-03-30 15:17:08 +03:00
|
|
|
summary: SchemaHelper.operationSummary(this.componentSchema),
|
2017-02-03 00:08:04 +03:00
|
|
|
anchor: this.buildAnchor(),
|
|
|
|
externalDocs: this.componentSchema.externalDocs
|
2016-12-25 15:24:58 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-03-29 11:25:30 +03:00
|
|
|
buildAnchor():string {
|
|
|
|
return this.menu.hashFor(this.pointer,
|
2017-03-30 15:17:08 +03:00
|
|
|
{ type: 'operation', operationId: this.operationId, pointer: this.pointer },
|
2017-02-27 14:13:06 +03:00
|
|
|
this.parentTagId );
|
2016-12-25 15:24:58 +03:00
|
|
|
}
|
|
|
|
|
2015-11-17 02:34:13 +03:00
|
|
|
filterMainTags(tags) {
|
2016-06-23 17:36:38 +03:00
|
|
|
var tagsMap = this.specMgr.getTagsMap();
|
2016-01-15 18:08:25 +03:00
|
|
|
if (!tags) return [];
|
2015-12-01 01:29:01 +03:00
|
|
|
return tags.filter(tag => tagsMap[tag] && tagsMap[tag]['x-traitTag']);
|
2015-11-17 02:34:13 +03:00
|
|
|
}
|
|
|
|
|
2017-04-18 16:46:19 +03:00
|
|
|
findBodyParam():SwaggerBodyParameter {
|
2017-03-30 15:17:08 +03:00
|
|
|
let params = this.specMgr.getOperationParams(this.pointer);
|
|
|
|
let bodyParam = params.find(param => param.in === 'body');
|
2015-10-25 14:26:38 +03:00
|
|
|
return bodyParam;
|
2015-10-08 23:21:51 +03:00
|
|
|
}
|
2016-08-28 21:46:10 +03:00
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.preinit();
|
|
|
|
}
|
2015-10-08 23:21:51 +03:00
|
|
|
}
|