2015-10-22 20:53:07 +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-06 00:48:41 +03:00
|
|
|
import { statusCodeType } from '../../utils/helpers';
|
2015-10-22 20:53:07 +03:00
|
|
|
|
|
|
|
|
|
|
|
function isNumeric(n) {
|
|
|
|
return (!isNaN(parseFloat(n)) && isFinite(n));
|
|
|
|
}
|
|
|
|
|
2015-10-22 21:31:12 +03:00
|
|
|
function hasExample(response) {
|
|
|
|
return ((response.examples && response.examples['application/json']) ||
|
|
|
|
response.schema);
|
|
|
|
}
|
|
|
|
|
2016-08-22 12:12:13 +03:00
|
|
|
@Component({
|
2015-10-22 20:53:07 +03:00
|
|
|
selector: 'responses-samples',
|
2016-05-25 18:34:31 +03:00
|
|
|
templateUrl: './responses-samples.html',
|
|
|
|
styleUrls: ['./responses-samples.css'],
|
2016-08-30 17:07:54 +03:00
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
2015-10-22 20:53:07 +03:00
|
|
|
})
|
2016-08-28 21:46:10 +03:00
|
|
|
export class ResponsesSamples extends BaseComponent implements OnInit {
|
2016-08-22 12:12:13 +03:00
|
|
|
@Input() pointer:string;
|
|
|
|
|
2016-05-25 18:34:31 +03:00
|
|
|
data: any;
|
2016-08-22 12:12:13 +03:00
|
|
|
|
2016-06-23 17:36:38 +03:00
|
|
|
constructor(specMgr:SpecManager) {
|
|
|
|
super(specMgr);
|
2015-10-22 20:53:07 +03:00
|
|
|
}
|
|
|
|
|
2016-07-20 11:07:08 +03:00
|
|
|
init() {
|
2015-10-22 20:53:07 +03:00
|
|
|
this.data = {};
|
2015-12-19 18:18:48 +03:00
|
|
|
this.data.responses = [];
|
|
|
|
|
2015-10-22 20:53:07 +03:00
|
|
|
let responses = this.componentSchema;
|
2015-12-19 18:18:48 +03:00
|
|
|
if (!responses) return;
|
|
|
|
|
2015-10-22 20:53:07 +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-22 20:53:07 +03:00
|
|
|
resp.pointer = ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.code = respCode;
|
2015-11-23 23:27:55 +03:00
|
|
|
resp.type = statusCodeType(resp.code);
|
2015-10-22 20:53:07 +03:00
|
|
|
return resp;
|
2015-10-22 21:31:12 +03:00
|
|
|
})
|
|
|
|
.filter(response => hasExample(response));
|
2015-10-22 20:53:07 +03:00
|
|
|
this.data.responses = responses;
|
|
|
|
}
|
2016-08-28 21:46:10 +03:00
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.preinit();
|
|
|
|
}
|
2015-10-22 20:53:07 +03:00
|
|
|
}
|