Skip to content

Commit bff65e9

Browse files
author
agustin
committed
Merge branch 'develop' into features/raml-expander
2 parents 9f663df + 383378a commit bff65e9

File tree

9 files changed

+97
-85
lines changed

9 files changed

+97
-85
lines changed

dist/scripts/api-console.js

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -790,15 +790,17 @@
790790
showSecuritySchemaProperties: '='
791791
},
792792
controller: ['$scope', '$rootScope', function ($scope, $rootScope) {
793-
if (!Array.isArray($scope.list)) {
794-
$scope.listArray = Object.keys($scope.list).map(function (key) {
795-
return $scope.list[key];
796-
});
793+
$scope.$watch('list', function () {
794+
if (!Array.isArray($scope.list)) {
795+
$scope.listArray = Object.keys($scope.list).map(function (key) {
796+
return $scope.list[key];
797+
});
797798

798-
$scope.listArray = RAML.Inspector.Properties.normalizeNamedParameters($scope.listArray);
799-
} else {
800-
$scope.listArray = $scope.list;
801-
}
799+
$scope.listArray = RAML.Inspector.Properties.normalizeNamedParameters($scope.listArray);
800+
} else {
801+
$scope.listArray = $scope.list;
802+
}
803+
});
802804

803805
var getArrayTypes = function(arrayType) {
804806
if (arrayType.items.type || Array.isArray(arrayType.items.type)) {
@@ -1164,18 +1166,15 @@
11641166
$scope.vm.error = void(0);
11651167

11661168
if(RAML.LoaderUtils.ramlOriginValidate(url, $scope.options)) {
1167-
$scope.vm.error = {buffer : 'RAML origin check failed. Raml does not reside underneath the path:' + RAML.LoaderUtils.allowedRamlOrigin($scope.options)};
1169+
$scope.vm.error = {message : 'RAML origin check failed. Raml does not reside underneath the path:' + RAML.LoaderUtils.allowedRamlOrigin($scope.options)};
11681170
} else {
11691171
return ramlParser.loadPath($window.resolveUrl(url), null, $scope.options)
11701172
.then(function (api) {
1171-
$scope.vm.raml = api.specification;
1172-
})
1173-
.catch(function (error) {
1174-
$scope.vm.error = angular.extend(error, {
1175-
/*jshint camelcase: false */
1176-
buffer: (error.context_mark || error.problem_mark).buffer
1177-
/*jshint camelcase: true */
1178-
});
1173+
if (api.errors.length <= 0) {
1174+
$scope.vm.raml = api.specification;
1175+
} else {
1176+
$scope.vm.error = { message: 'Api contains errors.', errors : api.errors};
1177+
}
11791178
})
11801179
.finally(function () {
11811180
$scope.vm.loaded = true;
@@ -1641,7 +1640,6 @@
16411640

16421641
function loadFromUrl(url) {
16431642
$scope.vm.ramlUrl = url;
1644-
16451643
if(RAML.LoaderUtils.ramlOriginValidate(url, $scope.options)) {
16461644
$scope.vm.isLoadedFromUrl = true;
16471645
$scope.vm.error = {message : 'RAML origin check failed. Raml does not reside underneath the path:' + RAML.LoaderUtils.allowedRamlOrigin($scope.options)};
@@ -4652,38 +4650,35 @@ RAML.Inspector = (function() {
46524650
});
46534651
})();
46544652

4655-
(function() {
4653+
(function () {
46564654
'use strict';
46574655

46584656
RAML.LoaderUtils = {
4659-
4660-
allowedRamlOrigin : function(options) {
4661-
var basepath='../';
4662-
if(typeof options.ramlOriginCheck === 'string') {
4657+
allowedRamlOrigin: function (options) {
4658+
var basepath = '../';
4659+
if (typeof options.ramlOriginCheck === 'string') {
46634660
basepath = options.ramlOriginCheck;
46644661
}
46654662
return basepath;
46664663
},
46674664

46684665
// prevent loading stuff from other hosts and/or services
46694666
ramlOriginValidate: function (url, options) {
4670-
var absolutePath = function(href) {
4671-
var link = document.createElement('a');
4672-
link.href = href;
4673-
return link.href;
4667+
var absolutePath = function (href) {
4668+
var link = document.createElement('a');
4669+
link.href = href;
4670+
return link.href;
46744671
};
46754672

4676-
var isSameBasePath = function(href, basepath) {
4677-
var absoluteBasepath=absolutePath(basepath);
4678-
var absoluteRamlPath=absolutePath(href);
4679-
return absoluteRamlPath.indexOf(absoluteBasepath, 0) === 0;
4673+
var isSameBasePath = function (href, basepath) {
4674+
var absoluteBasepath = absolutePath(basepath);
4675+
var absoluteRamlPath = absolutePath(href);
4676+
return absoluteRamlPath.indexOf(absoluteBasepath, 0) === 0;
46804677
};
46814678

4682-
var decodedRamlUrl=decodeURIComponent(url);
4679+
var decodedRamlUrl = decodeURIComponent(url);
46834680
return options && options.ramlOriginCheck && !isSameBasePath(decodedRamlUrl, RAML.LoaderUtils.allowedRamlOrigin(options));
46844681
}
4685-
4686-
46874682
};
46884683
})();
46894684

@@ -7105,17 +7100,12 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
71057100
" </header>\n" +
71067101
"\n" +
71077102
" <div class=\"raml-console-initializer-row\">\n" +
7108-
" <p class=\"raml-console-initializer-input-container\" style=\"height: 550px;\">\n" +
7109-
" <textarea id=\"raml\" ui-codemirror=\"{\n" +
7110-
" gutters: ['CodeMirror-lint-markers'],\n" +
7111-
" lineNumbers: true,\n" +
7112-
" lineWrapping: false,\n" +
7113-
" lint: true,\n" +
7114-
" mode: 'yaml',\n" +
7115-
" tabSize: 2,\n" +
7116-
" theme: 'raml-console'\n" +
7117-
" }\" ng-model=\"vm.error.buffer\"></textarea>\n" +
7118-
" </p>\n" +
7103+
" <div class=\"raml-console-parser-error\">\n" +
7104+
" <span>{{ vm.error.message }}</span>\n" +
7105+
" </div>\n" +
7106+
" <div class=\"raml-console-error-pre\" ng-repeat=\"err in vm.error.errors\">\n" +
7107+
" {{err.message}}\n" +
7108+
" </div>\n" +
71197109
" </div>\n" +
71207110
" </section>\n" +
71217111
" </div>\n" +

src/app/directives/properties.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@
1818
showSecuritySchemaProperties: '='
1919
},
2020
controller: ['$scope', '$rootScope', function ($scope, $rootScope) {
21-
if (!Array.isArray($scope.list)) {
22-
$scope.listArray = Object.keys($scope.list).map(function (key) {
23-
return $scope.list[key];
24-
});
25-
26-
$scope.listArray = RAML.Inspector.Properties.normalizeNamedParameters($scope.listArray);
27-
} else {
28-
$scope.listArray = $scope.list;
29-
}
21+
$scope.$watch('list', function () {
22+
if (!Array.isArray($scope.list)) {
23+
$scope.listArray = Object.keys($scope.list).map(function (key) {
24+
return $scope.list[key];
25+
});
26+
27+
$scope.listArray = RAML.Inspector.Properties.normalizeNamedParameters($scope.listArray);
28+
} else {
29+
$scope.listArray = $scope.list;
30+
}
31+
});
3032

3133
var getArrayTypes = function(arrayType) {
3234
if (arrayType.items.type || Array.isArray(arrayType.items.type)) {

src/app/directives/raml-console-loader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@
4141
$scope.vm.error = void(0);
4242

4343
if(RAML.LoaderUtils.ramlOriginValidate(url, $scope.options)) {
44-
$scope.vm.error = {buffer : 'RAML origin check failed. Raml does not reside underneath the path:' + RAML.LoaderUtils.allowedRamlOrigin($scope.options)};
44+
$scope.vm.error = {message : 'RAML origin check failed. Raml does not reside underneath the path:' + RAML.LoaderUtils.allowedRamlOrigin($scope.options)};
4545
} else {
4646
return ramlParser.loadPath($window.resolveUrl(url), null, $scope.options)
4747
.then(function (api) {
4848
if (api.errors.length <= 0) {
4949
$scope.vm.raml = api.specification;
5050
} else {
51-
$scope.vm.error = { message: 'Api contains errors.'};
51+
$scope.vm.error = { message: 'Api contains errors.', errors : api.errors};
5252
}
5353
})
5454
.finally(function () {

src/app/directives/raml-console-loader.tpl.html

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,12 @@ <h4 class="raml-console-initializer-subhead">Error while parsing</h4>
1313
</header>
1414

1515
<div class="raml-console-initializer-row">
16-
<p class="raml-console-initializer-input-container" style="height: 550px;">
17-
<textarea id="raml" ui-codemirror="{
18-
gutters: ['CodeMirror-lint-markers'],
19-
lineNumbers: true,
20-
lineWrapping: false,
21-
lint: true,
22-
mode: 'yaml',
23-
tabSize: 2,
24-
theme: 'raml-console'
25-
}" ng-model="vm.error.buffer"></textarea>
26-
</p>
16+
<div class="raml-console-parser-error">
17+
<span>{{ vm.error.message }}</span>
18+
</div>
19+
<div class="raml-console-error-pre" ng-repeat="err in vm.error.errors">
20+
{{err.message}}
21+
</div>
2722
</div>
2823
</section>
2924
</div>

src/app/directives/raml-initializer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747

4848
function loadFromUrl(url) {
4949
$scope.vm.ramlUrl = url;
50-
5150
if(RAML.LoaderUtils.ramlOriginValidate(url, $scope.options)) {
5251
$scope.vm.isLoadedFromUrl = true;
5352
$scope.vm.error = {message : 'RAML origin check failed. Raml does not reside underneath the path:' + RAML.LoaderUtils.allowedRamlOrigin($scope.options)};

src/common/loader_utils.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
1-
(function() {
1+
(function () {
22
'use strict';
33

44
RAML.LoaderUtils = {
5-
6-
allowedRamlOrigin : function(options) {
7-
var basepath='../';
8-
if(typeof options.ramlOriginCheck === 'string') {
5+
allowedRamlOrigin: function (options) {
6+
var basepath = '../';
7+
if (typeof options.ramlOriginCheck === 'string') {
98
basepath = options.ramlOriginCheck;
109
}
1110
return basepath;
1211
},
1312

1413
// prevent loading stuff from other hosts and/or services
1514
ramlOriginValidate: function (url, options) {
16-
var absolutePath = function(href) {
17-
var link = document.createElement('a');
18-
link.href = href;
19-
return link.href;
15+
var absolutePath = function (href) {
16+
var link = document.createElement('a');
17+
link.href = href;
18+
return link.href;
2019
};
2120

22-
var isSameBasePath = function(href, basepath) {
23-
var absoluteBasepath=absolutePath(basepath);
24-
var absoluteRamlPath=absolutePath(href);
25-
return absoluteRamlPath.indexOf(absoluteBasepath, 0) === 0;
21+
var isSameBasePath = function (href, basepath) {
22+
var absoluteBasepath = absolutePath(basepath);
23+
var absoluteRamlPath = absolutePath(href);
24+
return absoluteRamlPath.indexOf(absoluteBasepath, 0) === 0;
2625
};
2726

28-
var decodedRamlUrl=decodeURIComponent(url);
27+
var decodedRamlUrl = decodeURIComponent(url);
2928
return options && options.ramlOriginCheck && !isSameBasePath(decodedRamlUrl, RAML.LoaderUtils.allowedRamlOrigin(options));
3029
}
31-
32-
3330
};
3431
})();
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/wrong.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>

test/regression/page_objects/errorPO.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var basePO = require('./basePO');
44

55
function ErrorPO () {
66
this.title = element(by.css('.raml-console-heading'));
7-
this.errorMessage = element(by.css('.raml-console-error-message'));
7+
this.errorMessage = element(by.css('.raml-console-parser-error'));
88
this.errorSnippet = element(by.css('.raml-console-error-snippet'));
99

1010
this.getTitle = function () {

test/regression/standalone/directiveSpec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ var assertions = require('../assertions');
44
var factory = require('../page_objects');
55

66
module.exports = function() {
7+
8+
it('should be able to diplay errors for wrong raml', function () {
9+
// Arrange
10+
var assert = assertions.create('error');
11+
12+
// Act
13+
browser.get('http://localhost:9000/directive-wrong.html');
14+
15+
// Assert
16+
assert.ifErrorMessageIsPresent('Api contains errors.');
17+
});
18+
719
it('should be able to diplay the API title', function () {
820
// Arrange
921
var assert = assertions.create('resource');

0 commit comments

Comments
 (0)