Added responses list

This commit is contained in:
Roman Gotsiy 2015-10-21 12:20:14 +03:00
parent 8c54d83ee8
commit 93d7d98ad7
8 changed files with 110 additions and 6 deletions

View File

@ -1,3 +1,7 @@
responses-list, params-list {
display: block;
}
h2 {
font-size: 32px;
font-weight: 200;

View File

@ -7,3 +7,5 @@
{{data.methodInfo.description}}
</p>
<params-list pointer="{{pointer}}/parameters"> </params-list>
<br>
<responses-list pointer="{{pointer}}/responses"> </responses-list>

View File

@ -3,12 +3,13 @@
import {JsonPointer} from '../../utils/JsonPointer';
import {RedocComponent, BaseComponent} from '../base';
import {ParamsList} from '../ParamsList/params-list';
import {ResponsesList} from '../ResponsesList/responses-list';
@RedocComponent({
selector: 'method',
templateUrl: './lib/components/Method/method.html',
styleUrls: ['./lib/components/Method/method.css'],
directives: [ParamsList]
directives: [ParamsList, ResponsesList]
})
export class Method extends BaseComponent {
constructor(schemaMgr) {

View File

@ -5,6 +5,7 @@ h4 {
}
table {
width: 100%;
border-spacing: 0;
border: 2px solid #1976D3;
}

View File

@ -1,24 +1,24 @@
<small class="no-params" *ng-if="data.noParams"> No parameters </small>
<!-- General parameters -->
<table *ng-if="!data.noParams">
<table *ng-if="!data.noParams" class="inline">
<thead>
<tr>
<th colspan="3"> Parameters </th>
</tr>
<tr>
<th> Name </th>
<th> Type </th>
<th> Description </th>
<th> Type </th>
</tr>
</thead>
<tbody>
<tr *ng-for="#param of data.params">
<!--<div class="param">-->
<td class="param-name">{{param.name}}</td>
<td>
<span class="param-type" [ng-class]="param.type">{{param.type}}</span>
</td>
<td class="param-description">{{param.description}}</td>
<td>
<span class="type" [ng-class]="param.type">{{param.type}}</span>
</td>
<!--</div>-->
</tr>
<!-- in-body parameter -->

View File

@ -0,0 +1,32 @@
table {
width: 100%;
border-spacing: 0;
border: 2px solid green;
}
thead tr:first-child {
background: green;
color: #fff;
border: none;
}
thead tr:last-child th {
border-bottom: 3px solid #ddd;
}
tbody tr:last-child td {
border: none;
}
tbody td {
border-bottom: 1px solid #ddd;
}
td, th {
vertical-align: top;
padding: 10px 15px;
font-size: 12px;
}
th {
text-align: left;
}

View File

@ -0,0 +1,22 @@
<table class="inline">
<thead>
<tr>
<th colspan="3"> Responses </th>
</tr>
<tr>
<th> Response code </th>
<th> Description </th>
<th> Response schema </th>
</tr>
</thead>
<tbody>
<tr *ng-for="#response of data.responses">
<td>{{response.code}}</td>
<td>{{response.description}}</td>
<td>
<schema *ng-if="response.schema" class="schema type" pointer="{{response.pointer}}/schema">
</schema>
</td>
</tr>
</tbody>
</table>

View File

@ -0,0 +1,42 @@
'use strict';
import {RedocComponent, BaseComponent} from '../base';
import {JsonPointer} from '../../utils/JsonPointer';
import {JsonSchemaView} from '../JsonSchemaView/json-schema-view';
function isNumeric(n) {
return (!isNaN(parseFloat(n)) && isFinite(n));
}
@RedocComponent({
selector: 'responses-list',
templateUrl: './lib/components/ResponsesList/responses-list.html',
styleUrls: ['./lib/components/ResponsesList/responses-list.css'],
directives: [JsonSchemaView]
})
export class ResponsesList extends BaseComponent {
constructor(schemaMgr) {
super(schemaMgr);
}
prepareModel() {
this.data = {};
let responses = this.componentSchema;
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;
}
resp.code = respCode;
return resp;
});
this.data.responses = responses;
}
}