2015-10-10 16:01:41 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import {RedocComponent, BaseComponent} from '../base';
|
2015-10-27 20:44:08 +03:00
|
|
|
import JsonSchemaView from '../JsonSchemaView/json-schema-view';
|
2015-11-19 00:23:18 +03:00
|
|
|
import JsonSchema from '../JsonSchema/json-schema';
|
2015-10-17 21:12:46 +03:00
|
|
|
|
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'],
|
2015-11-19 00:23:18 +03:00
|
|
|
directives: [JsonSchemaView, JsonSchema]
|
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 = {};
|
2015-10-25 14:26:38 +03:00
|
|
|
let params = this.schemaMgr.getMethodParams(this.pointer, true);
|
2015-10-10 16:01:41 +03:00
|
|
|
this.sortParams(params);
|
|
|
|
|
2015-10-17 21:12:46 +03:00
|
|
|
// temporary handle body param
|
2015-10-10 16:01:41 +03:00
|
|
|
if (params.length && params[params.length - 1].in === 'body') {
|
|
|
|
let bodyParam = params.pop();
|
2015-10-25 14:26:38 +03:00
|
|
|
bodyParam.pointer = bodyParam._pointer;
|
2015-10-10 16:01:41 +03:00
|
|
|
this.data.bodyParam = bodyParam;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.data.noParams = !(params.length || this.data.bodyParam);
|
|
|
|
this.data.params = params;
|
|
|
|
}
|
|
|
|
|
|
|
|
sortParams(params) {
|
|
|
|
const sortOrder = {
|
|
|
|
'path' : 0,
|
|
|
|
'query' : 10,
|
|
|
|
'formData' : 20,
|
|
|
|
'header': 40,
|
|
|
|
'body': 50
|
|
|
|
};
|
|
|
|
|
2015-10-10 16:48:17 +03:00
|
|
|
params.sort((a, b) => sortOrder[a.in] - sortOrder[b.in]);
|
2015-10-10 16:01:41 +03:00
|
|
|
}
|
|
|
|
}
|