|
381 | 381 | } |
382 | 382 | } |
383 | 383 |
|
| 384 | + function beautifyCustomSecuritySchemeName (name) { |
| 385 | + return (name.charAt(0).toUpperCase() + name.slice(1)).replace(/_/g, ' '); |
| 386 | + } |
| 387 | + |
384 | 388 | $scope.readTraits = function (traits) { |
385 | 389 | var list = []; |
386 | 390 |
|
|
442 | 446 | type: 'Anonymous' |
443 | 447 | }; |
444 | 448 |
|
| 449 | + Object.keys($scope.securitySchemes).map(function (key) { |
| 450 | + var type = $scope.securitySchemes[key].type; |
| 451 | + |
| 452 | + $scope.securitySchemes[key].name = type; |
| 453 | + $scope.securitySchemes[key].id = type + '|' + key; |
| 454 | + |
| 455 | + if (type === 'x-custom') { |
| 456 | + $scope.securitySchemes[key].name = beautifyCustomSecuritySchemeName(key); |
| 457 | + $scope.securitySchemes[key].id = type + '|' + key; |
| 458 | + } |
| 459 | + }); |
| 460 | + |
445 | 461 | /*jshint camelcase: false */ |
446 | 462 | // Digest Authentication is not supported |
447 | 463 | delete $scope.securitySchemes.digest_auth; |
|
913 | 929 | controller: function ($scope, $location, $anchorScroll) { |
914 | 930 | $scope.markedOptions = RAML.Settings.marked; |
915 | 931 | $scope.currentSchemeType = 'Anonymous'; |
| 932 | + $scope.currentScheme = 'Anonymous|anonymous'; |
916 | 933 | $scope.responseDetails = false; |
917 | 934 |
|
918 | 935 | function completeAnimation (element) { |
|
1172 | 1189 |
|
1173 | 1190 | $scope.context.forceRequest = false; |
1174 | 1191 |
|
| 1192 | + function cleanSchemeMetadata(collection, context) { |
| 1193 | + Object.keys(collection).map(function (key) { |
| 1194 | + if (collection[key][0].isFromSecurityScheme) { |
| 1195 | + delete collection[key]; |
| 1196 | + } |
| 1197 | + |
| 1198 | + if (context.plain[key].definitions[0].isFromSecurityScheme) { |
| 1199 | + delete context.plain[key]; |
| 1200 | + } |
| 1201 | + }); |
| 1202 | + } |
| 1203 | + |
| 1204 | + function updateContextData (type, scheme, collection, context) { |
| 1205 | + var details = $scope.securitySchemes[scheme].describedBy || {}; |
| 1206 | + var securityHeaders = details[type] || {}; |
| 1207 | + |
| 1208 | + if (securityHeaders) { |
| 1209 | + Object.keys(securityHeaders).map(function (key) { |
| 1210 | + if (!securityHeaders[key]) { |
| 1211 | + securityHeaders[key] = { |
| 1212 | + id: key, |
| 1213 | + type: 'string' |
| 1214 | + }; |
| 1215 | + } |
| 1216 | + |
| 1217 | + securityHeaders[key].displayName = key; |
| 1218 | + securityHeaders[key].isFromSecurityScheme = true; |
| 1219 | + collection[key] = [securityHeaders[key]]; |
| 1220 | + |
| 1221 | + context.plain[key] = { |
| 1222 | + definitions: [securityHeaders[key]], |
| 1223 | + selected: securityHeaders[key].type |
| 1224 | + }; |
| 1225 | + context.values[key] = [undefined]; |
| 1226 | + }); |
| 1227 | + } |
| 1228 | + } |
| 1229 | + |
| 1230 | + $scope.securitySchemeChanged = function (scheme) { |
| 1231 | + var info = scheme.split('|'); |
| 1232 | + var type = info[0]; |
| 1233 | + var name = info[1]; |
| 1234 | + |
| 1235 | + $scope.currentSchemeType = type; |
| 1236 | + |
| 1237 | + cleanSchemeMetadata($scope.methodInfo.headers.plain, $scope.context.headers); |
| 1238 | + cleanSchemeMetadata($scope.methodInfo.queryParameters, $scope.context.queryParameters); |
| 1239 | + |
| 1240 | + if (type === 'x-custom') { |
| 1241 | + if (!$scope.methodInfo.headers.plain) { |
| 1242 | + $scope.methodInfo.headers.plain = {}; |
| 1243 | + } |
| 1244 | + |
| 1245 | + updateContextData('headers', name, $scope.methodInfo.headers.plain, $scope.context.headers); |
| 1246 | + updateContextData('queryParameters', name, $scope.methodInfo.queryParameters, $scope.context.queryParameters); |
| 1247 | + } |
| 1248 | + }; |
| 1249 | + |
1175 | 1250 | $scope.tryIt = function ($event) { |
1176 | 1251 | $scope.requestOptions = null; |
1177 | 1252 | $scope.responseDetails = false; |
|
1929 | 2004 | return new RAML.Client.AuthStrategies.Oauth2(scheme, credentials); |
1930 | 2005 | case 'OAuth 1.0': |
1931 | 2006 | return new RAML.Client.AuthStrategies.Oauth1(scheme, credentials); |
| 2007 | + case 'x-custom': |
| 2008 | + return RAML.Client.AuthStrategies.anonymous(); |
1932 | 2009 | default: |
1933 | 2010 | throw new Error('Unknown authentication strategy: ' + scheme.type); |
1934 | 2011 | } |
@@ -5114,7 +5191,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache) |
5114 | 5191 |
|
5115 | 5192 | $templateCache.put('directives/raml-field.tpl.html', |
5116 | 5193 | "<div>\n" + |
5117 | | - " <label for=\"{{param.id}}\" class=\"raml-console-sidebar-label\">{{param.displayName}} <a class=\"raml-console-sidebar-override\" ng-if=\"canOverride(param)\" ng-click=\"overrideField($event, param)\">Override</a> <span class=\"raml-console-side-bar-required-field\" ng-if=\"param.required\">*</span></label>\n" + |
| 5194 | + " <label for=\"{{param.id}}\" class=\"raml-console-sidebar-label\">{{param.displayName}} <a class=\"raml-console-sidebar-override\" ng-if=\"canOverride(param)\" ng-click=\"overrideField($event, param)\">Override</a> <span class=\"raml-console-side-bar-required-field\" ng-if=\"param.required\">*</span><label ng-if=\"param.isFromSecurityScheme\" class=\"raml-console-sidebar-security-label\">from security scheme</label></label>\n" + |
5118 | 5195 | "\n" + |
5119 | 5196 | " <span class=\"raml-console-sidebar-input-tooltip-container raml-console-sidebar-input-left\" ng-if=\"hasExampleValue(param)\">\n" + |
5120 | 5197 | " <button tabindex=\"-1\" class=\"raml-console-sidebar-input-reset\" ng-click=\"reset(param)\"><span class=\"raml-console-visuallyhidden\">Reset field</span></button>\n" + |
@@ -5318,8 +5395,8 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache) |
5318 | 5395 | " <div class=\"raml-console-sidebar-row raml-console-sidebar-securty\">\n" + |
5319 | 5396 | " <div class=\"raml-console-toggle-group raml-console-sidebar-toggle-group\">\n" + |
5320 | 5397 | " <label class=\"raml-console-sidebar-label\">Security Scheme</label>\n" + |
5321 | | - " <select class=\"raml-console-sidebar-input\" ng-model=\"currentSchemeType\" style=\"margin-bottom: 0;\">\n" + |
5322 | | - " <option ng-repeat=\"(key, scheme) in securitySchemes\" value=\"{{scheme.type}}\" ng-selected=\"scheme.type=='Anonymous'\">{{scheme.type}}</option>\n" + |
| 5398 | + " <select ng-change=\"securitySchemeChanged(currentScheme)\" class=\"raml-console-sidebar-input\" ng-model=\"currentScheme\" style=\"margin-bottom: 0;\">\n" + |
| 5399 | + " <option ng-repeat=\"(key, scheme) in securitySchemes\" value=\"{{scheme.id}}\" ng-selected=\"scheme.type=='Anonymous'\">{{scheme.name}}</option>\n" + |
5323 | 5400 | " </select>\n" + |
5324 | 5401 | " </div>\n" + |
5325 | 5402 | " </div>\n" + |
|
0 commit comments