Skip to content

Commit 591d634

Browse files
author
agustin
committed
Merge branch 'master' into bugs/query-parameters-validations
2 parents f74d8aa + ab6cf93 commit 591d634

File tree

14 files changed

+46129
-327587
lines changed

14 files changed

+46129
-327587
lines changed

dist/scripts/api-console-vendor.js

Lines changed: 45910 additions & 327545 deletions
Large diffs are not rendered by default.

dist/scripts/api-console.js

Lines changed: 63 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,53 @@
124124
return {
125125
restrict: 'E',
126126
templateUrl: 'directives/documentation.tpl.html',
127-
replace: true,
128127
controller: ['$scope', function($scope) {
129128
var defaultSchemaKey = Object.keys($scope.securitySchemes).sort()[0];
130129
var defaultSchema = $scope.securitySchemes[defaultSchemaKey];
131130

132131
$scope.markedOptions = RAML.Settings.marked;
133132
$scope.documentationSchemeSelected = defaultSchema;
134133

134+
function mergeResponseCodes(methodCodes, schemas) {
135+
var extractSchema = function (key) { return schemas.hasOwnProperty(key) ? schemas[key] : undefined; };
136+
var isValidSchema = function (schema) { return schema.describedBy && schema.describedBy.responses; };
137+
138+
var codes = {};
139+
140+
// Copy all method codes
141+
Object.keys(methodCodes).forEach(function (code) {
142+
if (methodCodes.hasOwnProperty(code)) { codes[code] = methodCodes[code]; }
143+
});
144+
145+
// Copy schema's code that are not present in the method
146+
Object.keys(schemas)
147+
.map(extractSchema)
148+
.filter(isValidSchema)
149+
.forEach(function (schema) {
150+
copyToCodesIfNotPresent(codes, schema.describedBy.responses);
151+
});
152+
153+
return codes;
154+
}
155+
156+
function copyToCodesIfNotPresent(codes, schemaCodes) {
157+
if (Array.isArray(schemaCodes)) {
158+
schemaCodes.forEach(function (response) {
159+
if (!codes.hasOwnProperty(response.code)) {
160+
codes[response.code] = response.code;
161+
}
162+
});
163+
} else {
164+
Object.keys(schemaCodes).forEach(function (code) {
165+
if (schemaCodes.hasOwnProperty(code) && !codes.hasOwnProperty(code)) {
166+
codes[code] = schemaCodes[code];
167+
}
168+
});
169+
}
170+
}
171+
$scope.fullResponses = mergeResponseCodes($scope.methodInfo.responses || {}, $scope.methodInfo.securitySchemes());
172+
$scope.fullResponseCodes = Object.keys($scope.fullResponses);
173+
135174
$scope.isSchemeSelected = function isSchemeSelected(scheme) {
136175
return scheme.id === $scope.documentationSchemeSelected.id;
137176
};
@@ -156,13 +195,13 @@
156195

157196
$scope.currentStatusCode = '200';
158197

159-
if ($scope.methodInfo.responseCodes && $scope.methodInfo.responseCodes.length > 0) {
160-
$scope.currentStatusCode = $scope.methodInfo.responseCodes[0];
198+
if ($scope.fullResponseCodes && $scope.fullResponseCodes.length > 0) {
199+
$scope.currentStatusCode = $scope.fullResponseCodes[0];
161200
}
162201

163202
$scope.$on('resetData', function() {
164-
if ($scope.methodInfo.responseCodes && $scope.methodInfo.responseCodes.length > 0) {
165-
$scope.currentStatusCode = $scope.methodInfo.responseCodes[0];
203+
if ($scope.fullResponseCodes && $scope.fullResponseCodes.length > 0) {
204+
$scope.currentStatusCode = $scope.fullResponseCodes[0];
166205
}
167206
});
168207

@@ -314,7 +353,8 @@
314353
$elements.removeClass('raml-console-is-active');
315354
$container.find('.raml-console-body-' + $scope.getBodyId(value)).addClass('raml-console-is-active');
316355
});
317-
}]
356+
}],
357+
replace: true
318358
};
319359
};
320360

@@ -3069,6 +3109,8 @@
30693109
return new RAML.Client.AuthStrategies.Oauth2(scheme, credentials);
30703110
case 'OAuth 1.0':
30713111
return new RAML.Client.AuthStrategies.Oauth1(scheme, credentials);
3112+
case 'Pass Through':
3113+
return RAML.Client.AuthStrategies.anonymous();
30723114
case 'x-custom':
30733115
return RAML.Client.AuthStrategies.anonymous();
30743116
case 'Anonymous':
@@ -6280,14 +6322,15 @@ RAML.Inspector = (function() {
62806322
* @return {Object}
62816323
*/
62826324
return function (value, key, object) {
6283-
// Short-circuit validation if the value is `null`.
6284-
if (value == null) {
6285-
return toValidationObject(isOptional, 'required', value, key);
6286-
}
62876325

62886326
// Switch validation type depending on if the value is an array or not.
62896327
var isArray = Array.isArray(value);
62906328

6329+
// Short-circuit validation if empty value
6330+
if (value == null || (isArray && value.length === 0)) {
6331+
return toValidationObject(isOptional, 'required', value, key);
6332+
}
6333+
62916334
// Select the validation stack to use based on the (repeated) value.
62926335
var values = isArray ? value : [value];
62936336
var validations = isArray ? repeatValidations : simpleValidations;
@@ -6603,7 +6646,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
66036646
" </div>\n" +
66046647
"\n" +
66056648
" <!-- Response -->\n" +
6606-
" <div ng-if=\"methodInfo.responseCodes\">\n" +
6649+
" <div ng-if=\"fullResponseCodes\">\n" +
66076650
" <header class=\"raml-console-resource-header\">\n" +
66086651
" <h3 class=\"raml-console-resource-head\">\n" +
66096652
" Response\n" +
@@ -6612,39 +6655,39 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
66126655
"\n" +
66136656
" <div class=\"raml-console-resource-response-jump\">\n" +
66146657
" <ul class=\"raml-console-resource-menu\">\n" +
6615-
" <li class=\"raml-console-resource-btns raml-console-resource-menu-item\" ng-repeat=\"code in methodInfo.responseCodes\">\n" +
6658+
" <li class=\"raml-console-resource-btns raml-console-resource-menu-item\" ng-repeat=\"code in fullResponseCodes\">\n" +
66166659
" <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" +
66176660
" </li>\n" +
66186661
" </ul>\n" +
66196662
" </div>\n" +
66206663
"\n" +
66216664
" <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" +
6622-
" <section ng-if=\"isActiveCode(code)\" class=\"raml-console-resource-section raml-console-resource-response-section\" ng-repeat=\"code in methodInfo.responseCodes\">\n" +
6665+
" <section ng-if=\"isActiveCode(code)\" class=\"raml-console-resource-section raml-console-resource-response-section\" ng-repeat=\"code in fullResponseCodes\">\n" +
66236666
" <a name=\"code{{code}}\"></a>\n" +
66246667
" <h3 class=\"raml-console-resource-heading-a\">Status {{code}}</h3>\n" +
66256668
"\n" +
66266669
" <div class=\"raml-console-resource-response\">\n" +
6627-
" <p markdown=\"methodInfo.responses[code].description\" class=\"raml-console-marked-content\"></p>\n" +
6670+
" <p markdown=\"fullResponses[code].description\" class=\"raml-console-marked-content\"></p>\n" +
66286671
" </div>\n" +
66296672
"\n" +
6630-
" <div class=\"raml-console-resource-response\" ng-if=\"methodInfo.responses[code].headers\">\n" +
6673+
" <div class=\"raml-console-resource-response\" ng-if=\"fullResponses[code].headers\">\n" +
66316674
" <h4 class=\"raml-console-resource-body-heading\">Headers</h4>\n" +
6632-
" <properties list=\"methodInfo.responses[code].headers\"></properties>\n" +
6675+
" <properties list=\"fullResponses[code].headers\"></properties>\n" +
66336676
" </div>\n" +
66346677
"\n" +
6635-
" <div class=\"raml-console-resource-response\" ng-if=\"methodInfo.responses[code].body\">\n" +
6678+
" <div class=\"raml-console-resource-response\" ng-if=\"fullResponses[code].body\">\n" +
66366679
" <h4 class=\"raml-console-resource-body-heading\">\n" +
66376680
" Body\n" +
66386681
" <span\n" +
66396682
" ng-click=\"changeType($event, key, code)\"\n" +
66406683
" ng-class=\"{ 'raml-console-is-active': responseInfo[code].currentType === key}\"\n" +
66416684
" class=\"raml-console-flag\"\n" +
6642-
" ng-repeat=\"(key, value) in methodInfo.responses[code].body\">\n" +
6685+
" ng-repeat=\"(key, value) in fullResponses[code].body\">\n" +
66436686
" {{key}}\n" +
66446687
" </span>\n" +
66456688
" </h4>\n" +
66466689
"\n" +
6647-
" <div ng-repeat=\"(key, value) in methodInfo.responses[code].body\">\n" +
6690+
" <div ng-repeat=\"(key, value) in fullResponses[code].body\">\n" +
66486691
" <div ng-if=\"responseInfo[code].currentType === key\">\n" +
66496692
" <examples\n" +
66506693
" ng-if=\"responseInfo[code] && responseInfo[code].currentType\"\n" +
@@ -6708,7 +6751,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
67086751
" <div class=\"raml-console-sidebar-row\">\n" +
67096752
" <p class=\"raml-console-sidebar-input-container raml-console-sidebar-input-container-custom\" ng-repeat=\"customParam in context.customParameters[type]\">\n" +
67106753
" <button class=\"raml-console-sidebar-input-delete\" ng-click=\"removeCutomParam(customParam)\"></button>\n" +
6711-
" <label for=\"custom-header\" class=\"raml-console-sidebar-label raml-console-sidebar-label-custom\">\n" +
6754+
" <label class=\"raml-console-sidebar-label raml-console-sidebar-label-custom\">\n" +
67126755
" <input class=\"raml-console-sidebar-custom-input-for-label\" ng-model=\"customParam.name\" placeholder=\"custom key\">\n" +
67136756
" </label>\n" +
67146757
" <input name=\"custom-header\" class=\"raml-console-sidebar-input raml-console-sidebar-input-custom\" placeholder=\"custom value\" ng-model=\"customParam.value\">\n" +

src/app/directives/documentation.js

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,53 @@
55
return {
66
restrict: 'E',
77
templateUrl: 'directives/documentation.tpl.html',
8-
replace: true,
98
controller: ['$scope', function($scope) {
109
var defaultSchemaKey = Object.keys($scope.securitySchemes).sort()[0];
1110
var defaultSchema = $scope.securitySchemes[defaultSchemaKey];
1211

1312
$scope.markedOptions = RAML.Settings.marked;
1413
$scope.documentationSchemeSelected = defaultSchema;
1514

15+
function mergeResponseCodes(methodCodes, schemas) {
16+
var extractSchema = function (key) { return schemas.hasOwnProperty(key) ? schemas[key] : undefined; };
17+
var isValidSchema = function (schema) { return schema.describedBy && schema.describedBy.responses; };
18+
19+
var codes = {};
20+
21+
// Copy all method codes
22+
Object.keys(methodCodes).forEach(function (code) {
23+
if (methodCodes.hasOwnProperty(code)) { codes[code] = methodCodes[code]; }
24+
});
25+
26+
// Copy schema's code that are not present in the method
27+
Object.keys(schemas)
28+
.map(extractSchema)
29+
.filter(isValidSchema)
30+
.forEach(function (schema) {
31+
copyToCodesIfNotPresent(codes, schema.describedBy.responses);
32+
});
33+
34+
return codes;
35+
}
36+
37+
function copyToCodesIfNotPresent(codes, schemaCodes) {
38+
if (Array.isArray(schemaCodes)) {
39+
schemaCodes.forEach(function (response) {
40+
if (!codes.hasOwnProperty(response.code)) {
41+
codes[response.code] = response.code;
42+
}
43+
});
44+
} else {
45+
Object.keys(schemaCodes).forEach(function (code) {
46+
if (schemaCodes.hasOwnProperty(code) && !codes.hasOwnProperty(code)) {
47+
codes[code] = schemaCodes[code];
48+
}
49+
});
50+
}
51+
}
52+
$scope.fullResponses = mergeResponseCodes($scope.methodInfo.responses || {}, $scope.methodInfo.securitySchemes());
53+
$scope.fullResponseCodes = Object.keys($scope.fullResponses);
54+
1655
$scope.isSchemeSelected = function isSchemeSelected(scheme) {
1756
return scheme.id === $scope.documentationSchemeSelected.id;
1857
};
@@ -37,13 +76,13 @@
3776

3877
$scope.currentStatusCode = '200';
3978

40-
if ($scope.methodInfo.responseCodes && $scope.methodInfo.responseCodes.length > 0) {
41-
$scope.currentStatusCode = $scope.methodInfo.responseCodes[0];
79+
if ($scope.fullResponseCodes && $scope.fullResponseCodes.length > 0) {
80+
$scope.currentStatusCode = $scope.fullResponseCodes[0];
4281
}
4382

4483
$scope.$on('resetData', function() {
45-
if ($scope.methodInfo.responseCodes && $scope.methodInfo.responseCodes.length > 0) {
46-
$scope.currentStatusCode = $scope.methodInfo.responseCodes[0];
84+
if ($scope.fullResponseCodes && $scope.fullResponseCodes.length > 0) {
85+
$scope.currentStatusCode = $scope.fullResponseCodes[0];
4786
}
4887
});
4988

@@ -195,7 +234,8 @@
195234
$elements.removeClass('raml-console-is-active');
196235
$container.find('.raml-console-body-' + $scope.getBodyId(value)).addClass('raml-console-is-active');
197236
});
198-
}]
237+
}],
238+
replace: true
199239
};
200240
};
201241

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"

src/app/directives/named-parameters.tpl.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ <h4 class="raml-console-sidebar-subhead">{{title}}</h4>
77
<div class="raml-console-sidebar-row">
88
<p class="raml-console-sidebar-input-container raml-console-sidebar-input-container-custom" ng-repeat="customParam in context.customParameters[type]">
99
<button class="raml-console-sidebar-input-delete" ng-click="removeCutomParam(customParam)"></button>
10-
<label for="custom-header" class="raml-console-sidebar-label raml-console-sidebar-label-custom">
10+
<label class="raml-console-sidebar-label raml-console-sidebar-label-custom">
1111
<input class="raml-console-sidebar-custom-input-for-label" ng-model="customParam.name" placeholder="custom key">
1212
</label>
1313
<input name="custom-header" class="raml-console-sidebar-input raml-console-sidebar-input-custom" placeholder="custom value" ng-model="customParam.value">

src/app/directives/properties.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@
5555
};
5656

5757
$scope.isPropertyVisible = function(property) {
58-
return ($scope.showSecuritySchemaProperties || !property[0].isFromSecurityScheme)
59-
&& !isPattern(property[0].displayName);
58+
return ($scope.showSecuritySchemaProperties || !property[0].isFromSecurityScheme) && !isPattern(property[0].displayName);
6059
};
6160

6261
$scope.mergeType = function (type) {

src/common/client/auth_strategies.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
return new RAML.Client.AuthStrategies.Oauth2(scheme, credentials);
1515
case 'OAuth 1.0':
1616
return new RAML.Client.AuthStrategies.Oauth1(scheme, credentials);
17+
case 'Pass Through':
18+
return RAML.Client.AuthStrategies.anonymous();
1719
case 'x-custom':
1820
return RAML.Client.AuthStrategies.anonymous();
1921
case 'Anonymous':

src/vendor/raml-validate/raml-validate.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,15 @@
250250
* @return {Object}
251251
*/
252252
return function (value, key, object) {
253-
// Short-circuit validation if the value is `null`.
254-
if (value == null) {
255-
return toValidationObject(isOptional, 'required', value, key);
256-
}
257253

258254
// Switch validation type depending on if the value is an array or not.
259255
var isArray = Array.isArray(value);
260256

257+
// Short-circuit validation if empty value
258+
if (value == null || (isArray && value.length === 0)) {
259+
return toValidationObject(isOptional, 'required', value, key);
260+
}
261+
261262
// Select the validation stack to use based on the (repeated) value.
262263
var values = isArray ? value : [value];
263264
var validations = isArray ? repeatValidations : simpleValidations;

test/regression/assertions/resource.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ function Resource (poName) {
3333
});
3434
};
3535

36+
this.ifBeAbleToTryIt = function (resource, method) {
37+
var button = this.po.getMethodBtn(resource, method);
38+
var schemes, securitySchemesCount;
39+
40+
button.click();
41+
42+
schemes = this.po.getSecuritySchemes(resource);
43+
securitySchemesCount = schemes.count();
44+
expect(securitySchemesCount).toBe(1);
45+
46+
47+
this.po.getTryItGetBtn(resource).click();
48+
49+
var errorMessages = this.po.getTryItErrorMessages(resource);
50+
expect(errorMessages.count()).toBe(1);
51+
expect(errorMessages.get(0).isDisplayed()).toBe(false);
52+
};
53+
3654
this.ifShowingSecuritySchemes = function (resource, method, expectedSchemes) {
3755
var button = this.po.getMethodBtn(resource, method);
3856
var schemes, securitySchemesCount;

0 commit comments

Comments
 (0)