Skip to content

Commit

Permalink
[preview] Render response examples
Browse files Browse the repository at this point in the history
Renders response examples. This also fixes an error in
documentations for `hasAResponseWithSchema` and
`hasAResponseWithHeaders`.

Fixes #674
Fixes #698
Fixes #652
  • Loading branch information
saharj committed Dec 18, 2015
1 parent fa590f4 commit 4f044bf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
17 changes: 15 additions & 2 deletions app/scripts/directives/operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ SwaggerEditor.directive('swaggerOperation', function (defaults) {
* Returns true if the operation responses has at least one response with
* schema
*
* @param responses {array} - an array of responses
* @param responses {object} - a hash of responses
* @returns boolean
*/
$scope.hasAResponseWithSchema = function (responses) {
Expand All @@ -93,14 +93,27 @@ SwaggerEditor.directive('swaggerOperation', function (defaults) {
* Returns true if the operation responses has at least one response with
* "headers" field
*
* @param responses {array} - an array of responses
* @param responses {object} - a hash of responses
* @returns boolean
*/
$scope.hasAResponseWithHeaders = function (responses) {
return _.keys(responses).some(function (responseCode) {
return responses[responseCode] && responses[responseCode].headers;
});
};

/*
* Returns true if the operation responses has at least one response with
* examples
*
* @param responses {object} - a hash of responses
* @returns boolean
*/
$scope.hasAResponseWithExamples = function (responses) {
return _.keys(responses).some(function (responseCode) {
return responses[responseCode] && responses[responseCode].examples;
});
};
}
};
});
2 changes: 1 addition & 1 deletion app/styles/components/operation.less
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ li.operation {
}


table.params, table.respns, table.security {
table.params, table.respns, table.security, table.examples {
width: 100%;

>thead {
Expand Down
13 changes: 13 additions & 0 deletions app/templates/operation.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ <h4>Responses</h4>
<th>Description</th>
<th ng-if="hasAResponseWithHeaders(operation.responses)">Headers</th>
<th ng-if="hasAResponseWithSchema(operation.responses)">Schema</th>
<th ng-if="hasAResponseWithExamples(operation.responses)">Examples</th>
</tr>
</thead>

Expand Down Expand Up @@ -144,6 +145,18 @@ <h4>Responses</h4>
<td ng-if="hasAResponseWithSchema(operation.responses)">
<schema-model ng-if="response.schema" schema="response.schema"></schema-model>
</td>
<td ng-if="hasAResponseWithExamples(operation.responses)">
<table class="examples">
<tbody>
<tr ng-repeat="(exampleMimeType, example) in response.examples">
<td>{{exampleMimeType}}</td>
<td>
<json-formatter json="example" open="1"></json-formatter>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
Expand Down

0 comments on commit 4f044bf

Please sign in to comment.