2015-10-10 16:01:41 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import {RedocComponent, BaseComponent} from '../base';
|
2015-11-19 00:23:18 +03:00
|
|
|
import JsonSchema from '../JsonSchema/json-schema';
|
2016-02-07 17:11:15 +03:00
|
|
|
import JsonSchemaLazy from '../JsonSchema/json-schema-lazy';
|
2015-10-17 21:12:46 +03:00
|
|
|
|
2016-02-23 14:05:59 +03:00
|
|
|
function safePush(obj, prop, item) {
|
|
|
|
if (!obj[prop]) obj[prop] = [];
|
|
|
|
obj[prop].push(item);
|
|
|
|
}
|
|
|
|
|
2015-10-10 16:01:41 +03:00
|
|
|
@RedocComponent({
|
|
|
|
selector: 'params-list',
|
|
|
|
templateUrl: './lib/components/ParamsList/params-list.html',
|
2015-10-17 21:12:46 +03:00
|
|
|
styleUrls: ['./lib/components/ParamsList/params-list.css'],
|
2016-02-07 17:11:15 +03:00
|
|
|
directives: [JsonSchema, JsonSchemaLazy]
|
2015-10-10 16:01:41 +03:00
|
|
|
})
|
2015-10-27 20:44:08 +03:00
|
|
|
export default class ParamsList extends BaseComponent {
|
2015-10-10 16:01:41 +03:00
|
|
|
constructor(schemaMgr) {
|
|
|
|
super(schemaMgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
prepareModel() {
|
|
|
|
this.data = {};
|
2016-02-23 14:05:59 +03:00
|
|
|
let paramsList = this.schemaMgr.getMethodParams(this.pointer, true);
|
|
|
|
|
|
|
|
paramsList = paramsList.map((paramData) => {
|
|
|
|
let propPointer = paramData._pointer;
|
2016-03-09 01:28:55 +03:00
|
|
|
if (paramData.in === 'body') return paramData;
|
2016-02-23 14:05:59 +03:00
|
|
|
return JsonSchema.injectPropData(paramData, paramData.name, propPointer);
|
|
|
|
});
|
2015-10-10 16:01:41 +03:00
|
|
|
|
2016-02-23 14:05:59 +03:00
|
|
|
let paramsMap = this.orderParams(paramsList);
|
|
|
|
|
|
|
|
if (paramsMap.body && paramsMap.body.length) {
|
|
|
|
let bodyParam = paramsMap.body[0];
|
2015-10-25 14:26:38 +03:00
|
|
|
bodyParam.pointer = bodyParam._pointer;
|
2015-10-10 16:01:41 +03:00
|
|
|
this.data.bodyParam = bodyParam;
|
2016-03-09 01:28:55 +03:00
|
|
|
paramsMap.body = undefined;
|
2015-10-10 16:01:41 +03:00
|
|
|
}
|
|
|
|
|
2016-02-23 14:05:59 +03:00
|
|
|
this.data.noParams = !(Object.keys(paramsMap).length || this.data.bodyParam);
|
2016-02-04 12:49:00 +03:00
|
|
|
|
2016-02-23 14:05:59 +03:00
|
|
|
let paramsPlaces = ['path', 'query', 'formData', 'header', 'body'];
|
|
|
|
let params = [];
|
|
|
|
paramsPlaces.forEach(place => {
|
2016-02-23 14:09:31 +03:00
|
|
|
if (paramsMap[place] && paramsMap[place].length) {
|
2016-02-23 14:05:59 +03:00
|
|
|
params.push({place: place, params: paramsMap[place]});
|
2016-02-23 14:09:31 +03:00
|
|
|
}
|
2016-02-23 14:05:59 +03:00
|
|
|
});
|
2015-10-10 16:01:41 +03:00
|
|
|
this.data.params = params;
|
|
|
|
}
|
|
|
|
|
2016-02-23 14:05:59 +03:00
|
|
|
orderParams(params) {
|
|
|
|
let res = {};
|
|
|
|
params.forEach((param) => safePush(res, param.in, param));
|
|
|
|
return res;
|
2015-10-10 16:01:41 +03:00
|
|
|
}
|
|
|
|
}
|