Skip to content

Commit 7c7b51a

Browse files
authored
Merge branch 'master' into bugs/repeatable-headers-optional
2 parents 4f8fb66 + f1dc750 commit 7c7b51a

File tree

12 files changed

+15655
-15651
lines changed

12 files changed

+15655
-15651
lines changed

dist/scripts/api-console-vendor.js

Lines changed: 15451 additions & 15619 deletions
Large diffs are not rendered by default.

dist/scripts/api-console.js

Lines changed: 56 additions & 16 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

@@ -3062,6 +3100,8 @@
30623100
return new RAML.Client.AuthStrategies.Oauth2(scheme, credentials);
30633101
case 'OAuth 1.0':
30643102
return new RAML.Client.AuthStrategies.Oauth1(scheme, credentials);
3103+
case 'Pass Through':
3104+
return RAML.Client.AuthStrategies.anonymous();
30653105
case 'x-custom':
30663106
return RAML.Client.AuthStrategies.anonymous();
30673107
case 'Anonymous':
@@ -6595,7 +6635,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
65956635
" </div>\n" +
65966636
"\n" +
65976637
" <!-- Response -->\n" +
6598-
" <div ng-if=\"methodInfo.responseCodes\">\n" +
6638+
" <div ng-if=\"fullResponseCodes\">\n" +
65996639
" <header class=\"raml-console-resource-header\">\n" +
66006640
" <h3 class=\"raml-console-resource-head\">\n" +
66016641
" Response\n" +
@@ -6604,39 +6644,39 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
66046644
"\n" +
66056645
" <div class=\"raml-console-resource-response-jump\">\n" +
66066646
" <ul class=\"raml-console-resource-menu\">\n" +
6607-
" <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" +
66086648
" <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" +
66096649
" </li>\n" +
66106650
" </ul>\n" +
66116651
" </div>\n" +
66126652
"\n" +
66136653
" <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" +
6614-
" <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" +
66156655
" <a name=\"code{{code}}\"></a>\n" +
66166656
" <h3 class=\"raml-console-resource-heading-a\">Status {{code}}</h3>\n" +
66176657
"\n" +
66186658
" <div class=\"raml-console-resource-response\">\n" +
6619-
" <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" +
66206660
" </div>\n" +
66216661
"\n" +
6622-
" <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" +
66236663
" <h4 class=\"raml-console-resource-body-heading\">Headers</h4>\n" +
6624-
" <properties list=\"methodInfo.responses[code].headers\"></properties>\n" +
6664+
" <properties list=\"fullResponses[code].headers\"></properties>\n" +
66256665
" </div>\n" +
66266666
"\n" +
6627-
" <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" +
66286668
" <h4 class=\"raml-console-resource-body-heading\">\n" +
66296669
" Body\n" +
66306670
" <span\n" +
66316671
" ng-click=\"changeType($event, key, code)\"\n" +
66326672
" ng-class=\"{ 'raml-console-is-active': responseInfo[code].currentType === key}\"\n" +
66336673
" class=\"raml-console-flag\"\n" +
6634-
" ng-repeat=\"(key, value) in methodInfo.responses[code].body\">\n" +
6674+
" ng-repeat=\"(key, value) in fullResponses[code].body\">\n" +
66356675
" {{key}}\n" +
66366676
" </span>\n" +
66376677
" </h4>\n" +
66386678
"\n" +
6639-
" <div ng-repeat=\"(key, value) in methodInfo.responses[code].body\">\n" +
6679+
" <div ng-repeat=\"(key, value) in fullResponses[code].body\">\n" +
66406680
" <div ng-if=\"responseInfo[code].currentType === key\">\n" +
66416681
" <examples\n" +
66426682
" ng-if=\"responseInfo[code] && responseInfo[code].currentType\"\n" +
@@ -6700,7 +6740,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
67006740
" <div class=\"raml-console-sidebar-row\">\n" +
67016741
" <p class=\"raml-console-sidebar-input-container raml-console-sidebar-input-container-custom\" ng-repeat=\"customParam in context.customParameters[type]\">\n" +
67026742
" <button class=\"raml-console-sidebar-input-delete\" ng-click=\"removeCutomParam(customParam)\"></button>\n" +
6703-
" <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" +
67046744
" <input class=\"raml-console-sidebar-custom-input-for-label\" ng-model=\"customParam.name\" placeholder=\"custom key\">\n" +
67056745
" </label>\n" +
67066746
" <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/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/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':

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;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>API Console</title>
7+
<link href="styles/api-console-light-theme.css" rel="stylesheet" class="theme">
8+
</head>
9+
<body ng-app="ramlConsoleApp" ng-cloak class="raml-console-body">
10+
<raml-console-loader src="raml/security-schema-pass-though.raml"></raml-console-loader>
11+
<script src="scripts/api-console-vendor.js"></script>
12+
<script src="scripts/api-console.js"></script>
13+
<script type="text/javascript">
14+
$.noConflict();
15+
</script>
16+
</body>
17+
</html>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#%RAML 1.0
2+
title: Gello
3+
baseUri: http://localhost:3000
4+
securitySchemes:
5+
JWT:
6+
type: Pass Through
7+
description:
8+
This API uses JWT to authenticate the requests.
9+
describedBy:
10+
headers:
11+
Authorization:
12+
description: |
13+
Should contain the JWT token.
14+
Format of the value is : bearer $JWT_TOKEN
15+
type: string
16+
responses:
17+
401:
18+
description: Unauthorized
19+
20+
21+
securedBy: [JWT]
22+
23+
/test:
24+
get:

test/regression/page_objects/resourcePO.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ function ResourcesPO () {
3838
return this.getMethodsForResourceAt(resource).get(method).element(by.css('.raml-console-tab-label'));
3939
};
4040

41+
this.getTryItGetBtn = function (index) {
42+
return this.resources.get(index+1).element(by.css('.raml-console-sidebar-action-get'));
43+
};
44+
45+
this.getTryItErrorMessages = function (index) {
46+
return this.resources.get(index+1).all(by.css('.raml-console-sidebar-row > .raml-console-resource-param-instructional'));
47+
};
48+
4149
this.getSecuritySchemes = function (index) {
4250
return this.resources.get(index+1).all(by.tagName('option'));
4351
};

0 commit comments

Comments
 (0)