2015-10-10 16:01:41 +03:00
|
|
|
'use strict';
|
2016-08-28 21:46:10 +03:00
|
|
|
import { Component, Input, ChangeDetectionStrategy, OnInit } from '@angular/core';
|
2016-08-22 12:12:13 +03:00
|
|
|
import { BaseComponent, SpecManager } from '../base';
|
2016-06-22 21:17:48 +03:00
|
|
|
import { SchemaHelper } from '../../services/schema-helper.service';
|
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);
|
|
|
|
}
|
|
|
|
|
2016-08-22 12:12:13 +03:00
|
|
|
@Component({
|
2015-10-10 16:01:41 +03:00
|
|
|
selector: 'params-list',
|
2016-05-25 18:34:31 +03:00
|
|
|
templateUrl: './params-list.html',
|
|
|
|
styleUrls: ['./params-list.css'],
|
2016-08-22 12:12:13 +03:00
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
2015-10-10 16:01:41 +03:00
|
|
|
})
|
2016-08-28 21:46:10 +03:00
|
|
|
export class ParamsList extends BaseComponent implements OnInit {
|
2016-08-22 12:12:13 +03:00
|
|
|
@Input() pointer:string;
|
2016-06-13 20:54:24 +03:00
|
|
|
|
2016-07-20 11:07:08 +03:00
|
|
|
params: Array<any>;
|
|
|
|
empty: boolean;
|
|
|
|
bodyParam: any;
|
2016-06-13 20:54:24 +03:00
|
|
|
|
2016-06-23 17:36:38 +03:00
|
|
|
constructor(specMgr:SpecManager) {
|
|
|
|
super(specMgr);
|
2015-10-10 16:01:41 +03:00
|
|
|
}
|
|
|
|
|
2016-07-20 11:07:08 +03:00
|
|
|
init() {
|
|
|
|
this.params = [];
|
2017-01-30 17:11:14 +03:00
|
|
|
let paramsList = this.specMgr.getMethodParams(this.pointer);
|
2016-02-23 14:05:59 +03:00
|
|
|
|
2016-06-22 21:17:48 +03:00
|
|
|
paramsList = paramsList.map(paramSchema => {
|
|
|
|
let propPointer = paramSchema._pointer;
|
|
|
|
if (paramSchema.in === 'body') return paramSchema;
|
2016-07-28 07:24:12 +03:00
|
|
|
return SchemaHelper.preprocess(paramSchema, propPointer, this.pointer);
|
2016-02-23 14:05:59 +03:00
|
|
|
});
|
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];
|
2016-07-20 11:07:08 +03:00
|
|
|
this.bodyParam = bodyParam;
|
2016-03-09 01:28:55 +03:00
|
|
|
paramsMap.body = undefined;
|
2015-10-10 16:01:41 +03:00
|
|
|
}
|
|
|
|
|
2016-07-20 11:07:08 +03:00
|
|
|
this.empty = !(Object.keys(paramsMap).length || this.bodyParam);
|
2016-02-04 12:49:00 +03:00
|
|
|
|
2016-02-23 14:05:59 +03:00
|
|
|
let paramsPlaces = ['path', 'query', 'formData', 'header', 'body'];
|
2016-03-28 00:54:43 +03:00
|
|
|
let placeHint = {
|
|
|
|
path: `Used together with Path Templating, where the parameter value is actually part
|
|
|
|
of the operation's URL. This does not include the host or base path of the API.
|
|
|
|
For example, in /items/{itemId}, the path parameter is itemId`,
|
|
|
|
query: `Parameters that are appended to the URL.
|
|
|
|
For example, in /items?id=###, the query parameter is id`,
|
|
|
|
formData: `Parameters that are submitted through a form.
|
|
|
|
application/x-www-form-urlencoded, multipart/form-data or both are usually
|
|
|
|
used as the content type of the request`,
|
|
|
|
header: 'Custom headers that are expected as part of the request'
|
|
|
|
};
|
2016-02-23 14:05:59 +03:00
|
|
|
let params = [];
|
|
|
|
paramsPlaces.forEach(place => {
|
2016-02-23 14:09:31 +03:00
|
|
|
if (paramsMap[place] && paramsMap[place].length) {
|
2016-03-28 00:54:43 +03:00
|
|
|
params.push({place: place, placeHint: placeHint[place], params: paramsMap[place]});
|
2016-02-23 14:09:31 +03:00
|
|
|
}
|
2016-02-23 14:05:59 +03:00
|
|
|
});
|
2016-07-20 11:07:08 +03:00
|
|
|
this.params = params;
|
2015-10-10 16:01:41 +03:00
|
|
|
}
|
|
|
|
|
2016-05-25 18:34:31 +03:00
|
|
|
orderParams(params):any {
|
2016-02-23 14:05:59 +03:00
|
|
|
let res = {};
|
|
|
|
params.forEach((param) => safePush(res, param.in, param));
|
|
|
|
return res;
|
2015-10-10 16:01:41 +03:00
|
|
|
}
|
2016-08-28 21:46:10 +03:00
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.preinit();
|
|
|
|
}
|
2015-10-10 16:01:41 +03:00
|
|
|
}
|