Skip to content

Commit ccd2a78

Browse files
authored
Merge pull request #354 from mulesoft/bugs/query-parameters-validations
Bugs/query parameters validations
2 parents 623c8cd + 853dc8a commit ccd2a78

File tree

11 files changed

+14733
-14543
lines changed

11 files changed

+14733
-14543
lines changed

dist/scripts/api-console-vendor.js

Lines changed: 14679 additions & 14511 deletions
Large diffs are not rendered by default.

dist/scripts/api-console.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@
146146
Object.keys(schemas)
147147
.map(extractSchema)
148148
.filter(isValidSchema)
149-
.forEach(function (schema) { copyToCodesIfNotPresent(codes, schema.describedBy.responses) });
149+
.forEach(function (schema) {
150+
copyToCodesIfNotPresent(codes, schema.describedBy.responses);
151+
});
150152

151153
return codes;
152154
}
@@ -693,6 +695,7 @@
693695
scope: {
694696
src: '=',
695697
context: '=',
698+
types: '=',
696699
type: '@',
697700
title: '@'
698701
},
@@ -823,8 +826,7 @@
823826
};
824827

825828
$scope.isPropertyVisible = function(property) {
826-
return ($scope.showSecuritySchemaProperties || !property[0].isFromSecurityScheme)
827-
&& !isPattern(property[0].displayName);
829+
return ($scope.showSecuritySchemaProperties || !property[0].isFromSecurityScheme) && !isPattern(property[0].displayName);
828830
};
829831

830832
$scope.mergeType = function (type) {
@@ -1480,6 +1482,7 @@
14801482
scope: {
14811483
context: '=',
14821484
type: '=',
1485+
types: '=',
14831486
model: '=',
14841487
param: '='
14851488
},
@@ -2692,7 +2695,7 @@
26922695
var errors;
26932696

26942697
value = typeof value !== 'undefined' && value !== null && value.length === 0 ? undefined : value;
2695-
current[validation.id] = value;
2698+
current[validationId] = value;
26962699

26972700
errors = validator(sanitizer(current)).errors;
26982701

@@ -2701,24 +2704,30 @@
27012704
// Note: We want to allow invalid errors for testing purposes
27022705
return value;
27032706
} else {
2704-
clear(control, validationRules[validation.id]);
2707+
clear(control, validationRules[validationId]);
27052708
return value;
27062709
}
27072710
}
27082711

27092712
var validation = $parse($attrs.validate)($scope);
2713+
var validationId = validation.id;
27102714
var sanitationRules = {};
27112715
var validationRules = {};
27122716
var control = $ctrl;
27132717

2714-
sanitationRules[validation.id] = {
2718+
if (validation && validation.type) {
2719+
var declaredType = RAML.Inspector.Types.findType(validation.type[0], $scope.types);
2720+
if (declaredType) { validation = declaredType; }
2721+
}
2722+
2723+
sanitationRules[validationId] = {
27152724
type: validation.type || null,
27162725
repeat: validation.repeat || null
27172726
};
27182727

2719-
sanitationRules[validation.id] = RAML.Utils.filterEmpty(sanitationRules[validation.id]);
2728+
sanitationRules[validationId] = RAML.Utils.filterEmpty(sanitationRules[validationId]);
27202729

2721-
validationRules[validation.id] = {
2730+
validationRules[validationId] = {
27222731
type: validation.type || null,
27232732
minLength: validation.minLength || null,
27242733
maxLength: validation.maxLength || null,
@@ -2730,7 +2739,7 @@
27302739
repeat: validation.repeat || null
27312740
};
27322741

2733-
validationRules[validation.id] = RAML.Utils.filterEmpty(validationRules[validation.id]);
2742+
validationRules[validationId] = RAML.Utils.filterEmpty(validationRules[validationId]);
27342743

27352744
$ctrl.$formatters.unshift(function(value) {
27362745
return validate(value);
@@ -5744,7 +5753,9 @@ RAML.Inspector = (function() {
57445753
* @return {Boolean}
57455754
*/
57465755
var toBoolean = function (value) {
5747-
return [0, false, '', '0', 'false'].indexOf(value) === -1;
5756+
if ([0, false, '0', 'false'].indexOf(value) !== -1) return false;
5757+
if ([1, true, '1', 'true'].indexOf(value) !== -1) return true;
5758+
return null;
57485759
};
57495760

57505761
/**
@@ -5784,7 +5795,7 @@ RAML.Inspector = (function() {
57845795
*/
57855796
var returnValue = function (value) {
57865797
return value;
5787-
}
5798+
};
57885799

57895800
var toUnion = function (value, key, object, configs) {
57905801
var any = null;
@@ -5795,7 +5806,7 @@ RAML.Inspector = (function() {
57955806
});
57965807

57975808
return any;
5798-
}
5809+
};
57995810

58005811
function isNativeType(typeName) {
58015812
typeName = typeName.replace('[]', '');
@@ -6764,7 +6775,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
67646775
" </span>\n" +
67656776
" </span>\n" +
67666777
"\n" +
6767-
" <raml-field context=\"context\" type=\"type\" param=\"param.definitions[0]\" model=\"context[type].values[param.definitions[0].id]\"></raml-field>\n" +
6778+
" <raml-field context=\"context\" type=\"type\" types=\"types\" param=\"param.definitions[0]\" model=\"context[type].values[param.definitions[0].id]\"></raml-field>\n" +
67686779
" </p>\n" +
67696780
" </div>\n" +
67706781
"</section>\n"
@@ -7040,7 +7051,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
70407051
" </div>\n" +
70417052
"\n" +
70427053
" <div ng-if=\"param.properties\" style=\"padding-left: 10px\">\n" +
7043-
" <raml-field ng-repeat=\"aParam in param.properties\" context=\"context\" type=\"type\" param=\"aParam[0]\" ng-init=\"model[0][aParam[0].name] = [undefined]\" model=\"model[0][aParam[0].name]\"></raml-field>\n" +
7054+
" <raml-field ng-repeat=\"aParam in param.properties\" context=\"context\" type=\"type\" types=\"types\" param=\"aParam[0]\" ng-init=\"model[0][aParam[0].name] = [undefined]\" model=\"model[0][aParam[0].name]\"></raml-field>\n" +
70447055
" </div>\n" +
70457056
"</div>\n"
70467057
);
@@ -7270,7 +7281,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
72707281
"\n" +
72717282
" <named-parameters src=\"methodInfo.headers.plain\" context=\"context\" type=\"headers\" title=\"Headers\" enable-custom-parameters></named-parameters>\n" +
72727283
"\n" +
7273-
" <named-parameters src=\"methodInfo.queryParameters\" context=\"context\" type=\"queryParameters\" title=\"Query Parameters\" enable-custom-parameters></named-parameters>\n" +
7284+
" <named-parameters src=\"methodInfo.queryParameters\" context=\"context\" type=\"queryParameters\" types=\"types\" title=\"Query Parameters\" enable-custom-parameters></named-parameters>\n" +
72747285
"\n" +
72757286
" <section ng-if=\"methodInfo.queryString\">\n" +
72767287
" <header class=\"raml-console-sidebar-row raml-console-sidebar-subheader\">\n" +
@@ -7321,7 +7332,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
73217332
" </span>\n" +
73227333
" </span>\n" +
73237334
"\n" +
7324-
" <raml-field context=\"context\" type=\"type\" param=\"param.definitions[0]\" model=\"context.bodyContent.definitions[context.bodyContent.selected].values[param.definitions[0].id]\"></raml-field>\n" +
7335+
" <raml-field context=\"context\" type=\"type\" types=\"types\" param=\"param.definitions[0]\" model=\"context.bodyContent.definitions[context.bodyContent.selected].values[param.definitions[0].id]\"></raml-field>\n" +
73257336
" </p>\n" +
73267337
" </div>\n" +
73277338
" </div>\n" +

src/app/directives/documentation.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
Object.keys(schemas)
2828
.map(extractSchema)
2929
.filter(isValidSchema)
30-
.forEach(function (schema) { copyToCodesIfNotPresent(codes, schema.describedBy.responses) });
30+
.forEach(function (schema) {
31+
copyToCodesIfNotPresent(codes, schema.describedBy.responses);
32+
});
3133

3234
return codes;
3335
}

src/app/directives/named-parameters.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
scope: {
1010
src: '=',
1111
context: '=',
12+
types: '=',
1213
type: '@',
1314
title: '@'
1415
},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ <h4 class="raml-console-sidebar-subhead">{{title}}</h4>
3030
</span>
3131
</span>
3232

33-
<raml-field context="context" type="type" param="param.definitions[0]" model="context[type].values[param.definitions[0].id]"></raml-field>
33+
<raml-field context="context" type="type" types="types" param="param.definitions[0]" model="context[type].values[param.definitions[0].id]"></raml-field>
3434
</p>
3535
</div>
3636
</section>

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/app/directives/raml-field.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
scope: {
1010
context: '=',
1111
type: '=',
12+
types: '=',
1213
model: '=',
1314
param: '='
1415
},

src/app/directives/raml-field.tpl.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@
5050
</div>
5151

5252
<div ng-if="param.properties" style="padding-left: 10px">
53-
<raml-field ng-repeat="aParam in param.properties" context="context" type="type" param="aParam[0]" ng-init="model[0][aParam[0].name] = [undefined]" model="model[0][aParam[0].name]"></raml-field>
53+
<raml-field ng-repeat="aParam in param.properties" context="context" type="type" types="types" param="aParam[0]" ng-init="model[0][aParam[0].name] = [undefined]" model="model[0][aParam[0].name]"></raml-field>
5454
</div>
5555
</div>

src/app/directives/sidebar.tpl.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ <h4 class="raml-console-sidebar-subhead">Authentication</h4>
5454

5555
<named-parameters src="methodInfo.headers.plain" context="context" type="headers" title="Headers" enable-custom-parameters></named-parameters>
5656

57-
<named-parameters src="methodInfo.queryParameters" context="context" type="queryParameters" title="Query Parameters" enable-custom-parameters></named-parameters>
57+
<named-parameters src="methodInfo.queryParameters" context="context" type="queryParameters" types="types" title="Query Parameters" enable-custom-parameters></named-parameters>
5858

5959
<section ng-if="methodInfo.queryString">
6060
<header class="raml-console-sidebar-row raml-console-sidebar-subheader">
@@ -105,7 +105,7 @@ <h4 class="raml-console-sidebar-subhead">Body</h4>
105105
</span>
106106
</span>
107107

108-
<raml-field context="context" type="type" param="param.definitions[0]" model="context.bodyContent.definitions[context.bodyContent.selected].values[param.definitions[0].id]"></raml-field>
108+
<raml-field context="context" type="type" types="types" param="param.definitions[0]" model="context.bodyContent.definitions[context.bodyContent.selected].values[param.definitions[0].id]"></raml-field>
109109
</p>
110110
</div>
111111
</div>

src/app/directives/validate.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var errors;
1919

2020
value = typeof value !== 'undefined' && value !== null && value.length === 0 ? undefined : value;
21-
current[validation.id] = value;
21+
current[validationId] = value;
2222

2323
errors = validator(sanitizer(current)).errors;
2424

@@ -27,24 +27,30 @@
2727
// Note: We want to allow invalid errors for testing purposes
2828
return value;
2929
} else {
30-
clear(control, validationRules[validation.id]);
30+
clear(control, validationRules[validationId]);
3131
return value;
3232
}
3333
}
3434

3535
var validation = $parse($attrs.validate)($scope);
36+
var validationId = validation.id;
3637
var sanitationRules = {};
3738
var validationRules = {};
3839
var control = $ctrl;
3940

40-
sanitationRules[validation.id] = {
41+
if (validation && validation.type) {
42+
var declaredType = RAML.Inspector.Types.findType(validation.type[0], $scope.types);
43+
if (declaredType) { validation = declaredType; }
44+
}
45+
46+
sanitationRules[validationId] = {
4147
type: validation.type || null,
4248
repeat: validation.repeat || null
4349
};
4450

45-
sanitationRules[validation.id] = RAML.Utils.filterEmpty(sanitationRules[validation.id]);
51+
sanitationRules[validationId] = RAML.Utils.filterEmpty(sanitationRules[validationId]);
4652

47-
validationRules[validation.id] = {
53+
validationRules[validationId] = {
4854
type: validation.type || null,
4955
minLength: validation.minLength || null,
5056
maxLength: validation.maxLength || null,
@@ -56,7 +62,7 @@
5662
repeat: validation.repeat || null
5763
};
5864

59-
validationRules[validation.id] = RAML.Utils.filterEmpty(validationRules[validation.id]);
65+
validationRules[validationId] = RAML.Utils.filterEmpty(validationRules[validationId]);
6066

6167
$ctrl.$formatters.unshift(function(value) {
6268
return validate(value);

0 commit comments

Comments
 (0)