2015-10-21 12:20:14 +03:00
|
|
|
'use strict';
|
|
|
|
|
2016-02-16 16:31:12 +03:00
|
|
|
import {RedocComponent, BaseComponent, SchemaManager} from '../base';
|
2015-10-27 20:44:08 +03:00
|
|
|
import JsonPointer from '../../utils/JsonPointer';
|
2016-05-09 22:55:16 +03:00
|
|
|
import { JsonSchema } from '../JsonSchema/json-schema';
|
|
|
|
import { JsonSchemaLazy } from '../JsonSchema/json-schema-lazy';
|
|
|
|
import { Zippy } from '../../shared/components/index';
|
|
|
|
import { statusCodeType } from '../../utils/helpers';
|
2016-05-06 12:46:41 +03:00
|
|
|
import { OptionsService } from '../../services/index';
|
2015-10-21 12:20:14 +03:00
|
|
|
|
|
|
|
function isNumeric(n) {
|
|
|
|
return (!isNaN(parseFloat(n)) && isFinite(n));
|
|
|
|
}
|
|
|
|
|
|
|
|
@RedocComponent({
|
|
|
|
selector: 'responses-list',
|
2016-05-25 18:34:31 +03:00
|
|
|
templateUrl: './responses-list.html',
|
|
|
|
styleUrls: ['./responses-list.css'],
|
2016-05-18 16:59:54 +03:00
|
|
|
directives: [JsonSchema, Zippy, JsonSchemaLazy],
|
|
|
|
detect: true
|
2015-10-21 12:20:14 +03:00
|
|
|
})
|
2016-05-06 00:48:41 +03:00
|
|
|
export class ResponsesList extends BaseComponent {
|
2016-05-25 18:34:31 +03:00
|
|
|
data: any;
|
|
|
|
options: any;
|
|
|
|
constructor(schemaMgr:SchemaManager, optionsMgr:OptionsService) {
|
2015-10-21 12:20:14 +03:00
|
|
|
super(schemaMgr);
|
2016-02-16 16:31:12 +03:00
|
|
|
this.options = optionsMgr.options;
|
2015-10-21 12:20:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
prepareModel() {
|
|
|
|
this.data = {};
|
2015-12-19 18:18:48 +03:00
|
|
|
this.data.responses = [];
|
|
|
|
|
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;
|
|
|
|
resp = this.schemaMgr.byPointer(resp.$ref);
|
|
|
|
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);
|
2015-11-26 01:36:07 +03:00
|
|
|
if (resp.headers) {
|
|
|
|
resp.headers = Object.keys(resp.headers).map((k) => {
|
|
|
|
let respInfo = resp.headers[k];
|
|
|
|
respInfo.name = k;
|
|
|
|
return respInfo;
|
|
|
|
});
|
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;
|
|
|
|
});
|
|
|
|
this.data.responses = responses;
|
|
|
|
}
|
|
|
|
}
|