Skip to content

Commit b7dce72

Browse files
authored
Merge pull request #350 from mulesoft/bugs/custom-security-schema-headers
Bugs/custom security schema headers
2 parents 5863d2f + 38ec6c8 commit b7dce72

File tree

9 files changed

+108
-20
lines changed

9 files changed

+108
-20
lines changed

dist/scripts/api-console.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -743,15 +743,16 @@
743743
isNestedProperty: '=',
744744
hideTypeLinks: '=',
745745
hidePropertyDetails: '=',
746-
showExamples: '='
746+
showExamples: '=',
747+
showSecuritySchemaProperties: '='
747748
},
748749
controller: ['$scope', '$rootScope', function ($scope, $rootScope) {
749750
if (!Array.isArray($scope.list)) {
750751
$scope.listArray = Object.keys($scope.list).map(function (key) {
751752
return $scope.list[key];
752753
});
753754

754-
$scope.listArray = RAML.Inspector.Properties.normalizeNamedParameters($scope.list);
755+
$scope.listArray = RAML.Inspector.Properties.normalizeNamedParameters($scope.listArray);
755756
} else {
756757
$scope.listArray = $scope.list;
757758
}
@@ -778,6 +779,15 @@
778779
return newType;
779780
};
780781

782+
var isPattern = function (propertyName) {
783+
return propertyName.match(PATTERN_PATTERN);
784+
};
785+
786+
$scope.isPropertyVisible = function(property) {
787+
return ($scope.showSecuritySchemaProperties || !property[0].isFromSecurityScheme)
788+
&& !isPattern(property[0].displayName);
789+
};
790+
781791
$scope.mergeType = function (type) {
782792
var newType = angular.copy(type);
783793

@@ -789,10 +799,6 @@
789799

790800
$scope.isNativeType = RAML.Inspector.Types.isNativeType;
791801

792-
$scope.isPattern = function (propertyName) {
793-
return propertyName.match(PATTERN_PATTERN);
794-
};
795-
796802
$scope.isSchema = RAML.Inspector.Types.isSchema;
797803

798804
$scope.isCollapsible = function isCollapsible(property) {
@@ -6516,16 +6522,16 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
65166522
" <li class=\"raml-console-documentation-scheme\" ng-class=\"{'raml-console-is-active':isSchemeSelected(value)}\" ng-click=\"selectDocumentationScheme(value)\" ng-repeat=\"(key, value) in securitySchemes\">{{value.name}}</li>\n" +
65176523
" </ol>\n" +
65186524
"\n" +
6519-
" <p ng-if\"documentationSchemeSelected.description\" markdown=\"documentationSchemeSelected.description\" class=\"raml-console-marked-content\"></p>\n" +
6525+
" <p ng-if=\"documentationSchemeSelected.description\" markdown=\"documentationSchemeSelected.description\" class=\"raml-console-marked-content\"></p>\n" +
65206526
"\n" +
65216527
" <section class=\"raml-console-resource-section raml-console-scheme-headers\" ng-if=\"documentationSchemeSelected.describedBy.headers\">\n" +
65226528
" <h4 class=\"raml-console-resource-heading-a\">Headers</h4>\n" +
6523-
" <properties list=\"documentationSchemeSelected.describedBy.headers\" show-examples=\"true\"></properties>\n" +
6529+
" <properties list=\"documentationSchemeSelected.describedBy.headers\" show-security-schema-properties=\"true\" show-examples=\"true\"></properties>\n" +
65246530
" </section>\n" +
65256531
"\n" +
65266532
" <section class=\"raml-console-resource-section raml-console-scheme-query-parameters\" ng-if=\"documentationSchemeSelected.describedBy.queryParameters\">\n" +
65276533
" <h4 class=\"raml-console-resource-heading-a\">Query Parameters</h4>\n" +
6528-
" <properties list=\"documentationSchemeSelected.describedBy.queryParameters\" show-examples=\"true\"></properties>\n" +
6534+
" <properties list=\"documentationSchemeSelected.describedBy.queryParameters\" show-security-schema-properties=\"true\" show-examples=\"true\"></properties>\n" +
65296535
" </section>\n" +
65306536
"\n" +
65316537
" <section class=\"raml-console-resource-section raml-console-scheme-responses\" ng-if=\"documentationSchemeSelected.describedBy.responses\">\n" +
@@ -6725,7 +6731,9 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
67256731

67266732
$templateCache.put('directives/properties.tpl.html',
67276733
"<div>\n" +
6728-
" <div class=\"raml-console-resource-param\" ng-repeat=\"property in listArray\" ng-if=\"!property[0].isFromSecurityScheme && !isPattern(property[0].displayName)\" ng-init=\"vm.isCollapsed = !!collapsible\">\n" +
6734+
" <div class=\"raml-console-resource-param\" ng-repeat=\"property in listArray\"\n" +
6735+
" ng-if=\"isPropertyVisible(property)\"\n" +
6736+
" ng-init=\"vm.isCollapsed = !!collapsible\">\n" +
67296737
" <div ng-init=\"type = getType(property[0])\">\n" +
67306738
" <h4 class=\"raml-console-resource-param-heading\" style=\"position: relative\">\n" +
67316739
" <span ng-if=\"isCollapsible(type)\" ng-click=\"vm.isCollapsed = !vm.isCollapsed\" style=\"cursor: pointer\">{{ vm.isCollapsed ? '▶' : '▼' }}</span>&nbsp;{{type.displayName}}\n" +

src/app/directives/documentation.tpl.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ <h3 class="raml-console-resource-heading-a">Security Schemes</h3>
3636
<li class="raml-console-documentation-scheme" ng-class="{'raml-console-is-active':isSchemeSelected(value)}" ng-click="selectDocumentationScheme(value)" ng-repeat="(key, value) in securitySchemes">{{value.name}}</li>
3737
</ol>
3838

39-
<p ng-if"documentationSchemeSelected.description" markdown="documentationSchemeSelected.description" class="raml-console-marked-content"></p>
39+
<p ng-if="documentationSchemeSelected.description" markdown="documentationSchemeSelected.description" class="raml-console-marked-content"></p>
4040

4141
<section class="raml-console-resource-section raml-console-scheme-headers" ng-if="documentationSchemeSelected.describedBy.headers">
4242
<h4 class="raml-console-resource-heading-a">Headers</h4>
43-
<properties list="documentationSchemeSelected.describedBy.headers" show-examples="true"></properties>
43+
<properties list="documentationSchemeSelected.describedBy.headers" show-security-schema-properties="true" show-examples="true"></properties>
4444
</section>
4545

4646
<section class="raml-console-resource-section raml-console-scheme-query-parameters" ng-if="documentationSchemeSelected.describedBy.queryParameters">
4747
<h4 class="raml-console-resource-heading-a">Query Parameters</h4>
48-
<properties list="documentationSchemeSelected.describedBy.queryParameters" show-examples="true"></properties>
48+
<properties list="documentationSchemeSelected.describedBy.queryParameters" show-security-schema-properties="true" show-examples="true"></properties>
4949
</section>
5050

5151
<section class="raml-console-resource-section raml-console-scheme-responses" ng-if="documentationSchemeSelected.describedBy.responses">

src/app/directives/properties.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@
1414
isNestedProperty: '=',
1515
hideTypeLinks: '=',
1616
hidePropertyDetails: '=',
17-
showExamples: '='
17+
showExamples: '=',
18+
showSecuritySchemaProperties: '='
1819
},
1920
controller: ['$scope', '$rootScope', function ($scope, $rootScope) {
2021
if (!Array.isArray($scope.list)) {
2122
$scope.listArray = Object.keys($scope.list).map(function (key) {
2223
return $scope.list[key];
2324
});
2425

25-
$scope.listArray = RAML.Inspector.Properties.normalizeNamedParameters($scope.list);
26+
$scope.listArray = RAML.Inspector.Properties.normalizeNamedParameters($scope.listArray);
2627
} else {
2728
$scope.listArray = $scope.list;
2829
}
@@ -49,6 +50,15 @@
4950
return newType;
5051
};
5152

53+
var isPattern = function (propertyName) {
54+
return propertyName.match(PATTERN_PATTERN);
55+
};
56+
57+
$scope.isPropertyVisible = function(property) {
58+
return ($scope.showSecuritySchemaProperties || !property[0].isFromSecurityScheme)
59+
&& !isPattern(property[0].displayName);
60+
};
61+
5262
$scope.mergeType = function (type) {
5363
var newType = angular.copy(type);
5464

@@ -60,10 +70,6 @@
6070

6171
$scope.isNativeType = RAML.Inspector.Types.isNativeType;
6272

63-
$scope.isPattern = function (propertyName) {
64-
return propertyName.match(PATTERN_PATTERN);
65-
};
66-
6773
$scope.isSchema = RAML.Inspector.Types.isSchema;
6874

6975
$scope.isCollapsible = function isCollapsible(property) {

src/app/directives/properties.tpl.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<div>
2-
<div class="raml-console-resource-param" ng-repeat="property in listArray" ng-if="!property[0].isFromSecurityScheme && !isPattern(property[0].displayName)" ng-init="vm.isCollapsed = !!collapsible">
2+
<div class="raml-console-resource-param" ng-repeat="property in listArray"
3+
ng-if="isPropertyVisible(property)"
4+
ng-init="vm.isCollapsed = !!collapsible">
35
<div ng-init="type = getType(property[0])">
46
<h4 class="raml-console-resource-param-heading" style="position: relative">
57
<span ng-if="isCollapsible(type)" ng-click="vm.isCollapsed = !vm.isCollapsed" style="cursor: pointer">{{ vm.isCollapsed ? '▶' : '▼' }}</span>&nbsp;{{type.displayName}}

test/regression/assertions/resource.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ function Resource (poName) {
5151
});
5252
};
5353

54+
this.ifShowingSecuritySchemaHeaders = function (resource, method, expectedNOfHeaders, expectedHeaders) {
55+
var button = this.po.getMethodBtn(resource, method);
56+
button.click();
57+
58+
var headers = this.po.getSecuritySchemeHeaderTitles(resource);
59+
var numberOfHeaders = headers.count();
60+
61+
expect(numberOfHeaders).toBe(expectedNOfHeaders);
62+
for(var i = 0; i < expectedHeaders.length; i++) {
63+
expect(headers.get(i).getInnerHtml()).toContain(expectedHeaders[i]);
64+
}
65+
};
66+
5467
this.ifCredentialsUpdateBetweenResources = function () {
5568
var resourcesGetButton= this.po.getMethodBtn(0, 0);
5669
var pageObject = this.po;
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-resource.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 0.8
2+
title: My REST API
3+
version: v1
4+
5+
securitySchemes:
6+
- Custom:
7+
type: x-custom
8+
describedBy:
9+
headers:
10+
Authorization:
11+
description: This header MUST be included in all requests that require authentication/authorization. The auth scheme is using a JSON Web Token Bearer Token as the header value. See [JWT](http://jwt.io/introduction/) for an introduction to JWT. (Though you don't really need to know anything about it)
12+
type: string
13+
required: true
14+
responses:
15+
400:
16+
description: Bad request
17+
401:
18+
description: Unauthorized
19+
403:
20+
description: Forbidden. You are not authorized to access this resource
21+
22+
/endpoint:
23+
get:
24+
securedBy: [ Custom ]

test/regression/page_objects/resourcePO.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,19 @@ function ResourcesPO () {
4141
this.getSecuritySchemes = function (index) {
4242
return this.resources.get(index+1).all(by.tagName('option'));
4343
};
44+
45+
this.getSecuritySchemeHeaderTitles = function (index) {
46+
return this.resources.get(index+1).all(by.css('.raml-console-resource-param-heading'));
47+
};
48+
4449
this.getUsernameField = function () {
4550
return element(by.name('username'));
4651
};
52+
4753
this.getPasswordField = function () {
4854
return element(by.name('password'));
4955
};
56+
5057
this.getCloseBtn = function (index) {
5158
return this.resources.get(index+1).all(by.css('.raml-console-resource-close-btn'));
5259
};

test/regression/standalone/directiveSpec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ module.exports = function() {
4040
assert.ifShowingSecuritySchemes(0, 0, ['Anonymous', 'OAuth 2.0']);
4141
});
4242

43+
it('should be able to display security schemagit status headers', function () {
44+
// Arrange
45+
var assert = assertions.create('resource');
46+
47+
// Act
48+
browser.get('http://localhost:9000/directive-security-schema-resource.html');
49+
50+
// Assert
51+
assert.ifShowingSecuritySchemaHeaders(0, 0, 4, ['Authorization', '400', '401', '403']);
52+
});
53+
4354
it('should be able to cache credentials between resources', function () {
4455
// Arrange
4556
var assert = assertions.create('resource');

0 commit comments

Comments
 (0)