2015-10-08 23:21:51 +03:00
|
|
|
'use strict';
|
2016-05-25 18:34:31 +03:00
|
|
|
import { Input } from '@angular/core';
|
|
|
|
import JsonPointer from '../../utils/JsonPointer';
|
2016-06-22 21:17:48 +03:00
|
|
|
import { RedocComponent, BaseComponent, SpecManager} from '../base';
|
2016-02-10 14:19:50 +03:00
|
|
|
|
2016-05-09 22:55:16 +03:00
|
|
|
import { ParamsList } from '../ParamsList/params-list';
|
|
|
|
import { ResponsesList } from '../ResponsesList/responses-list';
|
|
|
|
import { ResponsesSamples } from '../ResponsesSamples/responses-samples';
|
|
|
|
import { SchemaSample } from '../SchemaSample/schema-sample';
|
|
|
|
import { RequestSamples } from '../RequestSamples/request-samples';
|
2016-07-01 17:24:59 +03:00
|
|
|
import { SchemaHelper } from '../../services/schema-helper.service';
|
2015-10-08 23:21:51 +03:00
|
|
|
|
2015-10-09 23:19:35 +03:00
|
|
|
@RedocComponent({
|
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-05-09 22:55:16 +03:00
|
|
|
directives: [ ParamsList, ResponsesList, ResponsesSamples, SchemaSample, RequestSamples ],
|
2016-05-18 16:59:54 +03:00
|
|
|
detect: true
|
2015-10-08 23:21:51 +03:00
|
|
|
})
|
2016-05-06 00:48:41 +03:00
|
|
|
export class Method extends BaseComponent {
|
2016-05-25 18:34:31 +03:00
|
|
|
data:any;
|
|
|
|
@Input() tag:string;
|
2016-06-23 17:36:38 +03:00
|
|
|
constructor(specMgr:SpecManager) {
|
|
|
|
super(specMgr);
|
2015-10-08 23:21:51 +03:00
|
|
|
}
|
|
|
|
|
2015-10-09 23:19:35 +03:00
|
|
|
prepareModel() {
|
2015-10-08 23:21:51 +03:00
|
|
|
this.data = {};
|
2016-06-23 17:36:38 +03:00
|
|
|
this.data.apiUrl = this.specMgr.apiUrl;
|
2015-12-19 03:24:25 +03:00
|
|
|
this.data.httpMethod = JsonPointer.baseName(this.pointer);
|
2015-10-09 08:31:09 +03:00
|
|
|
this.data.path = JsonPointer.baseName(this.pointer, 2);
|
2015-10-09 23:19:35 +03:00
|
|
|
this.data.methodInfo = this.componentSchema;
|
2015-11-17 02:34:13 +03:00
|
|
|
this.data.methodInfo.tags = this.filterMainTags(this.data.methodInfo.tags);
|
2015-10-25 14:26:38 +03:00
|
|
|
this.data.bodyParam = this.findBodyParam();
|
2016-07-01 17:24:59 +03:00
|
|
|
this.data.summary = SchemaHelper.methodSummary(this.componentSchema);
|
2016-02-07 17:10:32 +03:00
|
|
|
if (this.componentSchema.operationId) {
|
2016-03-09 22:54:21 +03:00
|
|
|
this.data.methodAnchor = 'operation/' + encodeURIComponent(this.componentSchema.operationId);
|
2016-02-07 17:10:32 +03:00
|
|
|
} else {
|
2016-03-09 23:05:06 +03:00
|
|
|
this.data.methodAnchor = 'tag/' + encodeURIComponent(this.tag + this.pointer);
|
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
|
|
|
}
|
|
|
|
}
|