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';
|
2016-12-02 12:59:29 +03:00
|
|
|
import { OptionsService } from '../../services/';
|
2015-10-08 23:21:51 +03:00
|
|
|
|
2016-12-25 15:24:58 +03:00
|
|
|
|
|
|
|
interface MethodInfo {
|
|
|
|
apiUrl: string;
|
|
|
|
httpMethod: string;
|
|
|
|
path: string;
|
|
|
|
info: {
|
|
|
|
tags: string[];
|
|
|
|
description: string;
|
|
|
|
};
|
|
|
|
bodyParam: any;
|
|
|
|
summary: any;
|
|
|
|
anchor: any;
|
|
|
|
}
|
|
|
|
|
2016-08-22 12:12:13 +03:00
|
|
|
@Component({
|
2015-10-08 23:21:51 +03:00
|
|
|
selector: 'method',
|
2016-05-25 18:34:31 +03:00
|
|
|
templateUrl: './method.html',
|
|
|
|
styleUrls: ['./method.css'],
|
2016-08-30 17:07:54 +03:00
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
2015-10-08 23:21:51 +03:00
|
|
|
})
|
2016-08-28 21:46:10 +03:00
|
|
|
export class Method 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
|
|
|
|
2016-12-25 20:15:24 +03:00
|
|
|
method: MethodInfo;
|
2016-08-22 12:12:13 +03:00
|
|
|
|
2016-12-25 15:24:58 +03:00
|
|
|
constructor(specMgr:SpecManager, private optionsService: OptionsService) {
|
2016-06-23 17:36:38 +03:00
|
|
|
super(specMgr);
|
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;
|
|
|
|
|
|
|
|
this.method = {
|
|
|
|
httpMethod: JsonPointer.baseName(this.pointer),
|
|
|
|
path: JsonPointer.baseName(this.pointer, 2),
|
|
|
|
info: {
|
|
|
|
description: this.componentSchema.description,
|
|
|
|
tags: this.filterMainTags(this.componentSchema.tags)
|
|
|
|
},
|
|
|
|
bodyParam: this.findBodyParam(),
|
|
|
|
summary: SchemaHelper.methodSummary(this.componentSchema),
|
|
|
|
apiUrl: this.getBaseUrl(),
|
|
|
|
anchor: this.buildAnchor()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
buildAnchor() {
|
|
|
|
if (this.operationId) {
|
|
|
|
return 'operation/' + encodeURIComponent(this.componentSchema.operationId);
|
2016-11-01 21:40:59 +03:00
|
|
|
} else {
|
2016-12-25 15:24:58 +03:00
|
|
|
return this.parentTagId + encodeURIComponent(this.pointer);
|
2016-11-01 21:40:59 +03:00
|
|
|
}
|
2016-12-25 15:24:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
getBaseUrl():string {
|
|
|
|
if (this.optionsService.options.hideHostname) {
|
|
|
|
return this.specMgr.basePath;
|
2016-02-07 17:10:32 +03:00
|
|
|
} else {
|
2016-12-25 15:24:58 +03:00
|
|
|
return this.specMgr.apiUrl;
|
2016-02-07 17:10:32 +03:00
|
|
|
}
|
2015-10-25 14:26:38 +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
|
|
|
}
|
|
|
|
|
2015-10-25 14:26:38 +03:00
|
|
|
findBodyParam() {
|
2016-06-23 17:36:38 +03:00
|
|
|
let pathParams = this.specMgr.getMethodParams(this.pointer, true);
|
2015-10-25 14:26:38 +03:00
|
|
|
let bodyParam = pathParams.find(param => param.in === 'body');
|
|
|
|
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
|
|
|
}
|