Skip to content

Commit 6537f21

Browse files
author
Javier Isoldi
committed
Merge branch 'bugs/responces-security-schema' into develop
2 parents 5351a23 + 0f17156 commit 6537f21

File tree

3 files changed

+80
-26
lines changed

3 files changed

+80
-26
lines changed

dist/scripts/api-console.js

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,33 @@
132132
$scope.markedOptions = RAML.Settings.marked;
133133
$scope.documentationSchemeSelected = defaultSchema;
134134

135+
function mergeResponseCodes(methodCodes, schemas) {
136+
var codes = {};
137+
138+
// Copy all method codes
139+
Object.keys(methodCodes).forEach(function (code) {
140+
if (methodCodes.hasOwnProperty(code)) { codes[code] = methodCodes[code]; }
141+
});
142+
143+
// Copy schema's code that are not present in the method
144+
Object.keys(schemas).forEach(function (key) {
145+
if (schemas.hasOwnProperty(key)) { copyToCodesIfNotPresent(codes, schemas[key].describedBy.responses) }
146+
});
147+
148+
return codes;
149+
}
150+
151+
function copyToCodesIfNotPresent(codes, schemaCodes) {
152+
Object.keys(schemaCodes).forEach(function (code) {
153+
if (schemaCodes.hasOwnProperty(code) && !codes.hasOwnProperty(code)) {
154+
codes[code] = schemaCodes[code];
155+
}
156+
});
157+
}
158+
$scope.fullResponses = mergeResponseCodes($scope.methodInfo.responses || {}, $scope.methodInfo.securitySchemes());
159+
$scope.fullResponseCodes = Object.keys($scope.fullResponses);
160+
161+
135162
$scope.isSchemeSelected = function isSchemeSelected(scheme) {
136163
return scheme.id === $scope.documentationSchemeSelected.id;
137164
};
@@ -156,13 +183,13 @@
156183

157184
$scope.currentStatusCode = '200';
158185

159-
if ($scope.methodInfo.responseCodes && $scope.methodInfo.responseCodes.length > 0) {
160-
$scope.currentStatusCode = $scope.methodInfo.responseCodes[0];
186+
if ($scope.fullResponseCodes && $scope.fullResponseCodes.length > 0) {
187+
$scope.currentStatusCode = $scope.fullResponseCodes[0];
161188
}
162189

163190
$scope.$on('resetData', function() {
164-
if ($scope.methodInfo.responseCodes && $scope.methodInfo.responseCodes.length > 0) {
165-
$scope.currentStatusCode = $scope.methodInfo.responseCodes[0];
191+
if ($scope.fullResponseCodes && $scope.fullResponseCodes.length > 0) {
192+
$scope.currentStatusCode = $scope.fullResponseCodes[0];
166193
}
167194
});
168195

@@ -6591,7 +6618,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
65916618
" </div>\n" +
65926619
"\n" +
65936620
" <!-- Response -->\n" +
6594-
" <div ng-if=\"methodInfo.responseCodes\">\n" +
6621+
" <div ng-if=\"fullResponseCodes\">\n" +
65956622
" <header class=\"raml-console-resource-header\">\n" +
65966623
" <h3 class=\"raml-console-resource-head\">\n" +
65976624
" Response\n" +
@@ -6600,39 +6627,39 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
66006627
"\n" +
66016628
" <div class=\"raml-console-resource-response-jump\">\n" +
66026629
" <ul class=\"raml-console-resource-menu\">\n" +
6603-
" <li class=\"raml-console-resource-btns raml-console-resource-menu-item\" ng-repeat=\"code in methodInfo.responseCodes\">\n" +
6630+
" <li class=\"raml-console-resource-btns raml-console-resource-menu-item\" ng-repeat=\"code in fullResponseCodes\">\n" +
66046631
" <button ng-click=\"showCodeDetails(code)\" class=\"raml-console-resource-btn raml-console-resource-menu-button raml-console-resource-menu-btn-{{getColorCode(code)}}\" ng-class=\"{ 'raml-console-button-is-active': isActiveCode(code) }\" href=\"#code{{code}}\">{{code}}</button>\n" +
66056632
" </li>\n" +
66066633
" </ul>\n" +
66076634
" </div>\n" +
66086635
"\n" +
66096636
" <div class=\"raml-console-resource-panel-primary-row raml-console-resource-panel-content raml-console-is-active raml-console-response-container\" ng-class=\"{'raml-console-is-active':showResponseDocumentation}\">\n" +
6610-
" <section ng-if=\"isActiveCode(code)\" class=\"raml-console-resource-section raml-console-resource-response-section\" ng-repeat=\"code in methodInfo.responseCodes\">\n" +
6637+
" <section ng-if=\"isActiveCode(code)\" class=\"raml-console-resource-section raml-console-resource-response-section\" ng-repeat=\"code in fullResponseCodes\">\n" +
66116638
" <a name=\"code{{code}}\"></a>\n" +
66126639
" <h3 class=\"raml-console-resource-heading-a\">Status {{code}}</h3>\n" +
66136640
"\n" +
66146641
" <div class=\"raml-console-resource-response\">\n" +
6615-
" <p markdown=\"methodInfo.responses[code].description\" class=\"raml-console-marked-content\"></p>\n" +
6642+
" <p markdown=\"fullResponses[code].description\" class=\"raml-console-marked-content\"></p>\n" +
66166643
" </div>\n" +
66176644
"\n" +
6618-
" <div class=\"raml-console-resource-response\" ng-if=\"methodInfo.responses[code].headers\">\n" +
6645+
" <div class=\"raml-console-resource-response\" ng-if=\"fullResponses[code].headers\">\n" +
66196646
" <h4 class=\"raml-console-resource-body-heading\">Headers</h4>\n" +
6620-
" <properties list=\"methodInfo.responses[code].headers\"></properties>\n" +
6647+
" <properties list=\"fullResponses[code].headers\"></properties>\n" +
66216648
" </div>\n" +
66226649
"\n" +
6623-
" <div class=\"raml-console-resource-response\" ng-if=\"methodInfo.responses[code].body\">\n" +
6650+
" <div class=\"raml-console-resource-response\" ng-if=\"fullResponses[code].body\">\n" +
66246651
" <h4 class=\"raml-console-resource-body-heading\">\n" +
66256652
" Body\n" +
66266653
" <span\n" +
66276654
" ng-click=\"changeType($event, key, code)\"\n" +
66286655
" ng-class=\"{ 'raml-console-is-active': responseInfo[code].currentType === key}\"\n" +
66296656
" class=\"raml-console-flag\"\n" +
6630-
" ng-repeat=\"(key, value) in methodInfo.responses[code].body\">\n" +
6657+
" ng-repeat=\"(key, value) in fullResponses[code].body\">\n" +
66316658
" {{key}}\n" +
66326659
" </span>\n" +
66336660
" </h4>\n" +
66346661
"\n" +
6635-
" <div ng-repeat=\"(key, value) in methodInfo.responses[code].body\">\n" +
6662+
" <div ng-repeat=\"(key, value) in fullResponses[code].body\">\n" +
66366663
" <div ng-if=\"responseInfo[code].currentType === key\">\n" +
66376664
" <examples\n" +
66386665
" ng-if=\"responseInfo[code] && responseInfo[code].currentType\"\n" +

src/app/directives/documentation.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,33 @@
1313
$scope.markedOptions = RAML.Settings.marked;
1414
$scope.documentationSchemeSelected = defaultSchema;
1515

16+
function mergeResponseCodes(methodCodes, schemas) {
17+
var codes = {};
18+
19+
// Copy all method codes
20+
Object.keys(methodCodes).forEach(function (code) {
21+
if (methodCodes.hasOwnProperty(code)) { codes[code] = methodCodes[code]; }
22+
});
23+
24+
// Copy schema's code that are not present in the method
25+
Object.keys(schemas).forEach(function (key) {
26+
if (schemas.hasOwnProperty(key)) { copyToCodesIfNotPresent(codes, schemas[key].describedBy.responses) }
27+
});
28+
29+
return codes;
30+
}
31+
32+
function copyToCodesIfNotPresent(codes, schemaCodes) {
33+
Object.keys(schemaCodes).forEach(function (code) {
34+
if (schemaCodes.hasOwnProperty(code) && !codes.hasOwnProperty(code)) {
35+
codes[code] = schemaCodes[code];
36+
}
37+
});
38+
}
39+
$scope.fullResponses = mergeResponseCodes($scope.methodInfo.responses || {}, $scope.methodInfo.securitySchemes());
40+
$scope.fullResponseCodes = Object.keys($scope.fullResponses);
41+
42+
1643
$scope.isSchemeSelected = function isSchemeSelected(scheme) {
1744
return scheme.id === $scope.documentationSchemeSelected.id;
1845
};
@@ -37,13 +64,13 @@
3764

3865
$scope.currentStatusCode = '200';
3966

40-
if ($scope.methodInfo.responseCodes && $scope.methodInfo.responseCodes.length > 0) {
41-
$scope.currentStatusCode = $scope.methodInfo.responseCodes[0];
67+
if ($scope.fullResponseCodes && $scope.fullResponseCodes.length > 0) {
68+
$scope.currentStatusCode = $scope.fullResponseCodes[0];
4269
}
4370

4471
$scope.$on('resetData', function() {
45-
if ($scope.methodInfo.responseCodes && $scope.methodInfo.responseCodes.length > 0) {
46-
$scope.currentStatusCode = $scope.methodInfo.responseCodes[0];
72+
if ($scope.fullResponseCodes && $scope.fullResponseCodes.length > 0) {
73+
$scope.currentStatusCode = $scope.fullResponseCodes[0];
4774
}
4875
});
4976

src/app/directives/documentation.tpl.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ <h4 class="raml-console-resource-param-heading">{{formParam[0].displayName}}<spa
108108
</div>
109109

110110
<!-- Response -->
111-
<div ng-if="methodInfo.responseCodes">
111+
<div ng-if="fullResponseCodes">
112112
<header class="raml-console-resource-header">
113113
<h3 class="raml-console-resource-head">
114114
Response
@@ -117,39 +117,39 @@ <h3 class="raml-console-resource-head">
117117

118118
<div class="raml-console-resource-response-jump">
119119
<ul class="raml-console-resource-menu">
120-
<li class="raml-console-resource-btns raml-console-resource-menu-item" ng-repeat="code in methodInfo.responseCodes">
120+
<li class="raml-console-resource-btns raml-console-resource-menu-item" ng-repeat="code in fullResponseCodes">
121121
<button ng-click="showCodeDetails(code)" class="raml-console-resource-btn raml-console-resource-menu-button raml-console-resource-menu-btn-{{getColorCode(code)}}" ng-class="{ 'raml-console-button-is-active': isActiveCode(code) }" href="#code{{code}}">{{code}}</button>
122122
</li>
123123
</ul>
124124
</div>
125125

126126
<div class="raml-console-resource-panel-primary-row raml-console-resource-panel-content raml-console-is-active raml-console-response-container" ng-class="{'raml-console-is-active':showResponseDocumentation}">
127-
<section ng-if="isActiveCode(code)" class="raml-console-resource-section raml-console-resource-response-section" ng-repeat="code in methodInfo.responseCodes">
127+
<section ng-if="isActiveCode(code)" class="raml-console-resource-section raml-console-resource-response-section" ng-repeat="code in fullResponseCodes">
128128
<a name="code{{code}}"></a>
129129
<h3 class="raml-console-resource-heading-a">Status {{code}}</h3>
130130

131131
<div class="raml-console-resource-response">
132-
<p markdown="methodInfo.responses[code].description" class="raml-console-marked-content"></p>
132+
<p markdown="fullResponses[code].description" class="raml-console-marked-content"></p>
133133
</div>
134134

135-
<div class="raml-console-resource-response" ng-if="methodInfo.responses[code].headers">
135+
<div class="raml-console-resource-response" ng-if="fullResponses[code].headers">
136136
<h4 class="raml-console-resource-body-heading">Headers</h4>
137-
<properties list="methodInfo.responses[code].headers"></properties>
137+
<properties list="fullResponses[code].headers"></properties>
138138
</div>
139139

140-
<div class="raml-console-resource-response" ng-if="methodInfo.responses[code].body">
140+
<div class="raml-console-resource-response" ng-if="fullResponses[code].body">
141141
<h4 class="raml-console-resource-body-heading">
142142
Body
143143
<span
144144
ng-click="changeType($event, key, code)"
145145
ng-class="{ 'raml-console-is-active': responseInfo[code].currentType === key}"
146146
class="raml-console-flag"
147-
ng-repeat="(key, value) in methodInfo.responses[code].body">
147+
ng-repeat="(key, value) in fullResponses[code].body">
148148
{{key}}
149149
</span>
150150
</h4>
151151

152-
<div ng-repeat="(key, value) in methodInfo.responses[code].body">
152+
<div ng-repeat="(key, value) in fullResponses[code].body">
153153
<div ng-if="responseInfo[code].currentType === key">
154154
<examples
155155
ng-if="responseInfo[code] && responseInfo[code].currentType"

0 commit comments

Comments
 (0)