All Downloads are FREE. Search and download functionalities are using the official Maven repository.

assets.scripts.api-console.js Maven / Gradle / Ivy

Go to download

A Wisdom monitor extension that display a RAML Console for the applications raml specs.

The newest version!
(function (window) {
  'use strict';

  // Namespaces
  RAML.Directives     = {};
  RAML.Services       = {};
  RAML.Filters        = {};
  RAML.Services.TryIt = {};
  RAML.Security       = {};
  RAML.Settings       = RAML.Settings || {};

  // Angular Modules
  angular.module('RAML.Directives', []);
  angular.module('RAML.Services', ['raml']);
  angular.module('RAML.Security', []);
  angular.module('ramlConsoleApp', [
    'RAML.Directives',
    'RAML.Services',
    'RAML.Security',
    'hc.marked',
    'ui.codemirror',
    'hljs'
  ]).config(function (hljsServiceProvider) {
    hljsServiceProvider.setOptions({
      classPrefix: 'raml-console-hljs-'
    });
  });

  var loc = window.location;
  var uri = loc.protocol + '//' + loc.host + loc.pathname.replace(/\/$/, '');

  window.hljs.configure({
    classPrefix: 'raml-console-hljs-'
  });

  // Settings
  RAML.Settings.proxy             = RAML.Settings.proxy || false;
  RAML.Settings.oauth2RedirectUri = RAML.Settings.oauth2RedirectUri || uri + '/authentication/oauth2.html';
  RAML.Settings.oauth1RedirectUri = RAML.Settings.oauth1RedirectUri || uri + '/authentication/oauth1.html';
  RAML.Settings.marked            = {
    gfm: true,
    tables: true,
    breaks: true,
    pedantic: false,
    sanitize: false,
    smartLists: true,
    silent: false,
    langPrefix: 'lang-',
    smartypants: false,
    headerPrefix: '',
    renderer: new window.marked.Renderer(),
    xhtml: false,
    highlight: function (code, lang) {
      var result = [
        '
',
        lang ? window.hljs.highlightAuto(code).value : code,
        '
' ]; return result.join(''); } }; })(window); (function () { 'use strict'; RAML.Directives.clickOutside = function ($document) { return { restrict: 'A', link: function ($scope, $element, $attrs) { function onClick (e) { if ($element[0] === e.target || $element.has(e.target).length) { return; } $scope.$apply($attrs.clickOutside); } $document.on('click', onClick); $scope.$on('$destroy', function () { $document.off('click', onClick); }); } }; }; angular.module('RAML.Directives') .directive('clickOutside', RAML.Directives.clickOutside); })(); (function () { 'use strict'; RAML.Directives.closeButton = function() { return { restrict: 'E', templateUrl: 'directives/close-button.tpl.html', replace: true, controller: function($scope) { $scope.close = function () { var $inactiveElements = jQuery('.raml-console-tab').add('.raml-console-resource').add('li'); $inactiveElements.removeClass('raml-console-is-active'); $scope.showPanel = false; $scope.traits = null; $scope.methodInfo = {}; }; } }; }; angular.module('RAML.Directives') .directive('closeButton', RAML.Directives.closeButton); })(); (function () { 'use strict'; RAML.Directives.documentation = function() { return { restrict: 'E', templateUrl: 'directives/documentation.tpl.html', replace: true, controller: function($scope) { var defaultSchemaKey = Object.keys($scope.securitySchemes).sort()[0]; var defaultSchema = $scope.securitySchemes[defaultSchemaKey]; $scope.markedOptions = RAML.Settings.marked; $scope.documentationSchemeSelected = defaultSchema; $scope.isSchemeSelected = function isSchemeSelected(scheme) { return scheme.id === $scope.documentationSchemeSelected.id; }; $scope.selectDocumentationScheme = function selectDocumentationScheme(scheme) { $scope.documentationSchemeSelected = scheme; }; $scope.schemaSettingsDocumentation = function schemaSettingsDocumentation(settings) { var doc = settings; if (typeof settings === 'object') { doc = settings.join(', '); } return doc; }; $scope.unique = function (arr) { return arr.filter (function (v, i, a) { return a.indexOf (v) === i; }); }; $scope.currentStatusCode = '200'; if ($scope.methodInfo.responseCodes && $scope.methodInfo.responseCodes.length > 0) { $scope.currentStatusCode = $scope.methodInfo.responseCodes[0]; } function beautify(body, contentType) { if(contentType.indexOf('json')) { body = vkbeautify.json(body, 2); } if(contentType.indexOf('xml')) { body = vkbeautify.xml(body, 2); } return body; } $scope.getBeatifiedExample = function (value) { var result = value; try { beautify(value, $scope.currentBodySelected); } catch (e) { } return result; }; $scope.getColorCode = function (code) { return code[0] + 'xx'; }; $scope.showCodeDetails = function (code) { $scope.currentStatusCode = code; }; $scope.isActiveCode = function (code) { return $scope.currentStatusCode === code; }; $scope.showRequestDocumentation = true; $scope.toggleRequestDocumentation = function () { $scope.showRequestDocumentation = !$scope.showRequestDocumentation; }; $scope.showResponseDocumentation = true; $scope.toggleResponseDocumentation = function () { $scope.showResponseDocumentation = !$scope.showResponseDocumentation; }; $scope.parameterDocumentation = function (parameter) { var result = ''; if (parameter) { if (parameter.required) { result += 'required, '; } if (parameter.enum) { var enumValues = $scope.unique(parameter.enum); if (enumValues.length > 1) { result += 'one of '; } result += '(' + enumValues.join(', ') + ')'; } else { result += parameter.type || ''; } if (parameter.pattern) { result += ' matching ' + parameter.pattern; } if (parameter.minLength && parameter.maxLength) { result += ', ' + parameter.minLength + '-' + parameter.maxLength + ' characters'; } else if (parameter.minLength && !parameter.maxLength) { result += ', at least ' + parameter.minLength + ' characters'; } else if (parameter.maxLength && !parameter.minLength) { result += ', at most ' + parameter.maxLength + ' characters'; } if (parameter.minimum && parameter.maximum) { result += ' between ' + parameter.minimum + '-' + parameter.maximum; } else if (parameter.minimum && !parameter.maximum) { result += ' ≥ ' + parameter.minimum; } else if (parameter.maximum && !parameter.minimum) { result += ' ≤ ' + parameter.maximum; } if (parameter.repeat) { result += ', repeatable'; } if (parameter['default']) { result += ', default: ' + parameter['default']; } } return result; }; $scope.toggleTab = function ($event) { var $this = jQuery($event.currentTarget); var $eachTab = $this.parent().children('.raml-console-toggle-tab'); var $panel = $this.closest('.raml-console-resource-panel'); var $eachContent = $panel.find('.raml-console-resource-panel-content'); if (!$this.hasClass('raml-console-is-active')) { $eachTab.toggleClass('raml-console-is-active'); $eachContent.toggleClass('raml-console-is-active'); } }; $scope.changeType = function ($event, type, code) { var $this = jQuery($event.currentTarget); var $panel = $this.closest('.raml-console-resource-body-heading'); var $eachContent = $panel.find('span'); $eachContent.removeClass('raml-console-is-active'); $this.addClass('raml-console-is-active'); $scope.responseInfo[code].currentType = type; }; $scope.changeResourceBodyType = function ($event, type) { var $this = jQuery($event.currentTarget); var $panel = $this.closest('.raml-console-request-body-heading'); var $eachContent = $panel.find('span'); $eachContent.removeClass('raml-console-is-active'); $this.addClass('raml-console-is-active'); $scope.currentBodySelected = type; }; $scope.getBodyId = function (bodyType) { return jQuery.trim(bodyType.toString().replace(/\W/g, ' ')).replace(/\s+/g, '_'); }; $scope.bodySelected = function (value) { return value === $scope.currentBodySelected; }; $scope.$watch('currentBodySelected', function (value) { var $container = jQuery('.raml-console-request-body-heading'); var $elements = $container.find('span'); $elements.removeClass('raml-console-is-active'); $container.find('.raml-console-body-' + $scope.getBodyId(value)).addClass('raml-console-is-active'); }); $scope.showSchema = function ($event) { var $this = jQuery($event.currentTarget); var $panel = $this.closest('.raml-console-schema-container'); var $schema = $panel.find('.raml-console-resource-pre-toggle'); $this.toggleClass('raml-console-is-active'); if (!$schema.hasClass('raml-console-is-active')) { $this.text('Hide Schema'); $schema .addClass('raml-console-is-active') .velocity('slideDown'); } else { $this.text('Show Schema'); $schema .removeClass('raml-console-is-active') .velocity('slideUp'); } }; } }; }; angular.module('RAML.Directives') .directive('documentation', RAML.Directives.documentation); })(); (function () { 'use strict'; angular.module('RAML.Directives').directive('dynamicName', ['$parse', function($parse) { return { restrict: 'A', controller: function($scope, $element, $attrs){ var name = $parse($attrs.dynamicName)($scope); delete($attrs.dynamicName); $element.removeAttr('data-dynamic-name'); $element.removeAttr('dynamic-name'); $attrs.$set('name', name); } }; }]); })(); (function () { 'use strict'; RAML.Directives.methodList = function() { return { restrict: 'E', templateUrl: 'directives/method-list.tpl.html', replace: true, controller: function($scope, $location, $anchorScroll, $rootScope) { function loadExamples () { $scope.context.uriParameters.reset($scope.resource.uriParametersForDocumentation); $scope.context.queryParameters.reset($scope.methodInfo.queryParameters); $scope.context.headers.reset($scope.methodInfo.headers.plain); if ($scope.context.bodyContent) { var definitions = $scope.context.bodyContent.definitions; Object.keys(definitions).map(function (key) { if (typeof definitions[key].reset !== 'undefined') { definitions[key].reset($scope.methodInfo.body[key].formParameters); } else { definitions[key].value = definitions[key].contentType.example; } }); } } function getResponseInfo() { var responseInfo = {}; var responses = $scope.methodInfo.responses; if (responses) { Object.keys(responses).map(function (key) { if(responses[key] && typeof responses[key].body !== 'undefined') { responseInfo[key] = {}; Object.keys(responses[key].body).sort().reverse().map(function (type) { responseInfo[key][type] = responses[key].body[type]; responseInfo[key].currentType = type; }); } }); } return responseInfo; } function toUIModel (collection) { if(collection) { Object.keys(collection).map(function (key) { collection[key][0].id = key; }); } } function beautifyCustomSecuritySchemeName (name) { return (name.charAt(0).toUpperCase() + name.slice(1)).replace(/_/g, ' '); } $scope.readTraits = function (traits) { var list = []; var traitList = traits || []; traitList = traitList.concat($scope.resource.traits); traitList.map(function (trait) { if (trait) { if (typeof trait === 'object') { trait = Object.keys(trait).join(', '); } if (list.indexOf(trait) === -1) { list.push(trait); } } }); return list.join(', '); }; $scope.generateId = function (path) { return jQuery.trim(path.toString().replace(/\W/g, ' ')).replace(/\s+/g, '_'); }; var $inactiveElements = jQuery('.raml-console-tab').add('.raml-console-resource') .add('li') .add('.raml-console-tab'); $scope.$on('openMethod', function(event, $currentScope) { if ($scope.$id !== $currentScope.$id) { $inactiveElements.removeClass('raml-console-is-active'); $scope.showPanel = false; } }); $scope.showResource = function ($event, $index) { var $this = jQuery($event.currentTarget); var $resource = $this.closest('.raml-console-resource'); var methodInfo = $scope.resource.methods[$index]; var $inactiveElements = jQuery('.raml-console-tab').add('.raml-console-resource') .add('li') .add('.raml-console-tab'); $scope.methodInfo = methodInfo; $scope.responseInfo = getResponseInfo(); $scope.context = new RAML.Services.TryIt.Context($scope.raml.baseUriParameters, $scope.resource, $scope.methodInfo); $scope.requestUrl = ''; $scope.response = {}; $scope.requestOptions = {}; $scope.requestEnd = false; $scope.showRequestMetadata = false; $scope.showMoreEnable = true; $scope.showSpinner = false; $scope.securitySchemes = $scope.methodInfo.securitySchemes(); $scope.credentials = {}; $scope.traits = $scope.readTraits($scope.methodInfo.is); $scope.context.customParameters = { headers: [], queryParameters: [] }; $scope.currentBodySelected = methodInfo.body ? Object.keys(methodInfo.body)[0] : 'application/json'; toUIModel($scope.methodInfo.queryParameters); toUIModel($scope.methodInfo.headers.plain); toUIModel($scope.resource.uriParametersForDocumentation); Object.keys($scope.securitySchemes).map(function (key) { var type = $scope.securitySchemes[key].type; $scope.securitySchemes[key].name = type; $scope.securitySchemes[key].id = type + '|' + key; if (type === 'x-custom') { $scope.securitySchemes[key].name = beautifyCustomSecuritySchemeName(key); $scope.securitySchemes[key].id = type + '|' + key; } }); $rootScope.$broadcast('resetData'); /*jshint camelcase: false */ // Digest Authentication is not supported delete $scope.securitySchemes.digest_auth; /*jshint camelcase: true */ loadExamples(); // Hack for codemirror setTimeout(function () { var editors = jQuery('.raml-console-sidebar-content-wrapper #sidebar-body .raml-console-codemirror-body-editor .CodeMirror'); editors.map(function (index) { var bodyEditor = editors[index].CodeMirror; if (bodyEditor && $scope.context.bodyContent) { bodyEditor.setOption('mode', $scope.context.bodyContent.selected); bodyEditor.refresh(); } }); }, 10); if (!$resource.hasClass('raml-console-is-active')) { var hash = $scope.generateId($scope.resource.pathSegments); $rootScope.$broadcast('openMethod', $scope); jQuery($this).addClass('raml-console-is-active'); $scope.showPanel = true; $location.hash(hash); $anchorScroll(); } else if (jQuery($this).hasClass('raml-console-is-active')) { $scope.showPanel = false; $inactiveElements.removeClass('raml-console-is-active'); $scope.traits = null; $scope.methodInfo = {}; } else { jQuery($this).addClass('raml-console-is-active'); jQuery($this).siblings('.raml-console-tab').removeClass('raml-console-is-active'); } }; } }; }; angular.module('RAML.Directives') .directive('methodList', RAML.Directives.methodList); })(); (function () { 'use strict'; RAML.Directives.namedParameters = function() { return { restrict: 'E', templateUrl: 'directives/named-parameters.tpl.html', replace: true, scope: { src: '=', context: '=', type: '@', title: '@' }, controller: function ($scope, $attrs) { $scope.markedOptions = RAML.Settings.marked; if ($attrs.hasOwnProperty('enableCustomParameters')) { $scope.enableCustomParameters = true; } if ($attrs.hasOwnProperty('showBaseUrl')) { $scope.showBaseUrl = true; } $scope.segments = []; var baseUri = $scope.$parent.raml.baseUri; if (typeof baseUri !== 'undefined' && baseUri.templated) { var tokens = baseUri.tokens; for (var i = 0; i < tokens.length; i++) { $scope.segments.push({ name: tokens[i], templated: typeof baseUri.parameters[tokens[i]] !== 'undefined' ? true : false }); } } $scope.$parent.resource.pathSegments.map(function (element) { var tokens = element.tokens; for (var i = 0; i < tokens.length; i++) { $scope.segments.push({ name: tokens[i], templated: element.templated && typeof element.parameters[tokens[i]] !== 'undefined' ? true : false }); } }); $scope.addCustomParameter = function () { $scope.context.customParameters[$scope.type].push({}); }; $scope.removeCutomParam = function (param) { $scope.context.customParameters[$scope.type] = $scope.context.customParameters[$scope.type].filter(function (el) { return el.name !== param.name; }); }; } }; }; angular.module('RAML.Directives') .directive('namedParameters', RAML.Directives.namedParameters); })(); (function () { 'use strict'; var generator = window.ramlClientGenerator; function downloadClient (language, ast) { var zip = new window.JSZip(); var output = generator[language](ast); var title = window.slug(output.context.title); Object.keys(output.files).forEach(function (key) { zip.file(key, output.files[key]); }); var content = zip.generate({ type: 'blob' }); var filename = title + '-' + language + '.zip'; // Download as a zip file with an appropriate language name. window.saveAs(content, filename); } RAML.Directives.ramlClientGenerator = function () { return { restrict: 'E', templateUrl: 'directives/raml-client-generator.tpl.html', controller: function ($scope) { $scope.downloadJavaScriptClient = function () { return downloadClient('javascript', $scope.rawRaml); }; } }; }; angular.module('RAML.Directives') .directive('ramlClientGenerator', RAML.Directives.ramlClientGenerator); })(); (function () { 'use strict'; RAML.Directives.ramlField = function() { return { restrict: 'E', templateUrl: 'directives/raml-field.tpl.html', replace: true, scope: { model: '=', param: '=' }, controller: function($scope) { var bodyContent = $scope.$parent.context.bodyContent; var context = $scope.$parent.context[$scope.$parent.type]; if (bodyContent) { context = context || bodyContent.definitions[bodyContent.selected]; } Object.keys(context.plain).map(function (key) { var definition = context.plain[key].definitions[0]; if (typeof definition.enum !== 'undefined') { context.values[definition.id][0] = definition.enum[0]; } }); $scope.canOverride = function (definition) { return definition.type === 'boolean' || typeof definition.enum !== 'undefined'; }; $scope.overrideField = function ($event, definition) { var $this = jQuery($event.currentTarget); var $container = $this.closest('p'); var $el = $container.find('#' + definition.id); var $checkbox = $container.find('#checkbox_' + definition.id); var $select = $container.find('#select_' + definition.id); $el.toggleClass('raml-console-sidebar-override-show'); $checkbox.toggleClass('raml-console-sidebar-override-hide'); $select.toggleClass('raml-console-sidebar-override-hide'); $this.text('Override'); if($el.hasClass('raml-console-sidebar-override-show')) { definition.overwritten = true; $this.text('Cancel override'); } else { definition.overwritten = false; $scope.context[$scope.type].values[definition.id][0] = definition.enum[0]; } }; $scope.onChange = function () { $scope.$parent.context.forceRequest = false; }; $scope.isDefault = function (definition) { return typeof definition.enum === 'undefined' && definition.type !== 'boolean'; }; $scope.isEnum = function (definition) { return typeof definition.enum !== 'undefined'; }; $scope.isBoolean = function (definition) { return definition.type === 'boolean'; }; $scope.hasExampleValue = function (value) { return $scope.isEnum(value) ? false : value.type === 'boolean' ? false : typeof value.enum !== 'undefined' ? false : typeof value.example !== 'undefined' ? true : false; }; $scope.reset = function (param) { var type = $scope.$parent.type || 'bodyContent'; var info = {}; info[param.id] = [param]; $scope.$parent.context[type].reset(info, param.id); }; $scope.unique = function (arr) { return arr.filter (function (v, i, a) { return a.indexOf (v) === i; }); }; } }; }; angular.module('RAML.Directives') .directive('ramlField', RAML.Directives.ramlField); })(); (function () { 'use strict'; RAML.Directives.ramlInitializer = function(ramlParserWrapper) { return { restrict: 'E', templateUrl: 'directives/raml-initializer.tpl.html', replace: true, controller: function($scope, $window) { $scope.ramlUrl = ''; ramlParserWrapper.onParseError(function(error) { /*jshint camelcase: false */ var context = error.context_mark || error.problem_mark; /*jshint camelcase: true */ $scope.errorMessage = error.message; if (context && !$scope.isLoadedFromUrl) { $scope.raml = context.buffer; $window.ramlErrors.line = context.line; $window.ramlErrors.message = error.message; // Hack to update codemirror setTimeout(function () { var editor = jQuery('.raml-console-initializer-input-container .CodeMirror')[0].CodeMirror; editor.addLineClass(context.line, 'background', 'line-error'); editor.doc.setCursor(context.line); }, 10); } $scope.ramlStatus = null; $scope.$apply.apply($scope, null); }); ramlParserWrapper.onParseSuccess(function() { $scope.ramlStatus = 'loaded'; }); $scope.onChange = function () { $scope.errorMessage = null; }; $scope.onKeyPressRamlUrl = function ($event) { if ($event.keyCode === 13) { $scope.loadFromUrl(); } }; $scope.loadFromUrl = function () { if ($scope.ramlUrl) { $scope.isLoadedFromUrl = true; $scope.ramlStatus = 'loading'; ramlParserWrapper.load($scope.ramlUrl); } }; $scope.loadRaml = function() { if ($scope.raml) { $scope.ramlStatus = 'loading'; $scope.isLoadedFromUrl = false; ramlParserWrapper.parse($scope.raml); } }; if (document.location.search.indexOf('?raml=') !== -1) { $scope.ramlUrl = document.location.search.replace('?raml=', ''); $scope.loadFromUrl(); } } }; }; angular.module('RAML.Directives') .directive('ramlInitializer', RAML.Directives.ramlInitializer); })(); (function () { 'use strict'; RAML.Directives.resourcePanel = function() { return { restrict: 'E', templateUrl: 'directives/resource-panel.tpl.html', replace: true }; }; angular.module('RAML.Directives') .directive('resourcePanel', RAML.Directives.resourcePanel); })(); (function () { 'use strict'; RAML.Directives.rootDocumentation = function() { return { restrict: 'E', templateUrl: 'directives/root-documentation.tpl.html', replace: true, controller: function($scope, $location) { $scope.markedOptions = RAML.Settings.marked; $scope.selectedSection = 'all'; $scope.hasDocumentationWithIndex = function () { var regex = /(^#|^##)+\s(.*)$/gim; return $scope.raml.documentation.filter(function (el) { return regex.test(el.content); }).length > 0; }; $scope.generateDocId = function (path) { return jQuery.trim(path.toString().replace(/\W/g, ' ')).replace(/\s+/g, '_').toLowerCase(); }; $scope.toggleSection = function ($event, key, section) { $scope.selectedDocumentSection = key; $scope.documentationEnabled = !$scope.documentationEnabled; $location.hash($scope.generateDocId(section)); }; $scope.closeDocumentation = function ($event) { var $container = jQuery($event.currentTarget).closest('.raml-console-documentation'); $container.toggleClass('raml-console-documentation-active'); $scope.documentationEnabled = false; }; $scope.sectionChange = function (value) { $scope.selectedDocumentSection = value; }; $scope.getDocumentationContent = function (content, selected) { var lines = content.split('\n'); var index = lines.indexOf(selected); var result = []; var regex = /(^#|^##)+\s(.*)$/gim; result.push(lines[index]); for (var i = index+1; i < lines.length; i++) { var line = lines[i]; if (regex.test(line)) { break; } result.push(line); } return !selected || selected === 'all' ? content : result.join('\n'); }; $scope.filterHeaders = function (c) { return c.filter(function (el) { return el.heading <= 2; }); }; $scope.getMarkdownHeaders = function (content) { var headers = content.match(/^#+\s(.*)$/gim); var result = []; var regex = new RegExp(/(^#|^##)+\s(.*)$/gim); if (headers) { var key = headers[0]; headers.map(function(el) { if(el.match(regex) !== null) { key = el; } result.push({ value: key, heading: el.match(/#/g).length, label: el.replace(/#/ig, '').trim() }); }); } return result; }; } }; }; angular.module('RAML.Directives') .directive('rootDocumentation', RAML.Directives.rootDocumentation); })(); (function () { 'use strict'; RAML.Directives.sidebar = function() { return { restrict: 'E', templateUrl: 'directives/sidebar.tpl.html', replace: true, controller: function ($scope, $location, $anchorScroll) { var defaultSchemaKey = Object.keys($scope.securitySchemes).sort()[0]; var defaultSchema = $scope.securitySchemes[defaultSchemaKey]; $scope.markedOptions = RAML.Settings.marked; $scope.currentSchemeType = defaultSchema.type; $scope.currentScheme = defaultSchema.id; $scope.responseDetails = false; $scope.currentProtocol = $scope.raml.protocols[0]; function readCustomSchemeInfo (name) { if (!$scope.methodInfo.headers.plain) { $scope.methodInfo.headers.plain = {}; } updateContextData('headers', name, $scope.methodInfo.headers.plain, $scope.context.headers); updateContextData('queryParameters', name, $scope.methodInfo.queryParameters, $scope.context.queryParameters); } if (defaultSchema.type === 'x-custom') { readCustomSchemeInfo(defaultSchema.id.split('|')[1]); } function completeAnimation (element) { jQuery(element).removeAttr('style'); } function parseHeaders(headers) { var parsed = {}, key, val, i; if (!headers) { return parsed; } headers.split('\n').forEach(function(line) { i = line.indexOf(':'); key = line.substr(0, i).trim().toLowerCase(); val = line.substr(i + 1).trim(); if (key) { if (parsed[key]) { parsed[key] += ', ' + val; } else { parsed[key] = val; } } }); return parsed; } function apply () { $scope.$apply.apply($scope, arguments); } function beautify(body, contentType) { if(contentType.indexOf('json')) { body = vkbeautify.json(body, 2); } if(contentType.indexOf('xml')) { body = vkbeautify.xml(body, 2); } return body; } function handleResponse(jqXhr, err) { $scope.response.status = jqXhr ? jqXhr.status : err ? err.status : 0; if (jqXhr) { $scope.response.headers = parseHeaders(jqXhr.getAllResponseHeaders()); if ($scope.response.headers['content-type']) { $scope.response.contentType = $scope.response.headers['content-type'].split(';')[0]; } $scope.currentStatusCode = jqXhr.status.toString(); try { $scope.response.body = beautify(jqXhr.responseText, $scope.response.contentType); } catch (e) { $scope.response.body = jqXhr.responseText; } } $scope.requestEnd = true; $scope.showMoreEnable = true; $scope.showSpinner = false; $scope.responseDetails = true; var hash = 'request_' + $scope.generateId($scope.resource.pathSegments); $location.hash(hash); $anchorScroll(); // If the response fails because of CORS, responseText is null var editorHeight = 50; if (jqXhr && jqXhr.responseText) { var lines = $scope.response.body.split('\n').length; editorHeight = lines > 100 ? 2000 : 25*lines; } $scope.editorStyle = { height: editorHeight + 'px' }; apply(); } function resolveSegementContexts(pathSegments, uriParameters) { var segmentContexts = []; pathSegments.forEach(function (element) { if (element.templated) { var segment = {}; Object.keys(element.parameters).map(function (key) { segment[key] = uriParameters[key]; }); segmentContexts.push(segment); } else { segmentContexts.push({}); } }); return segmentContexts; } function validateForm(form) { var errors = form.$error; // var uriParams = $scope.context.uriParameters.plain; var flag = false; Object.keys(form.$error).map(function (key) { for (var i = 0; i < errors[key].length; i++) { var fieldName = errors[key][i].$name; // var fieldValue = form[fieldName].$viewValue; form[fieldName].$setViewValue(form[fieldName].$viewValue); // Enforce request without URI parameters // if (typeof uriParams[fieldName] !== 'undefined' && (typeof fieldValue === 'undefined' || fieldValue === '')) { // flag = true; // break; // } } }); if (flag) { $scope.context.forceRequest = false; } } function getParameters (context, type) { var params = {}; var customParameters = context.customParameters[type]; if (!RAML.Utils.isEmpty(context[type].data())) { params = context[type].data(); } if (customParameters.length > 0) { for(var i = 0; i < customParameters.length; i++) { var key = customParameters[i].name; params[key] = []; params[key].push(customParameters[i].value); } } return params; } function clearCustomFields (types) { types.map(function (type) { var custom = $scope.context.customParameters[type]; for (var i = 0; i < custom.length; i++) { custom[i].value = ''; } }); } $scope.$on('resetData', function() { var defaultSchemaKey = Object.keys($scope.securitySchemes).sort()[0]; var defaultSchema = $scope.securitySchemes[defaultSchemaKey]; $scope.currentSchemeType = defaultSchema.type; $scope.currentScheme = defaultSchema.id; $scope.currentProtocol = $scope.raml.protocols[0]; $scope.documentationSchemeSelected = defaultSchema; $scope.responseDetails = null; }); $scope.cancelRequest = function () { $scope.showSpinner = false; }; $scope.prefillBody = function (current) { var definition = $scope.context.bodyContent.definitions[current]; definition.value = definition.contentType.example; }; $scope.clearFields = function () { $scope.context.uriParameters.clear($scope.resource.uriParametersForDocumentation); $scope.context.queryParameters.clear($scope.methodInfo.queryParameters); $scope.context.headers.clear($scope.methodInfo.headers.plain); if ($scope.context.bodyContent) { $scope.context.bodyContent.definitions[$scope.context.bodyContent.selected].value = ''; } $scope.context.forceRequest = false; if ($scope.credentials) { Object.keys($scope.credentials).map(function (key) { $scope.credentials[key] = ''; }); } clearCustomFields(['headers', 'queryParameters']); if ($scope.context.bodyContent) { var current = $scope.context.bodyContent.selected; var definition = $scope.context.bodyContent.definitions[current]; if (typeof definition.clear !== 'undefined') { definition.clear($scope.methodInfo.body[current].formParameters); } else { definition.value = ''; } } }; $scope.resetFormParameter = function (param) { var current = $scope.context.bodyContent.selected; var definition = $scope.context.bodyContent.definitions[current]; definition.reset($scope.methodInfo.body[current].formParameters, param.id); }; $scope.resetFields = function () { $scope.context.uriParameters.reset($scope.resource.uriParametersForDocumentation); $scope.context.queryParameters.reset($scope.methodInfo.queryParameters); $scope.context.headers.reset($scope.methodInfo.headers.plain); if ($scope.context.bodyContent) { var current = $scope.context.bodyContent.selected; var definition = $scope.context.bodyContent.definitions[current]; if (typeof definition.reset !== 'undefined') { definition.reset($scope.methodInfo.body[current].formParameters); } else { definition.value = definition.contentType.example; } } $scope.context.forceRequest = false; }; $scope.requestBodySelectionChange = function (bodyType) { $scope.currentBodySelected = bodyType; }; $scope.toggleBodyType = function ($event, bodyType) { var $this = jQuery($event.currentTarget); var $panel = $this.closest('.raml-console-sidebar-toggle-type').find('button'); $panel.removeClass('raml-console-is-active'); $this.addClass('raml-console-is-active'); $scope.context.bodyContent.selected = bodyType; }; $scope.getHeaderValue = function (header) { if (typeof header === 'string') { return header; } return header[0]; }; $scope.hasExampleValue = function (value) { return typeof value !== 'undefined' ? true : false; }; $scope.context.forceRequest = false; function cleanSchemeMetadata(collection, context) { if (collection) { Object.keys(collection).map(function (key) { if (collection[key][0].isFromSecurityScheme) { delete collection[key]; } if (context.plain[key].definitions[0].isFromSecurityScheme) { delete context.plain[key]; } }); } } function updateContextData (type, scheme, collection, context) { var details = $scope.securitySchemes[scheme].describedBy || {}; var securityHeaders = details[type] || {}; if (securityHeaders) { Object.keys(securityHeaders).map(function (key) { if (!securityHeaders[key]) { securityHeaders[key] = { id: key, type: 'string' }; } securityHeaders[key].displayName = key; securityHeaders[key].isFromSecurityScheme = true; collection[key] = [securityHeaders[key]]; context.plain[key] = { definitions: [securityHeaders[key]], selected: securityHeaders[key].type }; context.values[key] = [undefined]; }); } } $scope.protocolChanged = function protocolChanged(protocol) { $scope.currentProtocol = protocol; }; $scope.securitySchemeChanged = function securitySchemeChanged(scheme) { var info = scheme.split('|'); var type = info[0]; var name = info[1]; $scope.currentSchemeType = type; $scope.context.forceRequest = false; cleanSchemeMetadata($scope.methodInfo.headers.plain, $scope.context.headers); cleanSchemeMetadata($scope.methodInfo.queryParameters, $scope.context.queryParameters); $scope.documentationSchemeSelected = $scope.securitySchemes[name]; if (type === 'x-custom') { readCustomSchemeInfo(name); } }; $scope.tryIt = function ($event) { $scope.requestOptions = null; $scope.responseDetails = false; $scope.response = {}; validateForm($scope.form); if (!$scope.context.forceRequest) { jQuery($event.currentTarget).closest('form').find('.ng-invalid').first().focus(); } if($scope.context.forceRequest || $scope.form.$valid) { var url; var context = $scope.context; var segmentContexts = resolveSegementContexts($scope.resource.pathSegments, $scope.context.uriParameters.data()); $scope.showSpinner = true; $scope.toggleRequestMetadata($event, true); try { var pathBuilder = context.pathBuilder; var client = RAML.Client.create($scope.raml, function(client) { if ($scope.raml.baseUriParameters) { Object.keys($scope.raml.baseUriParameters).map(function (key) { var uriParameters = $scope.context.uriParameters.data(); pathBuilder.baseUriContext[key] = uriParameters[key][0]; delete uriParameters[key]; }); } client.baseUriParameters(pathBuilder.baseUriContext); }); client.baseUri = client.baseUri.replace(/(https)|(http)/, $scope.currentProtocol.toLocaleLowerCase()); url = client.baseUri + pathBuilder(segmentContexts); } catch (e) { $scope.response = {}; return; } var request = RAML.Client.Request.create(url, $scope.methodInfo.method); $scope.parameters = getParameters(context, 'queryParameters'); request.queryParams($scope.parameters); request.headers(getParameters(context, 'headers')); if (context.bodyContent) { request.header('Content-Type', context.bodyContent.selected); request.data(context.bodyContent.data()); } var authStrategy; try { var securitySchemes = $scope.methodInfo.securitySchemes(); var scheme; Object.keys(securitySchemes).map(function(key) { if (securitySchemes[key].type === $scope.currentSchemeType) { scheme = securitySchemes && securitySchemes[key]; return; } }); //// TODO: Make a uniform interface if (scheme && scheme.type === 'OAuth 2.0') { authStrategy = new RAML.Client.AuthStrategies.Oauth2(scheme, $scope.credentials); authStrategy.authenticate(request.toOptions(), function (jqXhr, err) { $scope.requestOptions = request.toOptions(); handleResponse(jqXhr, err); }); return; } authStrategy = RAML.Client.AuthStrategies.for(scheme, $scope.credentials); authStrategy.authenticate().then(function(token) { token.sign(request); $scope.requestOptions = request.toOptions(); jQuery.ajax(request.toOptions()).then( function(data, textStatus, jqXhr) { handleResponse(jqXhr); }, function(jqXhr) { handleResponse(jqXhr); } ); }); $scope.requestOptions = request.toOptions(); } catch (e) { // custom strategies aren't supported yet. } } else { $scope.context.forceRequest = true; } }; $scope.documentationEnabled = true; $scope.closeSidebar = function ($event) { var $this = jQuery($event.currentTarget); var $panel = $this.closest('.raml-console-resource-panel'); var $sidebar = $panel.find('.raml-console-sidebar'); var sidebarWidth = 0; if (jQuery(window).width() > 960) { sidebarWidth = 430; } $scope.documentationEnabled = true; $sidebar.velocity( { width: 0 }, { duration: 200, complete: function (element) { jQuery(element).removeAttr('style'); $sidebar.removeClass('raml-console-is-fullscreen'); } } ); $sidebar.toggleClass('raml-console-is-collapsed'); $sidebar.removeClass('raml-console-is-responsive'); $panel.toggleClass('raml-console-has-sidebar-collapsed'); }; $scope.toggleSidebar = function ($event) { var $this = jQuery($event.currentTarget); var $panel = $this.closest('.raml-console-resource-panel'); var $sidebar = $panel.find('.raml-console-sidebar'); var sidebarWidth = 0; if (jQuery(window).width() > 960) { sidebarWidth = 430; } if ($sidebar.hasClass('raml-console-is-fullscreen')) { $scope.documentationEnabled = true; $sidebar.velocity( { width: $scope.singleView ? 0 : sidebarWidth }, { duration: 200, complete: function (element) { jQuery(element).removeAttr('style'); $sidebar.removeClass('raml-console-is-fullscreen'); } } ); $sidebar.removeClass('raml-console-is-responsive'); $panel.removeClass('raml-console-has-sidebar-fullscreen'); } else { $sidebar.velocity( { width: '100%' }, { duration: 200, complete: function (element) { jQuery(element).removeAttr('style'); $scope.documentationEnabled = false; apply(); } } ); $sidebar.addClass('raml-console-is-fullscreen'); $sidebar.addClass('raml-console-is-responsive'); $panel.addClass('raml-console-has-sidebar-fullscreen'); } if ($scope.singleView) { $sidebar.toggleClass('raml-console-is-collapsed'); $panel.toggleClass('raml-console-has-sidebar-collapsed'); } }; $scope.collapseSidebar = function ($event) { var $this = jQuery($event.currentTarget); var $panel = $this.closest('.raml-console-resource-panel'); var $panelContent = $panel.find('.raml-console-resource-panel-primary'); var $sidebar = $panel.find('.raml-console-sidebar'); var animation = 430; var speed = 200; if ((!$sidebar.hasClass('raml-console-is-fullscreen') && !$sidebar.hasClass('raml-console-is-collapsed')) || $sidebar.hasClass('raml-console-is-responsive')) { animation = 0; } if ($scope.singleView) { $panel.toggleClass('raml-console-has-sidebar-fullscreen'); speed = 0; } $sidebar.velocity( { width: animation }, { duration: speed, complete: function (element) { jQuery(element).removeAttr('style'); if ($scope.singleView) { $scope.documentationEnabled = false; } apply(); } } ); $panelContent.velocity( { 'padding-right': animation }, { duration: speed, complete: completeAnimation } ); $sidebar.toggleClass('raml-console-is-collapsed'); $sidebar.removeClass('raml-console-is-responsive'); $panel.toggleClass('raml-console-has-sidebar-collapsed'); if ($sidebar.hasClass('raml-console-is-fullscreen') || $scope.singleView) { $sidebar.toggleClass('raml-console-is-fullscreen'); } }; $scope.toggleRequestMetadata = function (enabled) { if ($scope.showRequestMetadata && !enabled) { $scope.showRequestMetadata = false; } else { $scope.showRequestMetadata = true; } }; $scope.showResponseMetadata = true; $scope.toggleResponseMetadata = function () { $scope.showResponseMetadata = !$scope.showResponseMetadata; }; } }; }; angular.module('RAML.Directives') .directive('sidebar', RAML.Directives.sidebar); })(); (function () { 'use strict'; RAML.Directives.spinner = function() { return { restrict: 'E', templateUrl: 'directives/spinner.tpl.html', replace: true, link: function($scope, $element) { $scope.$on('loading-started', function() { $element.css({ 'display': ''}); }); $scope.$on('loading-complete', function() { $element.css({ 'display': 'none' }); }); } }; }; angular.module('RAML.Directives') .directive('spinner', RAML.Directives.spinner); })(); (function () { 'use strict'; RAML.Directives.theme = function() { return { restrict: 'E', templateUrl: 'directives/theme-switcher.tpl.html', replace: true, link: function($scope, $element) { $element.on('click', function() { // var $link = jQuery('head link.theme'); var $theme = jQuery('head').find('#raml-console-theme-dark'); // $link.attr('href', 'styles/light-theme.css'); // $element.removeClass('raml-console-theme-toggle-dark'); if ($theme.length === 0) { jQuery.ajax({ url: 'styles/api-console-dark-theme.css' }).done(function (data) { jQuery('head').append(''); jQuery('head').find('#raml-console-theme-light').remove(); }); } else { jQuery.ajax({ url: 'styles/api-console-light-theme.css' }).done(function (data) { jQuery('head').append(''); jQuery('head').find('#raml-console-theme-dark').remove(); }); } }); } }; }; angular.module('RAML.Directives') .directive('themeSwitcher', RAML.Directives.theme); })(); (function () { 'use strict'; RAML.Directives.validate = function($parse) { return { require: 'ngModel', link: function ($scope, $element, $attrs, $ctrl) { function clear ($ctrl, rules) { Object.keys(rules).map(function (key) { $ctrl.$setValidity(key, true); }); } function validate(value) { var sanitizer = (new RAMLSanitize())(sanitationRules); var validator = (new RAMLValidate())(validationRules); var current = {}; var errors; value = typeof value !== 'undefined' && value !== null && value.length === 0 ? undefined : value; current[validation.id] = value; errors = validator(sanitizer(current)).errors; if (errors.length > 0) { control.$setValidity(errors[0].rule, errors[0].valid); // Note: We want to allow invalid errors for testing purposes return value; } else { clear(control, validationRules[validation.id]); return value; } } var validation = $parse($attrs.validate)($scope); var sanitationRules = {}; var validationRules = {}; var control = $ctrl; sanitationRules[validation.id] = { type: validation.type || null, repeat: validation.repeat || null }; sanitationRules[validation.id] = RAML.Utils.filterEmpty(sanitationRules[validation.id]); validationRules[validation.id] = { type: validation.type || null, minLength: validation.minLength || null, maxLength: validation.maxLength || null, required: validation.required || null, enum: validation.enum || null, pattern: validation.pattern || null, minimum: validation.minimum || null, maximum: validation.maximum || null, repeat: validation.repeat || null }; validationRules[validation.id] = RAML.Utils.filterEmpty(validationRules[validation.id]); $ctrl.$formatters.unshift(function(value) { return validate(value); }); $ctrl.$parsers.unshift(function(value) { return validate(value); }); } }; }; angular.module('RAML.Directives') .directive('validate', RAML.Directives.validate); })(); (function () { 'use strict'; angular.module('raml', []) .factory('ramlParser', function () { return RAML.Parser; }); })(); (function () { 'use strict'; RAML.Directives.resourceType = function() { return { restrict: 'E', templateUrl: 'resources/resource-type.tpl.html', replace: true, controller: function ($scope) { var resourceType = $scope.resource.resourceType; if (typeof resourceType === 'object') { $scope.resource.resourceType = Object.keys(resourceType).join(); } } }; }; angular.module('RAML.Directives') .directive('resourceType', RAML.Directives.resourceType); })(); (function () { 'use strict'; RAML.Directives.resources = function(ramlParserWrapper) { return { restrict: 'E', templateUrl: 'resources/resources.tpl.html', replace: true, scope: { src: '@' }, controller: function($scope, $window, $attrs) { $scope.proxy = $window.RAML.Settings.proxy; $scope.disableTitle = false; $scope.resourcesCollapsed = false; $scope.documentationCollapsed = false; if ($attrs.hasOwnProperty('singleView')) { $scope.singleView = true; } if ($attrs.hasOwnProperty('disableThemeSwitcher')) { $scope.disableThemeSwitcher = true; } if ($attrs.hasOwnProperty('disableRamlClientGenerator')) { $scope.disableRamlClientGenerator = true; } if ($attrs.hasOwnProperty('disableTitle')) { $scope.disableTitle = true; } if ($attrs.hasOwnProperty('resourcesCollapsed')) { $scope.resourcesCollapsed = true; } if ($attrs.hasOwnProperty('documentationCollapsed')) { $scope.documentationCollapsed = true; } if ($scope.src) { ramlParserWrapper.load($scope.src); } $scope.readResourceTraits = function readResourceTraits(traits) { var list = []; if (traits) { traits.map(function (trait) { if (trait) { if (typeof trait === 'object') { list.push(Object.keys(trait).join(', ')); } else { list.push(trait); } } }); } return list.join(', '); }; $scope.updateProxyConfig = function (status) { $window.RAML.Settings.disableProxy = status; }; $scope.toggle = function ($event, index, collection, flagKey) { var $this = jQuery($event.currentTarget); var $section = $this .closest('.raml-console-resource-list-item') .find('.raml-console-resource-list'); if ($section.hasClass('raml-console-is-collapsed')) { $section.velocity('slideDown', { duration: 200 }); } else { $section.velocity('slideUp', { duration: 200 }); } collection[index] = !collection[index]; $scope[flagKey] = checkItemStatus(false, collection) ? false : $scope[flagKey]; $scope[flagKey] = checkItemStatus(true, collection) ? true : $scope[flagKey]; $section.toggleClass('raml-console-is-collapsed'); }; $scope.collapseAll = function ($event, collection, flagKey) { var $this = jQuery($event.currentTarget); if ($this.hasClass('raml-console-resources-expanded')) { $scope[flagKey] = true; jQuery('.raml-console-resources-' + flagKey).find('ol.raml-console-resource-list').velocity('slideUp', { duration: 200 }); } else { if (flagKey === 'resourcesCollapsed') { jQuery('.raml-console-resource-description').removeClass('ng-hide'); } $scope[flagKey] = false; jQuery('.raml-console-resources-' + flagKey).find('ol.raml-console-resource-list').velocity('slideDown', { duration: 200 }); } toggleCollapsed($scope[flagKey], collection); }; function toggleCollapsed (status, collection) { for (var i = 0; i < collection.length; i++) { collection[i] = collection[i] !== null ? status : collection[i]; } } function checkItemStatus(status, collection) { return collection.filter(function (el) { return el === status || el === null; }).length === collection.length; } $scope.hasResourcesWithChilds = function () { return $scope.raml.resourceGroups.filter(function (el) { return el.length > 1; }).length > 0; }; }, link: function($scope) { ramlParserWrapper.onParseSuccess(function(raml) { $scope.raml = RAML.Inspector.create(raml); $scope.rawRaml = raml; $scope.loaded = true; $scope.resourceList = []; $scope.documentList = []; for (var i = 0; i < $scope.raml.resourceGroups.length; i++) { var resources = $scope.raml.resourceGroups[i]; var status = resources.length > 1 ? false : null; $scope.resourceList.push($scope.resourcesCollapsed ? true : status); } if ($scope.raml.documentation) { for (var j = 0; j < $scope.raml.documentation.length; j++) { $scope.documentList.push($scope.documentationCollapsed ? true : false); } } }); } }; }; angular.module('RAML.Directives') .directive('ramlConsole', RAML.Directives.resources); })(); (function () { 'use strict'; RAML.Security.basicAuth = function() { return { restrict: 'E', templateUrl: 'security/basic_auth.tpl.html', replace: true, scope: { credentials: '=' }, controller: function ($scope) { $scope.onChange = function () { $scope.$parent.context.forceRequest = false; }; } }; }; angular.module('RAML.Security') .directive('basicAuth', RAML.Security.basicAuth); })(); (function () { 'use strict'; RAML.Security.oauth1 = function() { return { restrict: 'E', templateUrl: 'security/oauth1.tpl.html', replace: true, scope: { credentials: '=' }, controller: function ($scope) { $scope.onChange = function () { $scope.$parent.context.forceRequest = false; }; } }; }; angular.module('RAML.Security') .directive('oauth1', RAML.Security.oauth1); })(); (function () { 'use strict'; RAML.Security.oauth2 = function() { return { restrict: 'E', templateUrl: 'security/oauth2.tpl.html', replace: true, controller: function ($scope) { $scope.onChange = function () { $scope.$parent.context.forceRequest = false; }; $scope.ownerOptionsEnabled = function () { return $scope.credentials.grant === 'owner'; }; $scope.isImplicitEnabled = function () { return $scope.credentials.grant === 'token'; }; $scope.grants = [ { label: 'Implicit', value: 'token' }, { label: 'Authorization Code', value: 'code' }, { label: 'Resource Owner Password Credentials', value: 'owner' }, { label: 'Client Credentials', value: 'credentials' } ]; /* jshint camelcase: false */ var authorizationGrants = $scope.$parent.securitySchemes.oauth_2_0.settings.authorizationGrants; $scope.scopes = $scope.$parent.securitySchemes.oauth_2_0.settings.scopes; $scope.credentials.scopes = {}; if (authorizationGrants) { $scope.grants = $scope.grants.filter(function (el) { return authorizationGrants.indexOf(el.value) > -1; }); } /* jshint camelcase: true */ $scope.credentials.grant = $scope.grants[0].value; } }; }; angular.module('RAML.Security') .directive('oauth2', RAML.Security.oauth2); })(); (function () { 'use strict'; RAML.Services.RAMLParserWrapper = function($rootScope, ramlParser, $q) { var ramlProcessor, errorProcessor, whenParsed, PARSE_SUCCESS = 'event:raml-parsed'; var load = function(file) { setPromise(ramlParser.loadFile(file)); }; var parse = function(raml) { setPromise(ramlParser.load(raml)); }; var onParseSuccess = function(cb) { ramlProcessor = function() { cb.apply(this, arguments); if (!$rootScope.$$phase) { // handle aggressive digesters! $rootScope.$digest(); } }; if (whenParsed) { whenParsed.then(ramlProcessor); } }; var onParseError = function(cb) { errorProcessor = function() { cb.apply(this, arguments); if (!$rootScope.$$phase) { // handle aggressive digesters! $rootScope.$digest(); } }; if (whenParsed) { whenParsed.then(undefined, errorProcessor); } }; var setPromise = function(promise) { whenParsed = promise; if (ramlProcessor || errorProcessor) { whenParsed.then(ramlProcessor, errorProcessor); } }; $rootScope.$on(PARSE_SUCCESS, function(e, raml) { setPromise($q.when(raml)); }); return { load: load, parse: parse, onParseSuccess: onParseSuccess, onParseError: onParseError }; }; angular.module('RAML.Services') .service('ramlParserWrapper', RAML.Services.RAMLParserWrapper); })(); 'use strict'; (function() { var Client = function(configuration) { this.baseUri = configuration.getBaseUri(); }; function createConfiguration(parsed) { var config = { baseUriParameters: {} }; return { baseUriParameters: function(baseUriParameters) { config.baseUriParameters = baseUriParameters || {}; }, getBaseUri: function() { var template = RAML.Client.createBaseUri(parsed); config.baseUriParameters.version = parsed.version; return template.render(config.baseUriParameters); } }; } RAML.Client = { create: function(parsed, configure) { var configuration = createConfiguration(parsed); if (configure) { configure(configuration); } return new Client(configuration); }, createBaseUri: function(rootRAML) { var baseUri = rootRAML.baseUri.toString().replace(/\/+$/, ''); return new RAML.Client.ParameterizedString(baseUri, rootRAML.baseUriParameters, { parameterValues: {version: rootRAML.version} }); }, createPathSegment: function(resourceRAML) { return new RAML.Client.ParameterizedString(resourceRAML.relativeUri, resourceRAML.uriParameters); } }; })(); (function() { 'use strict'; RAML.Client.AuthStrategies = { for: function(scheme, credentials) { if (!scheme) { return RAML.Client.AuthStrategies.anonymous(); } switch(scheme.type) { case 'Basic Authentication': return new RAML.Client.AuthStrategies.Basic(scheme, credentials); case 'OAuth 2.0': return new RAML.Client.AuthStrategies.Oauth2(scheme, credentials); case 'OAuth 1.0': return new RAML.Client.AuthStrategies.Oauth1(scheme, credentials); case 'x-custom': return RAML.Client.AuthStrategies.anonymous(); case 'Anonymous': return RAML.Client.AuthStrategies.anonymous(); default: throw new Error('Unknown authentication strategy: ' + scheme.type); } } }; })(); 'use strict'; (function() { var NO_OP_TOKEN = { sign: function() {} }; var Anonymous = function() {}; Anonymous.prototype.authenticate = function() { return { then: function(success) { success(NO_OP_TOKEN); } }; }; var anonymous = new Anonymous(); RAML.Client.AuthStrategies.Anonymous = Anonymous; RAML.Client.AuthStrategies.anonymous = function() { return anonymous; }; })(); 'use strict'; (function() { var Basic = function(scheme, credentials) { this.token = new Basic.Token(credentials); }; Basic.prototype.authenticate = function() { var token = this.token; return { then: function(success) { success(token); } }; }; Basic.Token = function(credentials) { var words = CryptoJS.enc.Utf8.parse((credentials.username || '') + ':' + (credentials.password || '')); this.encoded = CryptoJS.enc.Base64.stringify(words); }; Basic.Token.prototype.sign = function(request) { request.header('Authorization', 'Basic ' + this.encoded); }; RAML.Client.AuthStrategies.Basic = Basic; })(); (function() { 'use strict'; var Oauth1 = function(scheme, credentials) { var signerFactory = RAML.Client.AuthStrategies.Oauth1.Signer.createFactory(scheme.settings, credentials); this.requestTemporaryCredentials = RAML.Client.AuthStrategies.Oauth1.requestTemporaryCredentials(scheme.settings, signerFactory); this.requestAuthorization = RAML.Client.AuthStrategies.Oauth1.requestAuthorization(scheme.settings); this.requestTokenCredentials = RAML.Client.AuthStrategies.Oauth1.requestTokenCredentials(scheme.settings, signerFactory); }; Oauth1.parseUrlEncodedData = function(data) { var result = {}; data.split('&').forEach(function(param) { var keyAndValue = param.split('='); result[keyAndValue[0]] = keyAndValue[1]; }); return result; }; Oauth1.prototype.authenticate = function() { return this.requestTemporaryCredentials().then(this.requestAuthorization).then(this.requestTokenCredentials); }; RAML.Client.AuthStrategies.Oauth1 = Oauth1; })(); (function() { /* jshint camelcase: false */ 'use strict'; var WINDOW_NAME = 'raml-console-oauth1'; RAML.Client.AuthStrategies.Oauth1.requestAuthorization = function(settings) { return function requestAuthorization(temporaryCredentials) { var authorizationUrl = settings.authorizationUri + '?oauth_token=' + temporaryCredentials.token, deferred = jQuery.Deferred(); window.RAML.authorizationSuccess = function(authResult) { temporaryCredentials.verifier = authResult.verifier; deferred.resolve(temporaryCredentials); }; window.open(authorizationUrl, WINDOW_NAME); return deferred.promise(); }; }; })(); (function() { /* jshint camelcase: false */ 'use strict'; RAML.Client.AuthStrategies.Oauth1.requestTemporaryCredentials = function(settings, signerFactory) { return function requestTemporaryCredentials() { var request = RAML.Client.Request.create(settings.requestTokenUri, 'post'); signerFactory().sign(request); return jQuery.ajax(request.toOptions()).then(function(rawFormData) { var data = RAML.Client.AuthStrategies.Oauth1.parseUrlEncodedData(rawFormData); return { token: data.oauth_token, tokenSecret: data.oauth_token_secret }; }); }; }; })(); (function() { /* jshint camelcase: false */ 'use strict'; RAML.Client.AuthStrategies.Oauth1.requestTokenCredentials = function(settings, signerFactory) { return function requestTokenCredentials(temporaryCredentials) { var request = RAML.Client.Request.create(settings.tokenCredentialsUri, 'post'); signerFactory(temporaryCredentials).sign(request); return jQuery.ajax(request.toOptions()).then(function(rawFormData) { var credentials = RAML.Client.AuthStrategies.Oauth1.parseUrlEncodedData(rawFormData); return signerFactory({ token: credentials.oauth_token, tokenSecret: credentials.oauth_token_secret }); }); }; }; })(); (function() { /* jshint camelcase: false */ 'use strict'; var Signer = RAML.Client.AuthStrategies.Oauth1.Signer = {}; Signer.createFactory = function(settings, consumerCredentials) { settings = settings || {}; return function createSigner(tokenCredentials) { var type = settings.signatureMethod === 'PLAINTEXT' ? 'Plaintext' : 'Hmac'; var mode = tokenCredentials === undefined ? 'Temporary' : 'Token'; return new Signer[type][mode](consumerCredentials, tokenCredentials); }; }; function baseParameters(consumerCredentials) { return { oauth_consumer_key: consumerCredentials.consumerKey, oauth_version: '1.0' }; } Signer.generateTemporaryCredentialParameters = function(consumerCredentials) { var result = baseParameters(consumerCredentials); result.oauth_callback = RAML.Settings.oauth1RedirectUri; return result; }; Signer.generateTokenCredentialParameters = function(consumerCredentials, tokenCredentials) { var result = baseParameters(consumerCredentials); result.oauth_token = tokenCredentials.token; if (tokenCredentials.verifier) { result.oauth_verifier = tokenCredentials.verifier; } return result; }; // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent Signer.rfc3986Encode = function(str) { return encodeURIComponent(str).replace(/[!'()]/g, window.escape).replace(/\*/g, '%2A'); }; Signer.setRequestHeader = function(params, request) { var header = Object.keys(params).map(function(key) { return key + '="' + Signer.rfc3986Encode(params[key]) + '"'; }).join(', '); request.header('Authorization', 'OAuth ' + header); }; })(); (function() { /* jshint camelcase: false */ 'use strict'; var generateTemporaryCredentialParameters = RAML.Client.AuthStrategies.Oauth1.Signer.generateTemporaryCredentialParameters, generateTokenCredentialParameters = RAML.Client.AuthStrategies.Oauth1.Signer.generateTokenCredentialParameters, rfc3986Encode = RAML.Client.AuthStrategies.Oauth1.Signer.rfc3986Encode, setRequestHeader = RAML.Client.AuthStrategies.Oauth1.Signer.setRequestHeader; function generateSignature(params, request, key) { params.oauth_signature_method = 'HMAC-SHA1'; params.oauth_timestamp = Math.floor(Date.now() / 1000); params.oauth_nonce = CryptoJS.lib.WordArray.random(16).toString(); var data = Hmac.constructHmacText(request, params); var hash = CryptoJS.HmacSHA1(data, key); params.oauth_signature = hash.toString(CryptoJS.enc.Base64); } var Hmac = { constructHmacText: function(request, oauthParams) { var options = request.toOptions(); return [ options.method.toUpperCase(), this.encodeURI(options.url), rfc3986Encode(this.encodeParameters(request, oauthParams)) ].join('&'); }, encodeURI: function(uri) { var parser = document.createElement('a'); parser.href = uri; var hostname = ''; if (parser.protocol === 'https:' && parser.port === 443 || parser.protocol === 'http:' && parser.port === 80) { hostname = parser.hostname.toLowerCase(); } else { hostname = parser.host.toLowerCase(); } return rfc3986Encode(parser.protocol + '//' + hostname + parser.pathname); }, encodeParameters: function(request, oauthParameters) { var params = request.queryParams(); var formParams = {}; if (request.toOptions().contentType === 'application/x-www-form-urlencoded') { formParams = request.data(); } var result = []; for (var key in params) { result.push([rfc3986Encode(key), rfc3986Encode(params[key])]); } for (var formKey in formParams) { result.push([rfc3986Encode(formKey), rfc3986Encode(formParams[formKey])]); } for (var oauthKey in oauthParameters) { result.push([rfc3986Encode(oauthKey), rfc3986Encode(oauthParameters[oauthKey])]); } result.sort(function(a, b) { return (a[0] === b[0] ? a[1].localeCompare(b[1]) : a[0].localeCompare(b[0])); }); return result.map(function(tuple) { return tuple.join('='); }).join('&'); } }; Hmac.Temporary = function(consumerCredentials) { this.consumerCredentials = consumerCredentials; }; Hmac.Temporary.prototype.sign = function(request) { var params = generateTemporaryCredentialParameters(this.consumerCredentials); var key = rfc3986Encode(this.consumerCredentials.consumerSecret) + '&'; generateSignature(params, request, key); setRequestHeader(params, request); }; Hmac.Token = function(consumerCredentials, tokenCredentials) { this.consumerCredentials = consumerCredentials; this.tokenCredentials = tokenCredentials; }; Hmac.Token.prototype.sign = function(request) { var params = generateTokenCredentialParameters(this.consumerCredentials, this.tokenCredentials); var key = rfc3986Encode(this.consumerCredentials.consumerSecret) + '&' + rfc3986Encode(this.tokenCredentials.tokenSecret); generateSignature(params, request, key); setRequestHeader(params, request); }; RAML.Client.AuthStrategies.Oauth1.Signer.Hmac = Hmac; })(); (function() { /* jshint camelcase: false */ 'use strict'; var generateTemporaryCredentialParameters = RAML.Client.AuthStrategies.Oauth1.Signer.generateTemporaryCredentialParameters, generateTokenCredentialParameters = RAML.Client.AuthStrategies.Oauth1.Signer.generateTokenCredentialParameters, rfc3986Encode = RAML.Client.AuthStrategies.Oauth1.Signer.rfc3986Encode, setRequestHeader = RAML.Client.AuthStrategies.Oauth1.Signer.setRequestHeader; var Plaintext = {}; Plaintext.Temporary = function(consumerCredentials) { this.consumerCredentials = consumerCredentials; }; Plaintext.Temporary.prototype.sign = function(request) { var params = generateTemporaryCredentialParameters(this.consumerCredentials); params.oauth_signature = rfc3986Encode(this.consumerCredentials.consumerSecret) + '&'; params.oauth_signature_method = 'PLAINTEXT'; setRequestHeader(params, request); }; Plaintext.Token = function(consumerCredentials, tokenCredentials) { this.consumerCredentials = consumerCredentials; this.tokenCredentials = tokenCredentials; }; Plaintext.Token.prototype.sign = function(request) { var params = generateTokenCredentialParameters(this.consumerCredentials, this.tokenCredentials); params.oauth_signature = rfc3986Encode(this.consumerCredentials.consumerSecret) + '&' + rfc3986Encode(this.tokenCredentials.tokenSecret); params.oauth_signature_method = 'PLAINTEXT'; setRequestHeader(params, request); }; RAML.Client.AuthStrategies.Oauth1.Signer.Plaintext = Plaintext; })(); (function() { 'use strict'; var Oauth2 = function(scheme, credentials) { this.scheme = scheme; this.credentials = credentials; }; function getScopes(credentials) { var scopes = []; if (credentials.scopes) { scopes = Object.keys(credentials.scopes).filter(function (scope) { return credentials.scopes[scope] === true; }); } return scopes; } function popup(location) { var w = 640; var h = 480; var left = (screen.width / 2) - (w / 2); var top = (screen.height / 2) - (h / 2); return window.open(location, 'Authentication', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left); } Oauth2.prototype.authenticate = function(options, done) { var auth = new ClientOAuth2({ clientId: this.credentials.clientId, clientSecret: this.credentials.clientSecret, accessTokenUri: this.scheme.settings.accessTokenUri, authorizationUri: this.scheme.settings.authorizationUri, redirectUri: RAML.Settings.oauth2RedirectUri, scopes: getScopes(this.credentials) }); var grantType = this.credentials.grant; if (grantType === 'token' || grantType === 'code') { window.oauth2Callback = function (uri) { auth[grantType].getToken(uri, function (err, user, raw) { if (err) { done(raw, err); } if (user && user.accessToken) { user.request(options, function (err, res) { done(res.raw, err); }); } }); }; //// TODO: Find a way to handle 404 popup(auth[grantType].getUri()); } if (grantType === 'owner') { auth.owner.getToken(this.credentials.username, this.credentials.password, function (err, user, raw) { if (err) { done(raw, err); } if (user && user.accessToken) { user.request(options, function (err, res) { done(res.raw, err); }); } }); } if (grantType === 'credentials') { auth.credentials.getToken(function (err, user, raw) { if (err) { done(raw, err); } if (user && user.accessToken) { user.request(options, function (err, res) { done(res.raw, err); }); } }); } }; RAML.Client.AuthStrategies.Oauth2 = Oauth2; })(); (function() { 'use strict'; var templateMatcher = /\{([^}]*)\}/g; function tokenize(template) { var tokens = template.split(templateMatcher); return tokens.filter(function(token) { return token.length > 0; }); } function rendererFor(template) { return function renderer(context) { context = context || {}; // Enforce request without URI parameters // requiredParameters.forEach(function(name) { // if (!context[name]) { // throw new Error('Missing required uri parameter: ' + name); // } // }); var templated = template.replace(templateMatcher, function(match, parameterName) { return context[parameterName] || ''; }); return templated; }; } RAML.Client.ParameterizedString = function(template, uriParameters, options) { options = options || {parameterValues: {} }; template = template.replace(templateMatcher, function(match, parameterName) { if (options.parameterValues[parameterName]) { return options.parameterValues[parameterName]; } return '{' + parameterName + '}'; }); this.parameters = uriParameters; this.templated = Object.keys(this.parameters || {}).length > 0; this.tokens = tokenize(template); this.render = rendererFor(template, uriParameters); this.toString = function() { return template; }; }; })(); (function() { 'use strict'; RAML.Client.PathBuilder = { create: function(pathSegments) { return function pathBuilder(contexts) { contexts = contexts || []; return pathSegments.map(function(pathSegment, index) { return pathSegment.render(contexts[index]); }).join(''); }; } }; })(); (function() { 'use strict'; var CONTENT_TYPE = 'content-type'; var FORM_DATA = 'multipart/form-data'; var RequestDsl = function(options) { var rawData; var queryParams; var isMultipartRequest; this.data = function(data) { if (data === undefined) { return RAML.Utils.clone(rawData); } else { rawData = data; } }; this.queryParams = function(parameters) { if (parameters === undefined) { return RAML.Utils.clone(queryParams); } else { queryParams = parameters; } }; this.queryParam = function(name, value) { queryParams = queryParams || {}; queryParams[name] = value; }; this.header = function(name, value) { options.headers = options.headers || {}; if (name.toLowerCase() === CONTENT_TYPE) { if (value === FORM_DATA) { isMultipartRequest = true; options.contentType = false; return; } else { isMultipartRequest = false; options.contentType = value; } } options.headers[name] = value; }; this.headers = function(headers) { options.headers = {}; isMultipartRequest = false; for (var name in headers) { this.header(name, headers[name]); } if (Object.keys(options.headers).length === 0) { options.headers = null; } }; this.toOptions = function() { var o = RAML.Utils.copy(options); o.traditional = true; if (rawData) { if (isMultipartRequest) { var data = new FormData(); var appendValueForKey = function(key) { return function(value) { data.append(key, value); }; }; for (var key in rawData) { rawData[key].forEach(appendValueForKey(key)); } o.processData = false; o.data = data; } else { o.processData = true; o.data = rawData; } } o.baseUrl = options.url; if (!RAML.Utils.isEmpty(queryParams)) { var separator = (options.url.match('\\?') ? '&' : '?'); o.baseUrl = options.url + separator; o.url = options.url + separator + jQuery.param(queryParams, true); } if (!RAML.Settings.disableProxy && RAML.Settings.proxy) { o.url = RAML.Settings.proxy + o.url; } return o; }; }; RAML.Client.Request = { create: function(url, method) { return new RequestDsl({ url: url, method: method }); } }; })(); (function() { 'use strict'; // number regular expressions from http://yaml.org/spec/1.2/spec.html#id2804092 var RFC1123 = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), \d{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{4} \d{2}:\d{2}:\d{2} GMT$/; function isEmpty(value) { return value == null || value === ''; } var VALIDATIONS = { required: function(value) { return !isEmpty(value); }, boolean: function(value) { return isEmpty(value) || value === 'true' || value === 'false'; }, enum: function(enumeration) { return function(value) { return isEmpty(value) || enumeration.indexOf(value) > -1; }; }, integer: function(value) { return isEmpty(value) || /^-?(0|[1-9][0-9]*)$/.test(value); }, number: function(value) { return isEmpty(value) || /^-?(0|[1-9][0-9]*)(\.[0-9]*)?([eE][-+]?[0-9]+)?$/.test(value); }, minimum: function(minimum) { return function(value) { return isEmpty(value) || value >= minimum; }; }, maximum: function(maximum) { return function(value) { return isEmpty(value) || value <= maximum; }; }, minLength: function(minimum) { return function(value) { return isEmpty(value) || value.length >= minimum; }; }, maxLength: function(maximum) { return function(value) { return isEmpty(value) || value.length <= maximum; }; }, pattern: function(pattern) { var regex = new RegExp(pattern); return function(value) { return isEmpty(value) || regex.test(value); }; }, date: function(value) { return isEmpty(value) || RFC1123.test(value); } }; function baseValidations(definition) { var validations = {}; if (definition.required) { validations.required = VALIDATIONS.required; } return validations; } function numberValidations(validations, definition) { if (definition.minimum != null) { validations.minimum = VALIDATIONS.minimum(definition.minimum); } if (definition.maximum != null) { validations.maximum = VALIDATIONS.maximum(definition.maximum); } } // function copyValidations(validations, types) { // Object.keys(types).forEach(function(type) { // validations[type] = VALIDATIONS[type](types[type]); // }); // } var VALIDATIONS_FOR_TYPE = { string: function(definition) { var validations = baseValidations(definition); if (Array.isArray(definition.enum)) { validations.enum = VALIDATIONS.enum(definition.enum); } if (definition.minLength != null) { validations.minLength = VALIDATIONS.minLength(definition.minLength); } if (definition.maxLength != null) { validations.maxLength = VALIDATIONS.maxLength(definition.maxLength); } if (definition.pattern) { validations.pattern = VALIDATIONS.pattern(definition.pattern); } return validations; }, integer: function(definition) { var validations = baseValidations(definition); validations.integer = VALIDATIONS.integer; numberValidations(validations, definition); return validations; }, number: function(definition) { var validations = baseValidations(definition); validations.number = VALIDATIONS.number; numberValidations(validations, definition); return validations; }, boolean: function(definition) { var validations = baseValidations(definition); validations.boolean = VALIDATIONS.boolean; return validations; }, date: function(definition) { var validations = baseValidations(definition); validations.date = VALIDATIONS.date; return validations; } }; function Validator(validations) { this.validations = validations; } Validator.prototype.validate = function(value) { var errors; for (var validation in this.validations) { if (!this.validations[validation](value)) { errors = errors || []; errors.push(validation); } } return errors; }; Validator.from = function(definition) { if (!definition) { throw new Error('definition is required!'); } var validations; if (VALIDATIONS_FOR_TYPE[definition.type]) { validations = VALIDATIONS_FOR_TYPE[definition.type](definition); } else { validations = {}; } return new Validator(validations); }; RAML.Client.Validator = Validator; })(); (function() { 'use strict'; RAML.Filters.nameFromParameterizable = function() { return function(input) { if (typeof input === 'object' && input !== null) { return Object.keys(input)[0]; } else if (input) { return input; } else { return undefined; } }; }; })(); RAML.Inspector = (function() { 'use strict'; var exports = {}; var METHOD_ORDERING = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS', 'TRACE', 'CONNECT']; function extractResources(basePathSegments, api, securitySchemes) { var resources = [], apiResources = api.resources || []; apiResources.forEach(function(resource) { var resourcePathSegments = basePathSegments.concat(RAML.Client.createPathSegment(resource)); var overview = exports.resourceOverviewSource(resourcePathSegments, resource); overview.methods = overview.methods.map(function(method) { return RAML.Inspector.Method.create(method, securitySchemes); }); resources.push(overview); if (resource.resources) { var extracted = extractResources(resourcePathSegments, resource, securitySchemes); extracted.forEach(function(resource) { resources.push(resource); }); } }); return resources; } function groupResources(resources) { var currentPrefix, resourceGroups = []; (resources || []).forEach(function(resource) { var prefix = resource.pathSegments[0].toString(); if (prefix === currentPrefix || prefix.indexOf(currentPrefix + '/') === 0) { resourceGroups[resourceGroups.length-1].push(resource); } else { currentPrefix = resource.pathSegments[0].toString(); resourceGroups.push([resource]); } }); return resourceGroups; } exports.resourceOverviewSource = function(pathSegments, resource) { var clone = RAML.Utils.clone(resource); clone.traits = resource.is; clone.resourceType = resource.type; clone.type = clone.is = undefined; clone.pathSegments = pathSegments; clone.methods = (resource.methods || []); clone.methods.sort(function(a, b) { var aOrder = METHOD_ORDERING.indexOf(a.method.toUpperCase()); var bOrder = METHOD_ORDERING.indexOf(b.method.toUpperCase()); return aOrder > bOrder ? 1 : -1; }); clone.uriParametersForDocumentation = pathSegments .map(function(segment) { return segment.parameters; }) .filter(function(params) { return !!params; }) .reduce(function(accum, parameters) { for (var key in parameters) { var parameter = parameters[key]; if (parameter) { parameter = (parameter instanceof Array) ? parameter : [ parameter ]; } accum[key] = parameter; } return accum; }, {}); if (Object.keys(clone.uriParametersForDocumentation).length === 0) { clone.uriParametersForDocumentation = null; } clone.toString = function() { return this.pathSegments.map(function(segment) { return segment.toString(); }).join(''); }; return clone; }; exports.create = function(api) { // Perform deep copy to avoid mutating object. // TODO: Audit code and only use parts of object that are required. api = jQuery.extend(true, {}, api); if (api.baseUri) { api.baseUri = RAML.Client.createBaseUri(api); } api.resources = extractResources([], api, api.securitySchemes); api.resourceGroups = groupResources(api.resources); return api; }; return exports; })(); (function() { 'use strict'; var PARAMETER = /\{\*\}/; function ensureArray(value) { if (value === undefined || value === null) { return; } return (value instanceof Array) ? value : [ value ]; } function normalizeNamedParameters(parameters) { Object.keys(parameters || {}).forEach(function(key) { parameters[key] = ensureArray(parameters[key]); }); } function wrapWithParameterizedHeader(name, definitions) { return definitions.map(function(definition) { return RAML.Inspector.ParameterizedHeader.fromRAML(name, definition); }); } function filterHeaders(headers) { var filtered = { plain: {}, parameterized: {} }; Object.keys(headers || {}).forEach(function(key) { if (key.match(PARAMETER)) { filtered.parameterized[key] = wrapWithParameterizedHeader(key, headers[key]); } else { filtered.plain[key] = headers[key]; } }); if(Object.keys(filtered.plain).length === 0) { filtered.plain = null; } return filtered; } function processBody(body) { var content = body['application/x-www-form-urlencoded']; if (content) { normalizeNamedParameters(content.formParameters); } content = body['multipart/form-data']; if (content) { normalizeNamedParameters(content.formParameters); } } function processResponses(responses) { Object.keys(responses).forEach(function(status) { var response = responses[status]; if (response) { normalizeNamedParameters(response.headers); } }); } function securitySchemesExtractor(securitySchemes) { securitySchemes = securitySchemes || []; return function() { var securedBy = this.securedBy || [], selectedSchemes = {}; var overwrittenSchemes = {}; securedBy.map(function(el) { if (el === null) { securitySchemes.push({ anonymous: { type: 'Anonymous' } }); securedBy.push('anonymous'); } if (typeof el === 'object' && el) { var key = Object.keys(el)[0]; overwrittenSchemes[key] = el[key]; securedBy.push(key); } }); securedBy = securedBy.filter(function(name) { return name !== null && typeof name !== 'object'; }); securitySchemes.forEach(function(scheme) { securedBy.forEach(function(name) { if (scheme[name]) { selectedSchemes[name] = jQuery.extend(true, {}, scheme[name]); } }); }); Object.keys(overwrittenSchemes).map(function (key) { Object.keys(overwrittenSchemes[key]).map(function (prop) { if (selectedSchemes[key].settings) { selectedSchemes[key].settings[prop] = overwrittenSchemes[key][prop]; } }); }); if(Object.keys(selectedSchemes).length === 0) { selectedSchemes.anonymous = { type: 'Anonymous' }; } return selectedSchemes; }; } function allowsAnonymousAccess() { /*jshint validthis: true */ var securedBy = this.securedBy || [null]; return securedBy.some(function(name) { return name === null; }); } RAML.Inspector.Method = { create: function(raml, securitySchemes) { var method = RAML.Utils.clone(raml); method.responseCodes = Object.keys(method.responses || {}); method.securitySchemes = securitySchemesExtractor(securitySchemes); method.allowsAnonymousAccess = allowsAnonymousAccess; normalizeNamedParameters(method.headers); normalizeNamedParameters(method.queryParameters); method.headers = filterHeaders(method.headers); processBody(method.body || {}); processResponses(method.responses || {}); method.plainAndParameterizedHeaders = RAML.Utils.copy(method.headers.plain); Object.keys(method.headers.parameterized).forEach(function(parameterizedHeader) { method.plainAndParameterizedHeaders[parameterizedHeader] = method.headers.parameterized[parameterizedHeader].map(function(parameterized) { return parameterized.definition(); }); }); return method; } }; })(); (function () { 'use strict'; function validate(value) { value = value ? value.trim() : ''; if (value === '') { throw new Error(); } return value; } function fromRAML(name, definition) { var parameterizedString = new RAML.Client.ParameterizedString(name, definition); return { create: function(value) { value = validate(value); var header = RAML.Utils.clone(definition); header.displayName = parameterizedString.render({'*': value}); return header; }, definition: function() { return definition; } }; } RAML.Inspector.ParameterizedHeader = { fromRAML: fromRAML }; })(); (function() { 'use strict'; window.ramlErrors = {}; CodeMirror.registerHelper('lint', 'yaml', function () { var found = []; found.push({ message: window.ramlErrors.message, severity: 'error', from: CodeMirror.Pos(window.ramlErrors.line), to: CodeMirror.Pos(window.ramlErrors.line) }); return found; }); })(); (function() { 'use strict'; var FORM_URLENCODED = 'application/x-www-form-urlencoded'; var FORM_DATA = 'multipart/form-data'; var BodyContent = function(contentTypes) { this.contentTypes = Object.keys(contentTypes).sort(); this.selected = this.contentTypes[0]; var definitions = this.definitions = {}; this.contentTypes.forEach(function(contentType) { var definition = contentTypes[contentType] || {}; if (definition.formParameters) { Object.keys(definition.formParameters).map(function (key) { definition.formParameters[key][0].id = key; }); } switch (contentType) { case FORM_URLENCODED: case FORM_DATA: definitions[contentType] = new RAML.Services.TryIt.NamedParameters(definition.formParameters); break; default: definitions[contentType] = new RAML.Services.TryIt.BodyType(definition); } }); }; BodyContent.prototype.isForm = function(contentType) { return contentType === FORM_URLENCODED || contentType === FORM_DATA; }; BodyContent.prototype.isSelected = function(contentType) { return contentType === this.selected; }; BodyContent.prototype.fillWithExample = function($event) { $event.preventDefault(); this.definitions[this.selected].fillWithExample(); }; BodyContent.prototype.hasExample = function(contentType) { return this.definitions[contentType].hasExample(); }; BodyContent.prototype.data = function() { if (this.selected) { return this.definitions[this.selected].data(); } }; BodyContent.prototype.copyFrom = function(oldContent) { var content = this; oldContent.contentTypes.forEach(function(contentType) { if (content.definitions[contentType]) { content.definitions[contentType].copyFrom(oldContent.definitions[contentType]); } }); if (this.contentTypes.some(function(contentType) { return contentType === oldContent.selected; })) { this.selected = oldContent.selected; } }; BodyContent.prototype.clear = function (info) { var that = this.definitions[this.selected]; Object.keys(this.values).map(function (key) { if (typeof info[key][0].enum === 'undefined' || info[key][0].overwritten === true) { that.values[key] = ['']; } }); }; BodyContent.prototype.reset = function (info, field) { var that = this.definitions[this.selected]; if (info) { Object.keys(info).map(function (key) { if (typeof field === 'undefined' || field === key) { if (typeof info[key][0].enum === 'undefined') { that.values[key][0] = info[key][0].example; } } }); } }; RAML.Services.TryIt.BodyContent = BodyContent; })(); (function() { 'use strict'; var BodyType = function(contentType) { this.contentType = contentType || {}; this.value = undefined; }; BodyType.prototype.fillWithExample = function() { this.value = this.contentType.example; }; BodyType.prototype.hasExample = function() { return !!this.contentType.example; }; BodyType.prototype.data = function() { return this.value; }; BodyType.prototype.copyFrom = function(oldBodyType) { this.value = oldBodyType.value; }; RAML.Services.TryIt.BodyType = BodyType; })(); (function() { 'use strict'; var Context = function(baseUriParameters, resource, method) { this.headers = new RAML.Services.TryIt.NamedParameters(method.headers.plain, method.headers.parameterized); this.queryParameters = new RAML.Services.TryIt.NamedParameters(method.queryParameters); resource.uriParametersForDocumentation = resource.uriParametersForDocumentation || {}; if (baseUriParameters) { Object.keys(baseUriParameters).map(function (key) { resource.uriParametersForDocumentation[key] = [baseUriParameters[key]]; }); } if (Object.keys(resource.uriParametersForDocumentation).length === 0) { resource.uriParametersForDocumentation = null; } this.uriParameters = new RAML.Services.TryIt.NamedParameters(resource.uriParametersForDocumentation); if (method.body) { this.bodyContent = new RAML.Services.TryIt.BodyContent(method.body); } this.pathBuilder = new RAML.Client.PathBuilder.create(resource.pathSegments); this.pathBuilder.baseUriContext = {}; this.pathBuilder.segmentContexts = resource.pathSegments.map(function() { return {}; }); }; Context.prototype.merge = function(oldContext) { this.headers.copyFrom(oldContext.headers); this.queryParameters.copyFrom(oldContext.queryParameters); this.uriParameters.copyFrom(oldContext.uriParameters); if (this.bodyContent && oldContext.bodyContent) { this.bodyContent.copyFrom(oldContext.bodyContent); } this.pathBuilder.baseUriContext = oldContext.pathBuilder.baseUriContext; this.pathBuilder.segmentContexts = oldContext.pathBuilder.segmentContexts; }; RAML.Services.TryIt.Context = Context; })(); (function() { 'use strict'; var NamedParameter = function(definitions) { this.definitions = definitions; this.selected = definitions[0].type; }; NamedParameter.prototype.hasMultipleTypes = function() { return this.definitions.length > 1; }; NamedParameter.prototype.isSelected = function(definition) { return this.selected === definition.type; }; RAML.Services.TryIt.NamedParameter = NamedParameter; })(); (function() { 'use strict'; function copy(object) { var shallow = {}; Object.keys(object || {}).forEach(function(key) { shallow[key] = new RAML.Services.TryIt.NamedParameter(object[key]); }); return shallow; } function filterEmpty(object) { var copy = {}; Object.keys(object).forEach(function(key) { var values = object[key].filter(function(value) { return value !== undefined && value !== null && (typeof value !== 'string' || value.trim().length > 0); }); if (values.length > 0) { copy[key] = values; } }); return copy; } var NamedParameters = function(plain, parameterized) { this.plain = copy(plain); this.parameterized = parameterized; Object.keys(parameterized || {}).forEach(function(key) { parameterized[key].created = []; }); this.values = {}; Object.keys(this.plain).forEach(function(key) { this.values[key] = [undefined]; }.bind(this)); }; NamedParameters.prototype.clear = function (info) { var that = this; Object.keys(this.values).map(function (key) { if (typeof info[key][0].enum === 'undefined' || info[key][0].overwritten === true) { that.values[key] = ['']; } }); }; NamedParameters.prototype.reset = function (info, field) { var that = this; if (info) { Object.keys(info).map(function (key) { if (typeof field === 'undefined' || field === key) { if (typeof info[key][0].enum === 'undefined') { if (info[key][0].type === 'date' && typeof info[key][0].example === 'object') { info[key][0].example = info[key][0].example.toUTCString(); } that.values[key][0] = info[key][0].example; } } }); } }; NamedParameters.prototype.create = function(name, value) { var parameters = this.parameterized[name]; var definition = parameters.map(function(parameterizedHeader) { return parameterizedHeader.create(value); }); var parameterizedName = definition[0].displayName; parameters.created.push(parameterizedName); this.plain[parameterizedName] = new RAML.Services.TryIt.NamedParameter(definition); this.values[parameterizedName] = [undefined]; }; NamedParameters.prototype.remove = function(name) { delete this.plain[name]; delete this.values[name]; return; }; NamedParameters.prototype.data = function() { return filterEmpty(this.values); }; NamedParameters.prototype.copyFrom = function(oldParameters) { var parameters = this; Object.keys(oldParameters.parameterized || {}).forEach(function(key) { if (parameters.parameterized[key]) { oldParameters.parameterized[key].created.forEach(function(createdParam) { parameters.plain[createdParam] = oldParameters.plain[createdParam]; }); } }); var keys = Object.keys(oldParameters.plain || {}).filter(function(key) { return parameters.plain[key]; }); keys.forEach(function(key) { parameters.values[key] = oldParameters.values[key]; }); }; RAML.Services.TryIt.NamedParameters = NamedParameters; })(); (function() { 'use strict'; function Clone() {} RAML.Utils = { clone: function(object) { Clone.prototype = object; return new Clone(); }, copy: function(object) { var copiedObject = {}; for (var key in object) { copiedObject[key] = object[key]; } return copiedObject; }, isEmpty: function(object) { if (object) { return Object.keys(object).length === 0; } else { return true; } }, filterEmpty: function (object) { var copy = {}; Object.keys(object).forEach(function(key) { var value = object[key]; var flag = value !== undefined && value !== null && (typeof value !== 'string' || value.trim().length > 0); if (flag) { copy[key] = value; } }); return copy; } }; })(); (function (root) { var _hasOwnProperty = Object.prototype.hasOwnProperty; var btoa = typeof Buffer === 'function' ? bufferBtoa : root.btoa; /** * Format error response types to regular strings for displaying to clients. * * Reference: http://tools.ietf.org/html/rfc6749#section-4.1.2.1 * * @type {Object} */ var ERROR_RESPONSES = { 'invalid_request': [ 'The request is missing a required parameter, includes an', 'invalid parameter value, includes a parameter more than', 'once, or is otherwise malformed.' ].join(' '), 'invalid_client': [ 'Client authentication failed (e.g., unknown client, no', 'client authentication included, or unsupported', 'authentication method).' ].join(' '), 'invalid_grant': [ 'The provided authorization grant (e.g., authorization', 'code, resource owner credentials) or refresh token is', 'invalid, expired, revoked, does not match the redirection', 'URI used in the authorization request, or was issued to', 'another client.' ].join(' '), 'unauthorized_client': [ 'The client is not authorized to request an authorization', 'code using this method.' ].join(' '), 'unsupported_grant_type': [ 'The authorization grant type is not supported by the', 'authorization server.' ].join(' '), 'access_denied': [ 'The resource owner or authorization server denied the request.' ].join(' '), 'unsupported_response_type': [ 'The authorization server does not support obtaining', 'an authorization code using this method.' ].join(' '), 'invalid_scope': [ 'The requested scope is invalid, unknown, or malformed.' ].join(' '), 'server_error': [ 'The authorization server encountered an unexpected', 'condition that prevented it from fulfilling the request.', '(This error code is needed because a 500 Internal Server', 'Error HTTP status code cannot be returned to the client', 'via an HTTP redirect.)' ].join(' '), 'temporarily_unavailable': [ 'The authorization server is currently unable to handle', 'the request due to a temporary overloading or maintenance', 'of the server.' ].join(' ') }; /** * Iterate over a source object and copy properties to the destination object. * * @param {Object} dest * @param {Object} source * @return {Object} */ function assign (dest /*, ...source */) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (_hasOwnProperty.call(source, key)) { dest[key] = source[key]; } } } return dest; } /** * Support base64 in node like how it works in the browser. * * @param {String} string * @return {String} */ function bufferBtoa (string) { return new Buffer(string).toString('base64'); } /** * Check if properties exist on an object and throw when they aren't. * * @throws {TypeError} If an expected property is missing. * * @param {Object} obj * @param {Array} props */ function expects (obj, props) { for (var i = 0; i < props.length; i++) { var prop = props[i]; } } /** * Create a new object based on a source object with keys omitted. * * @param {Object} source * @param {Array} keys * @return {Object} */ function omit (source, keys) { var obj = {}; // Iterate over the source object and set properties on a new object. Object.keys(source || {}).forEach(function (key) { if (keys.indexOf(key) === -1) { obj[key] = source[key]; } }); return obj; } /** * Attempt (and fix) URI component encoding. * * @param {String} str * @return {String} */ function encodeComponent (str) { return encodeURIComponent(str) .replace(/[!'()]/g, root.escape) .replace(/\*/g, '%2A'); } /** * Attempt URI component decoding. * * @param {String} str * @return {String} */ function decodeComponent (str) { return decodeURIComponent(str); } /** * Convert an object into a query string. * * @param {Object} obj * @param {String} sep * @param {String} eq * @return {String} */ function uriEncode (obj, sep, eq) { var params = []; eq = eq || '='; sep = sep || '&'; Object.keys(obj).forEach(function (key) { var value = obj[key]; var keyStr = encodeComponent(key) + eq; if (Array.isArray(value)) { for (var i = 0; i < value.length; i++) { params.push(keyStr + encodeComponent(value[i])); } } else if (value != null) { params.push(keyStr + encodeComponent(value)); } }); return params.join(sep); } /** * Convert a query string into an object. * * @param {String} qs * @param {String} sep * @param {String} eq * @return {Object} */ function uriDecode (qs, sep, eq) { eq = eq || '='; sep = sep || '&'; qs = qs.split(sep); var obj = {}; var maxKeys = 1000; var len = qs.length > maxKeys ? maxKeys : qs.length; for (var i = 0; i < len; i++) { var key = qs[i].replace(/\+/g, '%20'); var value = ''; var index = key.indexOf(eq); if (index !== -1) { value = key.substr(index + 1); key = key.substr(0, index); } key = decodeComponent(key); value = decodeComponent(value); if (!_hasOwnProperty.call(obj, key)) { obj[key] = value; } else if (Array.isArray(obj[key])) { obj[key].push(value); } else { obj[key] = [obj[key], value]; } } return obj; } /** * Pull an authentication error from the response data. * * @param {Object} data * @return {String} */ function getAuthError (data) { var message = ERROR_RESPONSES[data.error] || data.error || data.error_message; // Return an error instance with the message if it exists. return message && new Error(message); } /** * Retrieve all the HTTP response headers for an XMLHttpRequest instance. * * @param {XMLHttpRequest} xhr * @return {Object} */ function getAllReponseHeaders (xhr) { var headers = {}; // Split all header lines and iterate. xhr.getAllResponseHeaders().split('\n').forEach(function (header) { var index = header.indexOf(':'); if (index === -1) { return; } var name = header.substr(0, index).toLowerCase(); var value = header.substr(index + 1).trim(); headers[name] = value; }); return headers; } /** * Sanitize the scopes option to be a string. * * @param {Array} scopes * @return {String} */ function sanitizeScope (scopes) { if (!Array.isArray(scopes)) { return scopes == null ? null : String(scopes); } return scopes.join(' '); } /** * Construct an object that can handle the multiple OAuth 2.0 flows. * * @param {Object} options */ function ClientOAuth2 (options) { this.options = options; this.code = new CodeFlow(this); this.token = new TokenFlow(this); this.owner = new OwnerFlow(this); this.credentials = new CredentialsFlow(this); } /** * Alias the token constructor. * * @type {Function} */ ClientOAuth2.Token = ClientOAuth2Token; /** * Create a new token from existing data. * * @param {String} access * @param {String} [refresh] * @param {String} [type] * @param {Object} [data] * @return {Object} */ ClientOAuth2.prototype.createToken = function (access, refresh, type, data) { return new ClientOAuth2Token(this, assign({}, data, { access_token: access, refresh_token: refresh, token_type: type })); }; /** * Using the built-in request method, we'll automatically attempt to parse * the response. * * @param {Object} options * @param {Function} done */ ClientOAuth2.prototype._request = function (options, done) { return this.request(options, function (err, res) { if (err) { return done(err); } // Check the response status and fail. if (res.status && Math.floor(res.status / 100) !== 2) { err = new Error('HTTP Status ' + res.status); err.status = res.status; return done(err); } // Support already parsed responses in case of custom body parsing. if (typeof res.body !== 'string') { return done(null, res.body); } // Attempt to parse as JSON, falling back to parsing as a query string. try { done(null, JSON.parse(res.body), res.raw); } catch (e) { done(null, uriDecode(res.body), res.raw); } }); }; if (typeof window !== 'undefined') { /** * Make a HTTP request using XMLHttpRequest. * * @param {Object} options * @param {Function} done */ ClientOAuth2.prototype.request = function (options, done) { var xhr = new root.XMLHttpRequest(); var headers = options.headers || {}; // Open the request to the url and method. xhr.open(options.method, options.url); // When the request has loaded, attempt to automatically parse the body. xhr.onload = function () { return done(null, { raw: xhr, status: xhr.status, headers: getAllReponseHeaders(xhr), body: xhr.responseText }); }; // Catch request errors. xhr.onerror = xhr.onabort = function () { return done(new Error(xhr.statusText || 'XHR aborted')); }; // Set all request headers. Object.keys(headers).forEach(function (header) { xhr.setRequestHeader(header, headers[header]); }); // Make the request with the body. xhr.send(options.body); }; } else { var url = require('url'); var http = require('http'); var https = require('https'); /** * Make a request using the built-in node http library. * * @param {Object} options * @param {Function} done */ ClientOAuth2.prototype.request = function (options, done) { var lib = http; var reqOptions = url.parse(options.url); // If the protocol is over https, switch request library. if (reqOptions.protocol === 'https:') { lib = https; } // Alias request options. reqOptions.method = options.method; reqOptions.headers = options.headers; // Send the http request and listen for the response to finish. var req = lib.request(reqOptions, function (res) { var data = ''; // Callback to `done` if a response error occurs. res.on('error', done); // Concat all the data chunks into a string. res.on('data', function (chunk) { data += chunk; }); // When the response is finished, attempt to parse the data string. res.on('end', function () { return done(null, { raw: res, status: res.statusCode, headers: res.headers, body: data }); }); }); // Callback to `done` if a request error occurs. req.on('error', done); // Send the body and make the request. req.write(options.body); req.end(); }; } /** * General purpose client token generator. * * @param {Object} client * @param {Object} data */ function ClientOAuth2Token (client, data) { this.client = client; this.data = omit(data, [ 'access_token', 'refresh_token', 'token_type', 'expires_in', 'scope', 'state', 'error', 'error_description', 'error_uri' ]); this.tokenType = (data.token_type || 'bearer').toLowerCase(); this.accessToken = data.access_token; this.refreshToken = data.refresh_token; // Set the expiration date. if (data.expires_in) { this.expires = new Date(); this.expires.setSeconds(this.expires.getSeconds() + data.expires_in); } } /** * Sign a standardised request object with user authentication information. * * @param {Object} options * @return {Object} */ ClientOAuth2Token.prototype.sign = function (options) { if (!this.accessToken) { throw new Error('Unable to sign without access token'); } options.headers = options.headers || {}; if (this.tokenType === 'bearer') { options.headers.Authorization = 'Bearer ' + this.accessToken; } else { var parts = options.url.split('#'); var token = 'access_token=' + this.accessToken; var url = parts[0].replace(/[?&]access_token=[^&#]/, ''); var fragment = parts[1] ? '#' + parts[1] : ''; // Prepend the correct query string parameter to the url. options.url = url + (url.indexOf('?') > -1 ? '&' : '?') + token + fragment; // Attempt to avoid storing the url in proxies, since the access token // is exposed in the query parameters. options.headers.Pragma = 'no-store'; options.headers['Cache-Control'] = 'no-store'; } return options; }; /** * Make a HTTP request as the user. * * @param {Object} options * @param {Function} done */ ClientOAuth2Token.prototype.request = function (options, done) { return this.client.client.request(this.sign(options), done); }; /** * Refresh a user access token with the supplied token. * * @param {Function} done */ ClientOAuth2Token.prototype.refresh = function (done) { var self = this; var options = this.client.options; if (!this.refreshToken) { return done(new Error('No refresh token set')); } var authorization = btoa(options.clientId + ':' + options.clientSecret); return this.client._request({ url: options.accessTokenUri, method: 'POST', headers: { 'Accept': 'application/json, application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'Basic ' + authorization }, body: uriEncode({ refresh_token: this.refreshToken, grant_type: 'refresh_token' }) }, function (err, data) { // If an error exists or the data contains an error, return `done`. if (err || (err = getAuthError(data))) { return done(err); } // Update stored tokens on the current instance. self.accessToken = data.access_token; self.refreshToken = data.refresh_token; return done(null, self); }); }; /** * Check whether the token has expired. * * @return {Boolean} */ ClientOAuth2Token.prototype.expired = function () { if (this.expires) { return Date.now() < this.expires.getTime(); } return false; }; /** * Support resource owner password credentials OAuth 2.0 grant. * * Reference: http://tools.ietf.org/html/rfc6749#section-4.3 * * @param {ClientOAuth2} client */ function OwnerFlow (client) { this.client = client; } /** * Make a request on behalf of the user credentials to get an acces token. * * @param {String} username * @param {String} password * @param {Function} done */ OwnerFlow.prototype.getToken = function (username, password, done) { var self = this; var options = this.client.options; var authorization = btoa(options.clientId + ':' + options.clientSecret); return this.client._request({ url: options.accessTokenUri, method: 'POST', headers: { 'Accept': 'application/json, application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'Basic ' + authorization }, body: uriEncode({ scope: sanitizeScope(options.scopes), username: username, password: password, grant_type: 'password' }) }, function (err, data) { // If an error exists or the data contains an error, return `done`. if (err || (err = getAuthError(data))) { return done(err); } return done(null, new ClientOAuth2Token(self, data)); }); }; /** * Support implicit OAuth 2.0 grant. * * Reference: http://tools.ietf.org/html/rfc6749#section-4.2 * * @param {ClientOAuth2} client */ function TokenFlow (client) { this.client = client; } /** * Get the uri to redirect the user to for implicit authentication. * * @param {Object} options * @return {String} */ TokenFlow.prototype.getUri = function (options) { options = assign({}, this.client.options, options); // Check the parameters have been set. expects(options, [ 'clientId', 'redirectUri', 'authorizationUri' ]); return options.authorizationUri + '?' + uriEncode({ state: options.state, scope: sanitizeScope(options.scopes), client_id: options.clientId, redirect_uri: options.redirectUri, response_type: 'token' }); }; /** * Get the user access token from the url. * * @param {String} url * @param {String} [state] * @param {Function} done */ TokenFlow.prototype.getToken = function (url, state, done) { var options = this.client.options; var err; // State is an optional pass in. if (typeof state === 'function') { done = state; state = null; } // Make sure the url matches our expected redirect url. if (url.substr(0, options.redirectUri.length) !== options.redirectUri) { return done(new Error('Invalid url (should to match redirect): ' + url)); } var queryString = url.replace(/^[^\?]*|\#.*$/g, '').substr(1); var fragmentString = url.replace(/^[^\#]*/, '').substr(1); // Check whether a query string is present in the url. if (!queryString && !fragmentString) { return done(new Error('Unable to process url: ' + url)); } // Merge the fragment with the the query string. This is because, at least, // Instagram has a bug where the OAuth 2.0 state is being passed back as // part of the query string instead of the fragment. For example: // "?state=123#access_token=abc" var data = assign( queryString ? uriDecode(queryString) : {}, fragmentString ? uriDecode(fragmentString) : {} ); // Check if the query string was populated with a known error. if (err = getAuthError(data)) { return done(err); } // Check whether the state is correct. if (state && data.state !== state) { return done(new Error('Invalid state:' + data.state)); } // Initalize a new token and return. return done(null, new ClientOAuth2Token(this, data)); }; /** * Support client credentials OAuth 2.0 grant. * * Reference: http://tools.ietf.org/html/rfc6749#section-4.4 * * @param {ClientOAuth2} client */ function CredentialsFlow (client) { this.client = client; } /** * Request an access token using the client credentials. * * @param {Object} [options] * @param {Function} done */ CredentialsFlow.prototype.getToken = function (options, done) { var self = this; // Allow the options argument to be omitted. if (typeof options === 'function') { done = options; options = null; } options = assign({}, this.client.options, options); expects(options, [ 'clientId', 'clientSecret', 'accessTokenUri' ]); // Base64 encode the client id and secret for the Authorization header. var authorization = btoa(options.clientId + ':' + options.clientSecret); return this.client._request({ url: options.accessTokenUri, method: 'POST', headers: { 'Accept': 'application/json, application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'Basic ' + authorization }, body: uriEncode({ scope: sanitizeScope(options.scopes), grant_type: 'client_credentials' }) }, function (err, data) { // If an error exists or the data contains an error, return `done`. if (err || (err = getAuthError(data))) { return done(err); } return done(null, new ClientOAuth2Token(self, data)); }); }; /** * Support authorization code OAuth 2.0 grant. * * Reference: http://tools.ietf.org/html/rfc6749#section-4.1 * * @param {ClientOAuth2} client */ function CodeFlow (client) { this.client = client; } /** * Generate the uri for doing the first redirect. * * @return {String} */ CodeFlow.prototype.getUri = function (options) { options = assign({}, this.client.options, options); // Check the parameters have been set. expects(options, [ 'clientId', 'redirectUri', 'authorizationUri' ]); return options.authorizationUri + '?' + uriEncode({ state: options.state, scope: sanitizeScope(options.scopes), client_id: options.clientId, redirect_uri: options.redirectUri, response_type: 'code' }); }; /** * Get the code token from the redirected uri and make another request for * the user access token. * * @param {String} url * @param {String} [state] * @param {Function} done */ CodeFlow.prototype.getToken = function (url, state, done) { var self = this; var options = this.client.options; var err; // State is an optional pass in. if (typeof state === 'function') { done = state; state = null; } expects(options, [ 'clientId', 'clientSecret', 'redirectUri', 'accessTokenUri' ]); // Make sure the url matches our expected redirect url. if (url.substr(0, options.redirectUri.length) !== options.redirectUri) { return done(new Error('Invalid url (should to match redirect): ' + url)); } // Extract the query string from the url. var queryString = url.replace(/^[^\?]*|\#.*$/g, '').substr(1); // Check whether a query string is present in the url. if (!queryString) { return done(new Error('Unable to process url: ' + url)); } var query = uriDecode(queryString); // Check if the query string was populated with a known error. if (err = getAuthError(query)) { return done(err); } // Check whether the state is correct. if (state && query.state !== state) { return done(new Error('Invalid state:' + query.state)); } // Check whether the response code is set. if (!query.code) { return done(new Error('Missing code, unable to request token')); } return this.client._request({ url: options.accessTokenUri, method: 'POST', headers: { 'Accept': 'application/json, application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded' }, body: uriEncode({ code: query.code, grant_type: 'authorization_code', redirect_uri: options.redirectUri, client_id: options.clientId, client_secret: options.clientSecret }) }, function (err, data, raw) { // If an error exists or the data contains an error, return `done`. if (err || (err = getAuthError(data))) { return done(err, null, raw); } return done(null, new ClientOAuth2Token(self, data), raw); }); }; /** * Export the OAuth2 client for multiple environments. */ if (typeof define === 'function' && define.amd) { define([], function () { return ClientOAuth2; }); } else if (typeof exports === 'object') { module.exports = ClientOAuth2; } else { root.ClientOAuth2 = ClientOAuth2; } })(this); (function (root) { /** * Check if a value is empty. * * @param {*} value * @return {Boolean} */ var isEmpty = function (value) { return value == null; }; /** * Convert a value into a boolean. * * @param {String} value * @return {Boolean} */ var toBoolean = function (value) { return [0, false, '', '0', 'false'].indexOf(value) === -1; }; /** * Convert a value into a number. Non-number strings and infinite values will * sanitize into `NaN`. * * @param {String} value * @return {Number} */ var toNumber = function (value) { return isFinite(value) ? Number(value) : null; }; /** * Convert a value into an integer. Use strict sanitization - if something is * not an integer, return `NaN`. * * @param {String} value * @return {Number} */ var toInteger = function (value) { return value % 1 === 0 ? Number(value) : null; }; /** * Convert a value into a date. * * @param {String} value * @return {Date} */ var toDate = function (value) { return !isNaN(Date.parse(value)) ? new Date(value) : null; }; /** * Convert the schema config into a single sanitization function. * * @param {Object} configs * @param {Object} rules * @param {Object} types * @return {Function} */ var toSanitization = function (configs, rules, types) { configs = Array.isArray(configs) ? configs : [configs]; // Map configurations into function sanitization chains. var sanitizations = configs.map(function (config) { var fns = []; // Push type sanitization first. if (typeof types[config.type] === 'function') { fns.push(types[config.type]); } // Iterate over the schema configuration and push sanitization functions // into the sanitization array. Object.keys(config).filter(function (rule) { return rule !== 'type' && rule !== 'repeat' && rule !== 'default'; }).forEach(function (rule) { if (typeof rules[rule] === 'function') { fns.push(rules[rule](config[rule], rule, config)); } }); /** * Sanitize a single value using the function chain. Breaks when any value * returns an empty value (`null` or `undefined`). * * @param {*} value * @param {String} key * @param {Object} object * @return {*} */ var sanitize = function (value, key, object) { // Iterate over each sanitization function and return a single value. fns.every(function (fn) { value = fn(value, key, object); // Break when the value returns `null`. return value != null; }); return value; }; /** * Do the entire sanitization flow using the current config. * * @param {*} value * @param {String} key * @param {Object} object * @return {*} */ return function sanitization (value, key, object) { // Immediately return empty values with attempting to sanitize. if (isEmpty(value)) { // Fallback to providing the default value instead. if (config.default != null) { return sanitization(config.default, key, object); } // Return an empty array for repeatable values. return config.repeat && !config.required ? [] : value; } // Support repeated parameters as arrays. if (config.repeat) { // Turn the result into an array if (!Array.isArray(value)) { value = [value]; } // Map every value to be sanitized into a new array. value = value.map(function (value) { return sanitize(value, key, object); }); // If any of the values are empty, refuse the sanitization. return value.some(isEmpty) ? null : value; } return sanitize(value, key, object); }; }); /** * Pass in a value to be sanitized. * * @param {*} value * @param {String} key * @param {Object} object * @return {*} */ return function (value, key, object) { var result = value; // Iterate over each sanitization until one is not empty. sanitizations.some(function (sanitization) { var sanitized = sanitization(value, key, object); // If the value was accepted and sanitized, return it. if (sanitized != null) { // Assign the sanitized value to the result. result = sanitized; return true; } return false; }); return result; }; }; /** * Every time the module is exported and executed, we return a new instance. * * @return {Function} */ RAMLSanitize = function () { /** * Return a sanitization function based on the passed in schema. * * @param {Object} schema * @return {Function} */ var sanitize = function (schema) { var sanitizations = {}; // Map each parameter in the schema to a validation function. Object.keys(schema).forEach(function (param) { var config = schema[param]; var types = sanitize.TYPES; var rules = sanitize.RULES; sanitizations[param] = toSanitization(config, rules, types); }); /** * Execute the returned function with a model to return a sanitized object. * * @param {Object} model * @return {Object} */ return function (model) { model = model || {}; // Create a new model instance to be sanitized without any additional // properties or overrides occuring. var sanitized = {}; // Iterate only the sanitized parameters to get a clean model. Object.keys(sanitizations).forEach(function (param) { var value = model[param]; var sanitize = sanitizations[param]; // Ensure the value is a direct property on the model object before // sanitizing. The keeps model handling in sync with expectations. if (Object.prototype.hasOwnProperty.call(model, param)) { sanitized[param] = sanitize(value, param, model); } }); return sanitized; }; }; /** * Provide sanitization based on types. * * @type {Object} */ sanitize.TYPES = { string: String, number: toNumber, integer: toInteger, boolean: toBoolean, date: toDate }; /** * Provide sanitization based on rules. * * @type {Object} */ sanitize.RULES = {}; return sanitize; }; /** * Export the raml-sanitize for multiple environments. */ if (typeof define === 'function' && define.amd) { define([], function () { return RAMLSanitize; }); } else if (typeof exports === 'object') { module.exports = RAMLSanitize; } else { root.RAMLSanitize = RAMLSanitize; } })(this); (function (root) { /** * `Object.prototype.toString` as a function. * * @type {Function} */ var toString = Function.prototype.call.bind(Object.prototype.toString); /** * Check the value is a valid date. * * @param {Date} check * @return {Boolean} */ var isDate = function (check) { return toString(check) === '[object Date]' && !isNaN(check.getTime()); }; /** * Check if the value is a boolean. * * @param {Boolean} check * @return {Boolean} */ var isBoolean = function (check) { return typeof check === 'boolean'; }; /** * Check the value is a string. * * @param {String} check * @return {Boolean} */ var isString = function (check) { return typeof check === 'string'; }; /** * Check if the value is an integer. * * @param {Number} check * @return {Boolean} */ var isInteger = function (check) { return typeof check === 'number' && check % 1 === 0; }; /** * Check if the value is a number. * * @param {Number} check * @return {Boolean} */ var isNumber = function (check) { return typeof check === 'number' && isFinite(check); }; /** * Check a number is not smaller than the minimum. * * @param {Number} min * @return {Function} */ var isMinimum = function (min) { return function (check) { return check >= min; }; }; /** * Check a number doesn't exceed the maximum. * * @param {Number} max * @return {Boolean} */ var isMaximum = function (max) { return function (check) { return check <= max; }; }; /** * Check a string is not smaller than a minimum length. * * @param {Number} min * @return {Boolean} */ var isMinimumLength = function (min) { return function (check) { return check.length >= min; }; }; /** * Check a string does not exceed a maximum length. * * @param {Number} max * @return {Boolean} */ var isMaximumLength = function (max) { return function (check) { return check.length <= max; }; }; /** * Check a value is equal to anything in an array. * * @param {Array} values * @return {Function} */ var isEnum = function (values) { return function (check) { return values.indexOf(check) > -1; }; }; /** * Check if a pattern matches the value. * * @param {(String|RegExp)} pattern * @return {Function} */ var isPattern = function (pattern) { if (toString(pattern) !== '[object RegExp]') { pattern = new RegExp(pattern); } return pattern.test.bind(pattern); }; /** * Convert arguments into an object. * * @param {Boolean} valid * @param {String} rule * @param {*} value * @param {String} key * @return {Object} */ var toValidationObject = function (valid, rule, value, key) { return { valid: valid, rule: rule, value: value, key: key }; }; /** * Convert a single config into a function. * * @param {Object} config * @param {Object} rules * @return {Function} */ var toValidationFunction = function (config, rules) { var fns = []; // Iterate over all of the keys and dynamically push validation rules. Object.keys(config).forEach(function (rule) { if (rules.hasOwnProperty(rule)) { fns.push([rule, rules[rule](config[rule], rule)]); } }); /** * Run every validation that has been attached. * * @param {String} value * @param {String} value * @param {Object} object * @return {Object} */ return function (value, key, object) { // Run each of the validations returning early when something fails. for (var i = 0; i < fns.length; i++) { var valid = fns[i][1](value, key, object); if (!valid) { return toValidationObject(false, fns[i][0], value, key); } } return toValidationObject(true, null, value, key); }; }; /** * Convert a rules object into a simple validation function. * * @param {Object} configs * @param {Object} rules * @param {Object} types * @return {Function} */ var toValidation = function (configs, rules, types) { // Initialize the configs to an array if they aren't already. configs = Array.isArray(configs) ? configs : [configs]; var isOptional = !configs.length; var simpleValidations = []; var repeatValidations = []; // Support multiple type validations. configs.forEach(function (config) { var validation = [config.type, toValidationFunction(config, rules)]; // Allow short-circuiting of non-required values. if (!config.required) { isOptional = true; } // Push validations into each stack depending on the "repeat". if (config.repeat) { repeatValidations.push(validation); } else { simpleValidations.push(validation); } }); /** * Validate a value based on "type" and "repeat". * * @param {*} value * @param {String} key * @param {Object} object * @return {Object} */ return function (value, key, object) { // Short-circuit validation if the value is `null`. if (value == null) { return toValidationObject(isOptional, 'required', value, key); } // Switch validation type depending on if the value is an array or not. var isArray = Array.isArray(value); // Select the validation stack to use based on the (repeated) value. var values = isArray ? value : [value]; var validations = isArray ? repeatValidations : simpleValidations; // Set the initial response to be an error. var response = toValidationObject( false, validations.length ? 'type' : 'repeat', value, key ); // Iterate over each value and test using type validation. validations.some(function (validation) { // Non-existant types should always be invalid. if (!types.hasOwnProperty(validation[0])) { return false; } // Check all the types match. If they don't, attempt another validation. var isType = values.every(function (value) { return types[validation[0]](value, key, object); }); // Skip to the next check if not all types match. if (!isType) { return false; } // When every value is the correct type, run the validation on each value // and break the loop if we get a failure. values.every(function (value) { return (response = validation[1](value, key, object)).valid; }); // Always break the loop when the type was successful. If anything has // failed, `response` will have been set to the invalid object. return true; }); return response; }; }; /** * Every time you require the module you're expected to call it as a function * to create a new instance. This is to ensure two modules can't make competing * changes with their own validation rules. * * @return {Function} */ RAMLValidate = function () { /** * Return a validation function that validates a model based on the schema. * * @param {Object} schema * @return {Function} */ var validate = function (schema) { var validations = {}; // Convert all parameters into validation functions. Object.keys(schema).forEach(function (param) { var config = schema[param]; var rules = validate.RULES; var types = validate.TYPES; validations[param] = toValidation(config, rules, types); }); /** * The function accepts an object to be validated. All rules are already * precompiled. * * @param {Object} model * @return {Boolean} */ return function (model) { model = model || {}; // Map all validations to their object and filter for failures. var errors = Object.keys(validations).map(function (param) { var value = model[param]; var validation = validations[param]; // Return the validation result. return validation(value, param, model); }).filter(function (validation) { return !validation.valid; }); return { valid: errors.length === 0, errors: errors }; }; }; /** * Provide validation of types. * * @type {Object} */ validate.TYPES = { date: isDate, number: isNumber, integer: isInteger, boolean: isBoolean, string: isString }; /** * Provide overridable validation of parameters. * * @type {Object} */ validate.RULES = { minimum: isMinimum, maximum: isMaximum, minLength: isMinimumLength, maxLength: isMaximumLength, enum: isEnum, pattern: isPattern }; /** * Return the validate function. */ return validate; }; /** * Export the raml-validate for multiple environments. */ if (typeof define === 'function' && define.amd) { define([], function () { return RAMLValidate; }); } else if (typeof exports === 'object') { module.exports = RAMLValidate; } else { root.RAMLValidate = RAMLValidate; } })(this); angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache) { 'use strict'; $templateCache.put('directives/close-button.tpl.html', "\n" ); $templateCache.put('directives/documentation.tpl.html', "
\n" + " \n" + "
\n" + "

\n" + " Request\n" + "

\n" + "
\n" + "
\n" + "

Description

\n" + "\n" + "

\n" + "\n" + "
\n" + "

URI Parameters

\n" + "\n" + "
\n" + "

{{uriParam[0].displayName}}{{parameterDocumentation(uriParam[0])}}

\n" + "

\n" + "\n" + "

\n" + " Example: {{uriParam[0].example}}\n" + "

\n" + "
\n" + "
\n" + "\n" + "
\n" + "

Headers

\n" + "\n" + "
\n" + "

{{header[0].displayName}}{{parameterDocumentation(header[0])}}

\n" + "\n" + "

\n" + "\n" + "

\n" + " Example: {{header[0].example}}\n" + "

\n" + "
\n" + "
\n" + "\n" + "
\n" + "

Query Parameters

\n" + "\n" + "
\n" + "

{{queryParam[0].displayName}}{{parameterDocumentation(queryParam[0])}}

\n" + "\n" + "

\n" + "\n" + "

\n" + " Example: {{queryParam[0].example}}\n" + "

\n" + "
\n" + "
\n" + "\n" + "
\n" + "

Security Schemes

\n" + "
    \n" + "
  1. {{value.name}}
  2. \n" + "
\n" + "\n" + "

\n" + "\n" + "
\n" + "

Headers

\n" + "\n" + "
\n" + "

{{key}}{{parameterDocumentation(header)}}

\n" + "\n" + "

\n" + "\n" + "

\n" + " Example: {{header.example}}\n" + "

\n" + "
\n" + "
\n" + "\n" + "
\n" + "

Query Parameters

\n" + "\n" + "
\n" + "

{{key}}{{parameterDocumentation(queryParameter)}}

\n" + "\n" + "

\n" + "\n" + "

\n" + " Example: {{queryParameter.example}}\n" + "

\n" + "
\n" + "
\n" + "\n" + "
\n" + "

Responses

\n" + "\n" + "
\n" + "

{{code}}

\n" + "

\n" + "
\n" + "
\n" + "\n" + "
\n" + "

Settings

\n" + "\n" + "
\n" + "

{{key}}

\n" + "

{{schemaSettingsDocumentation(config)}}

\n" + "
\n" + "
\n" + "
\n" + "\n" + "\n" + "
\n" + "

\n" + " Body\n" + "

\n" + "\n" + "

\n" + " {{key}}\n" + "

\n" + "\n" + "
\n" + "
\n" + "

{{formParam[0].displayName}}{{parameterDocumentation(formParam[0])}}

\n" + "\n" + "

\n" + "\n" + "

\n" + " Example: {{formParam[0].example}}\n" + "

\n" + "
\n" + "
\n" + "\n" + "
\n" + " Example:\n" + "
\n" + "
\n" + "\n" + "
\n" + "

\n" + "
\n" + "
\n" + "
\n" + "
\n" + "\n" + " \n" + "
\n" + "
\n" + "

\n" + " Response\n" + "

\n" + "
\n" + "\n" + "
\n" + "
    \n" + "
  • \n" + " \n" + "
  • \n" + "
\n" + "
\n" + "\n" + "
\n" + "
\n" + " \n" + "

Status {{code}}

\n" + "\n" + "
\n" + "

\n" + "
\n" + "\n" + "
\n" + "

Headers

\n" + "\n" + "
\n" + "

{{header[0].displayName}} {{header[0].type}}

\n" + "\n" + "

\n" + "
\n" + "
\n" + "\n" + "
\n" + "

\n" + " Body\n" + " {{key}}\n" + "

\n" + "\n" + "
\n" + " Example:\n" + "
\n" + "
\n" + "\n" + "
\n" + "

\n" + "
\n" + "
\n" + "
\n" + "
\n" + "\n" + "
\n" + "
\n" + "
\n" ); $templateCache.put('directives/method-list.tpl.html', "
\n" + "
\n" + " {{method.method.toLocaleUpperCase()}}\n" + "
\n" + "
\n" ); $templateCache.put('directives/named-parameters.tpl.html', "
\n" + "
\n" + "

{{title}}

\n" + " \n" + "
\n" + "\n" + "
\n" + "

\n" + " \n" + " \n" + " \n" + "

\n" + "\n" + "

{{$parent.methodInfo.method.toUpperCase()}}

\n" + "
\n" + "
\n" + "
{{segment.name}}
\n" + "
{{context[type].values[segment.name][0]}}
\n" + "
{{{segment.name}}}
\n" + "
\n" + "
\n" + "\n" + "

\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n" + " \n" + "

\n" + "
\n" + "
\n" ); $templateCache.put('directives/raml-client-generator.tpl.html', "
\n" + " \n" + " Download API Client\n" + " \n" + "\n" + " \n" + "
\n" ); $templateCache.put('directives/raml-field.tpl.html', "
\n" + " \n" + "\n" + " \n" + " \n" + " \n" + " Use example value\n" + " \n" + " \n" + "\n" + " \n" + "\n" + " \n" + "\n" + " \n" + "\n" + " \n" + "
\n" ); $templateCache.put('directives/raml-initializer.tpl.html', "
\n" + "
\n" + "

RAML Console

\n" + "\n" + "
\n" + "
\n" + "
\n" + "

Initialize from the URL of a RAML file

\n" + "
\n" + "\n" + "
\n" + "

\n" + " \n" + "

\n" + "
\n" + " {{errorMessage}}\n" + "
\n" + "
\n" + " \n" + "
\n" + "
\n" + "
\n" + "\n" + "
\n" + "
\n" + "

or parse RAML in here

\n" + "
\n" + "\n" + "
\n" + "

\n" + " \n" + "

\n" + "
\n" + " \n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "\n" + " \n" + "\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" ); $templateCache.put('directives/resource-panel.tpl.html', "
\n" + "
\n" + " \n" + "\n" + " \n" + "\n" + "
\n" + " \n" + "
\n" + "\n" + "
\n" + " \n" + "
\n" + "
\n" + "
\n" ); $templateCache.put('directives/root-documentation.tpl.html', "
    \n" + "
  1. 0\">\n" + "
    \n" + " collapseexpand all\n" + "
    \n" + "

    \n" + " Documentation\n" + "

    \n" + "
    \n" + "
    \n" + "
  2. \n" + "\n" + "
  3. \n" + "
    \n" + "
    \n" + "
    \n" + "

    \n" + " \n" + " {{doc.title}}\n" + "

    \n" + " \n" + "
    \n" + " \n" + "
    \n" + "\n" + "
    \n" + "
    \n" + "
    \n" + "
    \n" + "
    \n" + "\n" + "
      \n" + "
    1. \n" + "
      \n" + "
      \n" + "

      \n" + "
      \n" + "
      {{header.label}}
      \n" + "
      \n" + "

      \n" + "
      \n" + "
      \n" + "
    2. \n" + "
    \n" + "
    \n" + "
  4. \n" + "
\n" ); $templateCache.put('directives/sidebar.tpl.html', "
\n" + "
\n" + "
\n" + "
\n" + "

\n" + " Try it\n" + "
×
\n" + "
×
\n" + "\n" + "
×
\n" + "\n" + " \n" + " \n" + "\n" + " \n" + " \n" + "

\n" + "
\n" + "\n" + "
\n" + "
1\">\n" + "
\n" + "

Protocols

\n" + "
\n" + "
\n" + " \n" + "
\n" + "
\n" + "\n" + "
\n" + "
\n" + "

Authentication

\n" + "
\n" + "\n" + "
\n" + "
\n" + " \n" + " \n" + "
\n" + "
\n" + "\n" + "
\n" + " \n" + " \n" + " \n" + "
\n" + "
\n" + "\n" + " \n" + "\n" + " \n" + "\n" + " \n" + "\n" + "
\n" + "
\n" + "

Body

\n" + "
\n" + "\n" + "
\n" + " \n" + "
\n" + "\n" + "
\n" + "
\n" + "
\n" + "
\n" + " \n" + "
\n" + "
\n" + "\n" + "\n" + "
\n" + "

\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n" + " \n" + "

\n" + "
\n" + "
\n" + "
\n" + "\n" + "
\n" + "
\n" + "
\n" + " \n" + " \n" + " \n" + " \n" + "
\n" + "
\n" + "
\n" + "\n" + "
\n" + "
\n" + "
\n" + "

\n" + " \n" + "

\n" + "
\n" + "
\n" + "\n" + "
\n" + "
\n" + "

Request URL

\n" + "
\n" + " \n" + "
\n" + "
\n" + "\n" + "
\n" + "

Headers

\n" + "
\n" + "

\n" + " {{key}}:
{{getHeaderValue(value)}}\n" + "

\n" + "
\n" + "
\n" + "\n" + "
\n" + "

Body

\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "

\n" + " {{key}}:
{{value}}\n" + "

\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "\n" + "
\n" + "
\n" + "

\n" + " \n" + "

\n" + "
\n" + "\n" + "
\n" + "

Status

\n" + "

{{response.status}}

\n" + "\n" + "

Headers

\n" + "
\n" + "

\n" + " {{key}}:
{{value}}\n" + "

\n" + "
\n" + "
\n" + "

Body

\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" ); $templateCache.put('directives/spinner.tpl.html', "\n" ); $templateCache.put('directives/theme-switcher.tpl.html', "
\n" + " Switch Theme\n" + "
\n" ); $templateCache.put('resources/resource-type.tpl.html', "Type: {{resource.resourceType}}\n" ); $templateCache.put('resources/resources.tpl.html', "
\n" + "\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "\n" + "
\n" + "
\n" + " \n" + " \n" + "
\n" + "\n" + "

{{raml.title}}

\n" + "\n" + " \n" + "\n" + "
    \n" + "
  1. \n" + "
    \n" + " \n" + " \n" + "
    \n" + "
    \n" + " \n" + " collapse\n" + " expand all\n" + " \n" + "\n" + "
    \n" + "

    \n" + " Resources\n" + "

    \n" + "
    \n" + " \n" + "
    \n" + "
  2. \n" + "\n" + "
  3. \n" + "
    \n" + "
    \n" + " \n" + "\n" + "

    \n" + " 1\" class=\"raml-console-resource-path-active\" ng-class=\"{'raml-console-resource-heading-hover':resourceGroup.length > 1}\" ng-repeat='segment in resource.pathSegments' ng-click=\"toggle($event, index, resourceList, 'resourcesCollapsed')\">{{segment.toString()}}\n" + "\n" + " {{segment.toString()}}\n" + "

    \n" + "\n" + " \n" + "\n" + " Traits: {{readTraits(methodInfo.is)}}\n" + "\n" + " Traits: {{readResourceTraits(resource.traits)}}\n" + "\n" + " \n" + "\n" + "
    \n" + " \n" + " \n" + "
    \n" + "\n" + " \n" + "\n" + " \n" + "
      \n" + "\n" + "
    1. \n" + "
      \n" + "
      \n" + "

      \n" + " {{segment.toString()}}{{segment.toString()}}\n" + "

      \n" + "\n" + " \n" + " Traits: {{readTraits(methodInfo.is)}}\n" + "\n" + " Traits: {{readResourceTraits(resource.traits)}}\n" + "\n" + " \n" + "
      \n" + "\n" + " \n" + " \n" + "
      \n" + "\n" + " \n" + "
    2. \n" + "
    \n" + "\n" + "
  4. \n" + "
\n" + "
\n" + "
\n" ); $templateCache.put('security/basic_auth.tpl.html', "
\n" + "

\n" + " \n" + " \n" + " \n" + "

\n" + "\n" + "

\n" + " \n" + " \n" + " \n" + "

\n" + "
\n" ); $templateCache.put('security/oauth1.tpl.html', "
\n" + "

\n" + " \n" + " \n" + " \n" + "

\n" + "\n" + "

\n" + " \n" + " \n" + " \n" + "

\n" + "
\n" ); $templateCache.put('security/oauth2.tpl.html', "
\n" + "

\n" + " \n" + " \n" + "

\n" + "\n" + "

\n" + " \n" + " \n" + " \n" + "

\n" + "\n" + "

\n" + " \n" + " \n" + " \n" + "

\n" + "\n" + "

\n" + " \n" + " \n" + " \n" + "

\n" + "\n" + "

\n" + " \n" + " \n" + " \n" + "

\n" + "\n" + "

\n" + " \n" + "

    \n" + "
  1. \n" + " {{scope}}\n" + "
  2. \n" + "
\n" + "

\n" + "
\n" ); }]);




© 2015 - 2025 Weber Informatics LLC | Privacy Policy