redoc/lib/components/Method/method.js

45 lines
1.5 KiB
JavaScript
Raw Normal View History

2015-10-08 23:21:51 +03:00
'use strict';
import {JsonPointer} from '../../utils/JsonPointer';
import {RedocComponent, BaseComponent} from '../base';
2015-10-27 20:44:08 +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';
2016-01-31 20:37:51 +03:00
import RequestSamples from '../RequestSamples/request-samples';
2015-10-08 23:21:51 +03:00
@RedocComponent({
2015-10-08 23:21:51 +03:00
selector: 'method',
2015-10-10 15:34:46 +03:00
templateUrl: './lib/components/Method/method.html',
2015-10-10 16:01:41 +03:00
styleUrls: ['./lib/components/Method/method.css'],
2016-01-31 20:37:51 +03:00
directives: [ParamsList, ResponsesList, ResponsesSamples, SchemaSample, RequestSamples],
2015-11-27 01:43:01 +03:00
inputs: ['tag']
2015-10-08 23:21:51 +03:00
})
2015-10-27 20:44:08 +03:00
export default class Method extends BaseComponent {
2015-10-08 23:21:51 +03:00
constructor(schemaMgr) {
super(schemaMgr);
2015-10-08 23:21:51 +03:00
}
prepareModel() {
2015-10-08 23:21:51 +03:00
this.data = {};
2015-11-17 01:03:09 +03:00
this.data.apiUrl = this.schemaMgr.apiUrl;
2015-12-19 03:24:25 +03:00
this.data.httpMethod = JsonPointer.baseName(this.pointer);
this.data.path = JsonPointer.baseName(this.pointer, 2);
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();
}
2015-11-17 02:34:13 +03:00
filterMainTags(tags) {
var tagsMap = this.schemaMgr.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() {
2015-12-12 18:29:50 +03:00
let pathParams = this.schemaMgr.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
}
}