2015-10-21 12:20:14 +03:00
|
|
|
'use strict';
|
|
|
|
|
2016-08-30 17:07:54 +03:00
|
|
|
import { Component, Input, OnInit, ChangeDetectionStrategy } from '@angular/core';
|
2016-08-22 12:12:13 +03:00
|
|
|
import { BaseComponent, SpecManager } from '../base';
|
2015-10-27 20:44:08 +03:00
|
|
|
import JsonPointer from '../../utils/JsonPointer';
|
2016-05-09 22:55:16 +03:00
|
|
|
import { statusCodeType } from '../../utils/helpers';
|
2016-05-06 12:46:41 +03:00
|
|
|
import { OptionsService } from '../../services/index';
|
2016-07-28 07:24:12 +03:00
|
|
|
import { SchemaHelper } from '../../services/schema-helper.service';
|
2015-10-21 12:20:14 +03:00
|
|
|
|
|
|
|
function isNumeric(n) {
|
|
|
|
return (!isNaN(parseFloat(n)) && isFinite(n));
|
|
|
|
}
|
|
|
|
|
2016-08-22 12:12:13 +03:00
|
|
|
@Component({
|
2015-10-21 12:20:14 +03:00
|
|
|
selector: 'responses-list',
|
2016-05-25 18:34:31 +03:00
|
|
|
templateUrl: './responses-list.html',
|
2016-08-30 17:07:54 +03:00
|
|
|
styleUrls: ['./responses-list.css'],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
2015-10-21 12:20:14 +03:00
|
|
|
})
|
2016-08-28 21:46:10 +03:00
|
|
|
export class ResponsesList extends BaseComponent implements OnInit {
|
2016-08-22 12:12:13 +03:00
|
|
|
@Input() pointer:string;
|
|
|
|
|
2016-07-20 11:07:08 +03:00
|
|
|
responses: Array<any>;
|
2016-05-25 18:34:31 +03:00
|
|
|
options: any;
|
2016-08-22 12:12:13 +03:00
|
|
|
|
2016-06-23 17:36:38 +03:00
|
|
|
constructor(specMgr:SpecManager, optionsMgr:OptionsService) {
|
|
|
|
super(specMgr);
|
2016-02-16 16:31:12 +03:00
|
|
|
this.options = optionsMgr.options;
|
2015-10-21 12:20:14 +03:00
|
|
|
}
|
|
|
|
|
2016-07-20 11:07:08 +03:00
|
|
|
init() {
|
|
|
|
this.responses = [];
|
2015-12-19 18:18:48 +03:00
|
|
|
|
2015-10-21 12:20:14 +03:00
|
|
|
let responses = this.componentSchema;
|
2015-12-19 18:18:48 +03:00
|
|
|
if (!responses) return;
|
|
|
|
|
2015-10-21 12:20:14 +03:00
|
|
|
responses = Object.keys(responses).filter(respCode => {
|
|
|
|
// only response-codes and "default"
|
|
|
|
return ( isNumeric(respCode) || (respCode === 'default'));
|
|
|
|
}).map(respCode => {
|
|
|
|
let resp = responses[respCode];
|
|
|
|
resp.pointer = JsonPointer.join(this.pointer, respCode);
|
|
|
|
if (resp.$ref) {
|
|
|
|
let ref = resp.$ref;
|
2016-06-23 17:36:38 +03:00
|
|
|
resp = this.specMgr.byPointer(resp.$ref);
|
2015-10-21 12:20:14 +03:00
|
|
|
resp.pointer = ref;
|
|
|
|
}
|
|
|
|
|
2016-01-24 22:27:15 +03:00
|
|
|
resp.empty = !resp.schema;
|
2015-10-21 12:20:14 +03:00
|
|
|
resp.code = respCode;
|
2015-11-23 23:57:49 +03:00
|
|
|
resp.type = statusCodeType(resp.code);
|
2016-12-14 15:49:02 +03:00
|
|
|
|
|
|
|
if (this.options.expandResponses) {
|
|
|
|
if (this.options.expandResponses === 'all' || this.options.expandResponses.has(respCode.toString())) {
|
|
|
|
resp.expanded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-30 16:42:36 +03:00
|
|
|
if (resp.headers && !(resp.headers instanceof Array)) {
|
2015-11-26 01:36:07 +03:00
|
|
|
resp.headers = Object.keys(resp.headers).map((k) => {
|
|
|
|
let respInfo = resp.headers[k];
|
|
|
|
respInfo.name = k;
|
2016-07-28 07:24:12 +03:00
|
|
|
return SchemaHelper.preprocess(respInfo, this.pointer, this.pointer);
|
2015-11-26 01:36:07 +03:00
|
|
|
});
|
2016-01-24 22:27:15 +03:00
|
|
|
resp.empty = false;
|
2015-11-26 01:36:07 +03:00
|
|
|
}
|
|
|
|
resp.extendable = resp.headers || resp.length;
|
2015-10-21 12:20:14 +03:00
|
|
|
return resp;
|
|
|
|
});
|
2016-07-20 11:07:08 +03:00
|
|
|
this.responses = responses;
|
2015-10-21 12:20:14 +03:00
|
|
|
}
|
2016-06-30 16:42:36 +03:00
|
|
|
|
2016-12-02 12:59:29 +03:00
|
|
|
trackByCode(_, el) {
|
2016-06-30 16:42:36 +03:00
|
|
|
return el.code;
|
|
|
|
}
|
2016-08-28 21:46:10 +03:00
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.preinit();
|
|
|
|
}
|
2015-10-21 12:20:14 +03:00
|
|
|
}
|