Skip to content

Commit f706f45

Browse files
author
Carolina Wright
committed
Merge branch 'master' into bugs/response-codes-panel
2 parents a3025c9 + 623c8cd commit f706f45

File tree

16 files changed

+46133
-327592
lines changed

16 files changed

+46133
-327592
lines changed

Gruntfile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ module.exports = function (grunt) {
285285

286286
jshint: {
287287
options: {
288-
jshintrc: true
288+
jshintrc: true,
289+
reporterOutput: ''
289290
},
290291

291292
files: [

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: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,51 @@
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) { copyToCodesIfNotPresent(codes, schema.describedBy.responses); });
150+
151+
return codes;
152+
}
153+
154+
function copyToCodesIfNotPresent(codes, schemaCodes) {
155+
if (Array.isArray(schemaCodes)) {
156+
schemaCodes.forEach(function (response) {
157+
if (!codes.hasOwnProperty(response.code)) {
158+
codes[response.code] = response.code;
159+
}
160+
});
161+
} else {
162+
Object.keys(schemaCodes).forEach(function (code) {
163+
if (schemaCodes.hasOwnProperty(code) && !codes.hasOwnProperty(code)) {
164+
codes[code] = schemaCodes[code];
165+
}
166+
});
167+
}
168+
}
169+
$scope.fullResponses = mergeResponseCodes($scope.methodInfo.responses || {}, $scope.methodInfo.securitySchemes());
170+
$scope.fullResponseCodes = Object.keys($scope.fullResponses);
171+
135172
$scope.isSchemeSelected = function isSchemeSelected(scheme) {
136173
return scheme.id === $scope.documentationSchemeSelected.id;
137174
};
@@ -156,13 +193,13 @@
156193

157194
$scope.currentStatusCode = '200';
158195

159-
if ($scope.methodInfo.responseCodes && $scope.methodInfo.responseCodes.length > 0) {
160-
$scope.currentStatusCode = $scope.methodInfo.responseCodes[0];
196+
if ($scope.fullResponseCodes && $scope.fullResponseCodes.length > 0) {
197+
$scope.currentStatusCode = $scope.fullResponseCodes[0];
161198
}
162199

163200
$scope.$on('resetData', function() {
164-
if ($scope.methodInfo.responseCodes && $scope.methodInfo.responseCodes.length > 0) {
165-
$scope.currentStatusCode = $scope.methodInfo.responseCodes[0];
201+
if ($scope.fullResponseCodes && $scope.fullResponseCodes.length > 0) {
202+
$scope.currentStatusCode = $scope.fullResponseCodes[0];
166203
}
167204
});
168205

@@ -314,7 +351,8 @@
314351
$elements.removeClass('raml-console-is-active');
315352
$container.find('.raml-console-body-' + $scope.getBodyId(value)).addClass('raml-console-is-active');
316353
});
317-
}]
354+
}],
355+
replace: true
318356
};
319357
};
320358

@@ -373,14 +411,15 @@
373411
return [{
374412
name: 'Example',
375413
content: (typeof exampleContainer.example === 'object') ?
376-
JSON.stringify(exampleContainer.example) : exampleContainer.example
414+
JSON.stringify(exampleContainer.example, null, 2) : exampleContainer.example
377415
}];
378416
} else if (exampleContainer.examples) {
379417
if (Array.isArray(exampleContainer.examples)) {
380418
return exampleContainer.examples.map(function (example, index) {
381419
return {
382420
name: example.name || 'Example ' + index,
383-
content: JSON.stringify(example.value, null, 2)
421+
content: (typeof example.value === 'object') ?
422+
JSON.stringify(example.value, null, 2) : example.value
384423
};
385424
});
386425
} else {
@@ -3061,6 +3100,8 @@
30613100
return new RAML.Client.AuthStrategies.Oauth2(scheme, credentials);
30623101
case 'OAuth 1.0':
30633102
return new RAML.Client.AuthStrategies.Oauth1(scheme, credentials);
3103+
case 'Pass Through':
3104+
return RAML.Client.AuthStrategies.anonymous();
30643105
case 'x-custom':
30653106
return RAML.Client.AuthStrategies.anonymous();
30663107
case 'Anonymous':
@@ -6270,14 +6311,15 @@ RAML.Inspector = (function() {
62706311
* @return {Object}
62716312
*/
62726313
return function (value, key, object) {
6273-
// Short-circuit validation if the value is `null`.
6274-
if (value == null) {
6275-
return toValidationObject(isOptional, 'required', value, key);
6276-
}
62776314

62786315
// Switch validation type depending on if the value is an array or not.
62796316
var isArray = Array.isArray(value);
62806317

6318+
// Short-circuit validation if empty value
6319+
if (value == null || (isArray && value.length === 0)) {
6320+
return toValidationObject(isOptional, 'required', value, key);
6321+
}
6322+
62816323
// Select the validation stack to use based on the (repeated) value.
62826324
var values = isArray ? value : [value];
62836325
var validations = isArray ? repeatValidations : simpleValidations;
@@ -6593,7 +6635,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
65936635
" </div>\n" +
65946636
"\n" +
65956637
" <!-- Response -->\n" +
6596-
" <div ng-if=\"methodInfo.responseCodes\">\n" +
6638+
" <div ng-if=\"fullResponseCodes\">\n" +
65976639
" <header class=\"raml-console-resource-header\">\n" +
65986640
" <h3 class=\"raml-console-resource-head\">\n" +
65996641
" Response\n" +
@@ -6602,39 +6644,39 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
66026644
"\n" +
66036645
" <div class=\"raml-console-resource-response-jump\">\n" +
66046646
" <ul class=\"raml-console-resource-menu\">\n" +
6605-
" <li class=\"raml-console-resource-btns raml-console-resource-menu-item\" ng-repeat=\"code in methodInfo.responseCodes\">\n" +
6647+
" <li class=\"raml-console-resource-btns raml-console-resource-menu-item\" ng-repeat=\"code in fullResponseCodes\">\n" +
66066648
" <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" +
66076649
" </li>\n" +
66086650
" </ul>\n" +
66096651
" </div>\n" +
66106652
"\n" +
66116653
" <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" +
6612-
" <section ng-if=\"isActiveCode(code)\" class=\"raml-console-resource-section raml-console-resource-response-section\" ng-repeat=\"code in methodInfo.responseCodes\">\n" +
6654+
" <section ng-if=\"isActiveCode(code)\" class=\"raml-console-resource-section raml-console-resource-response-section\" ng-repeat=\"code in fullResponseCodes\">\n" +
66136655
" <a name=\"code{{code}}\"></a>\n" +
66146656
" <h3 class=\"raml-console-resource-heading-a\">Status {{code}}</h3>\n" +
66156657
"\n" +
66166658
" <div class=\"raml-console-resource-response\">\n" +
6617-
" <p markdown=\"methodInfo.responses[code].description\" class=\"raml-console-marked-content\"></p>\n" +
6659+
" <p markdown=\"fullResponses[code].description\" class=\"raml-console-marked-content\"></p>\n" +
66186660
" </div>\n" +
66196661
"\n" +
6620-
" <div class=\"raml-console-resource-response\" ng-if=\"methodInfo.responses[code].headers\">\n" +
6662+
" <div class=\"raml-console-resource-response\" ng-if=\"fullResponses[code].headers\">\n" +
66216663
" <h4 class=\"raml-console-resource-body-heading\">Headers</h4>\n" +
6622-
" <properties list=\"methodInfo.responses[code].headers\"></properties>\n" +
6664+
" <properties list=\"fullResponses[code].headers\"></properties>\n" +
66236665
" </div>\n" +
66246666
"\n" +
6625-
" <div class=\"raml-console-resource-response\" ng-if=\"methodInfo.responses[code].body\">\n" +
6667+
" <div class=\"raml-console-resource-response\" ng-if=\"fullResponses[code].body\">\n" +
66266668
" <h4 class=\"raml-console-resource-body-heading\">\n" +
66276669
" Body\n" +
66286670
" <span\n" +
66296671
" ng-click=\"changeType($event, key, code)\"\n" +
66306672
" ng-class=\"{ 'raml-console-is-active': responseInfo[code].currentType === key}\"\n" +
66316673
" class=\"raml-console-flag\"\n" +
6632-
" ng-repeat=\"(key, value) in methodInfo.responses[code].body\">\n" +
6674+
" ng-repeat=\"(key, value) in fullResponses[code].body\">\n" +
66336675
" {{key}}\n" +
66346676
" </span>\n" +
66356677
" </h4>\n" +
66366678
"\n" +
6637-
" <div ng-repeat=\"(key, value) in methodInfo.responses[code].body\">\n" +
6679+
" <div ng-repeat=\"(key, value) in fullResponses[code].body\">\n" +
66386680
" <div ng-if=\"responseInfo[code].currentType === key\">\n" +
66396681
" <examples\n" +
66406682
" ng-if=\"responseInfo[code] && responseInfo[code].currentType\"\n" +
@@ -6698,7 +6740,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
66986740
" <div class=\"raml-console-sidebar-row\">\n" +
66996741
" <p class=\"raml-console-sidebar-input-container raml-console-sidebar-input-container-custom\" ng-repeat=\"customParam in context.customParameters[type]\">\n" +
67006742
" <button class=\"raml-console-sidebar-input-delete\" ng-click=\"removeCutomParam(customParam)\"></button>\n" +
6701-
" <label for=\"custom-header\" class=\"raml-console-sidebar-label raml-console-sidebar-label-custom\">\n" +
6743+
" <label class=\"raml-console-sidebar-label raml-console-sidebar-label-custom\">\n" +
67026744
" <input class=\"raml-console-sidebar-custom-input-for-label\" ng-model=\"customParam.name\" placeholder=\"custom key\">\n" +
67036745
" </label>\n" +
67046746
" <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: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,51 @@
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) { copyToCodesIfNotPresent(codes, schema.describedBy.responses); });
31+
32+
return codes;
33+
}
34+
35+
function copyToCodesIfNotPresent(codes, schemaCodes) {
36+
if (Array.isArray(schemaCodes)) {
37+
schemaCodes.forEach(function (response) {
38+
if (!codes.hasOwnProperty(response.code)) {
39+
codes[response.code] = response.code;
40+
}
41+
});
42+
} else {
43+
Object.keys(schemaCodes).forEach(function (code) {
44+
if (schemaCodes.hasOwnProperty(code) && !codes.hasOwnProperty(code)) {
45+
codes[code] = schemaCodes[code];
46+
}
47+
});
48+
}
49+
}
50+
$scope.fullResponses = mergeResponseCodes($scope.methodInfo.responses || {}, $scope.methodInfo.securitySchemes());
51+
$scope.fullResponseCodes = Object.keys($scope.fullResponses);
52+
1653
$scope.isSchemeSelected = function isSchemeSelected(scheme) {
1754
return scheme.id === $scope.documentationSchemeSelected.id;
1855
};
@@ -37,13 +74,13 @@
3774

3875
$scope.currentStatusCode = '200';
3976

40-
if ($scope.methodInfo.responseCodes && $scope.methodInfo.responseCodes.length > 0) {
41-
$scope.currentStatusCode = $scope.methodInfo.responseCodes[0];
77+
if ($scope.fullResponseCodes && $scope.fullResponseCodes.length > 0) {
78+
$scope.currentStatusCode = $scope.fullResponseCodes[0];
4279
}
4380

4481
$scope.$on('resetData', function() {
45-
if ($scope.methodInfo.responseCodes && $scope.methodInfo.responseCodes.length > 0) {
46-
$scope.currentStatusCode = $scope.methodInfo.responseCodes[0];
82+
if ($scope.fullResponseCodes && $scope.fullResponseCodes.length > 0) {
83+
$scope.currentStatusCode = $scope.fullResponseCodes[0];
4784
}
4885
});
4986

@@ -195,7 +232,8 @@
195232
$elements.removeClass('raml-console-is-active');
196233
$container.find('.raml-console-body-' + $scope.getBodyId(value)).addClass('raml-console-is-active');
197234
});
198-
}]
235+
}],
236+
replace: true
199237
};
200238
};
201239

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/examples.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@
3232
return [{
3333
name: 'Example',
3434
content: (typeof exampleContainer.example === 'object') ?
35-
JSON.stringify(exampleContainer.example) : exampleContainer.example
35+
JSON.stringify(exampleContainer.example, null, 2) : exampleContainer.example
3636
}];
3737
} else if (exampleContainer.examples) {
3838
if (Array.isArray(exampleContainer.examples)) {
3939
return exampleContainer.examples.map(function (example, index) {
4040
return {
4141
name: example.name || 'Example ' + index,
42-
content: JSON.stringify(example.value, null, 2)
42+
content: (typeof example.value === 'object') ?
43+
JSON.stringify(example.value, null, 2) : example.value
4344
};
4445
});
4546
} else {

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':

0 commit comments

Comments
 (0)