19751975
19761976 Object . keys ( definitions ) . map ( function ( key ) {
19771977 if ( typeof definitions [ key ] . reset !== 'undefined' ) {
1978- definitions [ key ] . reset ( $scope . methodInfo . body [ key ] . formParameters ) ;
1978+ //Reset formParameters or properties depending on RAML version
1979+ var body = $scope . methodInfo . body [ key ] ;
1980+ var parameters = body . formParameters ? body . formParameters : body . properties ;
1981+ definitions [ key ] . reset ( parameters ) ;
19791982 } else {
19801983 definitions [ key ] . fillWithExample ( ) ;
19811984 if ( definitions [ key ] . value ) {
20222025 }
20232026
20242027 function expandBodyExamples ( $scope , methodInfo ) {
2025- if ( methodInfo . body ) {
2026- Object . keys ( methodInfo . body ) . forEach ( function ( key ) {
2027- var bodyType = methodInfo . body [ key ] ;
2028- var type = bodyType . type ? RAML . Inspector . Types . findType ( bodyType . type [ 0 ] , $scope . types ) : undefined ;
2029- if ( ! bodyType . example && type && type . example ) {
2030- bodyType . example = type . example ;
2028+ function expandExamples ( body ) {
2029+ Object . keys ( body ) . forEach ( function ( key ) {
2030+ var info = body [ key ] ;
2031+ var type = info . type ? RAML . Inspector . Types . findType ( info . type [ 0 ] , $scope . types ) : undefined ;
2032+ if ( ! body . example && type && type . example ) {
2033+ info . example = type . example ;
2034+ }
2035+
2036+ if ( info . properties ) {
2037+ expandExamples ( info . properties ) ;
20312038 }
20322039 } ) ;
20332040 }
2041+
2042+ if ( methodInfo . body ) {
2043+ expandExamples ( methodInfo . body ) ;
2044+ }
20342045 return methodInfo ;
20352046 }
20362047
20482059
20492060 $scope . methodInfo = expandBodyExamples ( $scope , methodInfo ) ;
20502061 $scope . responseInfo = getResponseInfo ( $scope ) ;
2051- $scope . context = new RAML . Services . TryIt . Context ( $scope . raml . baseUriParameters , resource , $scope . methodInfo ) ;
2062+ $scope . context = new RAML . Services . TryIt . Context ( $scope . raml . baseUriParameters , resource , $scope . methodInfo , $scope . types ) ;
20522063 $scope . requestUrl = '' ;
20532064 $scope . response = { } ;
20542065 $scope . requestOptions = { } ;
29762987 $scope . context . bodyContent . definitions [ $scope . context . bodyContent . selected ] . value = event . files [ 0 ] ;
29772988 } ;
29782989
2979- $scope . hasFormParameters = $scope . context . bodyContent && $scope . context . bodyContent . selected ? $scope . methodInfo . body [ $scope . context . bodyContent . selected ] . hasOwnProperty ( 'formParameters' ) : undefined ;
2980-
2981- $scope . getExample = function ( param ) {
2982- var definitions = $scope . context . bodyContent . definitions [ $scope . context . bodyContent . selected ] ;
2983- var example = definitions . contentType [ param . name ] . example ;
2984- return example ? [ example ] : example ;
2985- } ;
29862990 } ]
29872991 } ;
29882992 } ;
@@ -5143,7 +5147,17 @@ RAML.Inspector = (function() {
51435147 var FORM_URLENCODED = 'application/x-www-form-urlencoded' ;
51445148 var FORM_DATA = 'multipart/form-data' ;
51455149
5146- var BodyContent = function ( contentTypes ) {
5150+ var BodyContent = function ( contentTypes , types ) {
5151+ function toObjectArray ( properties ) {
5152+ Object . keys ( properties ) . forEach ( function ( property ) {
5153+ if ( ! Array . isArray ( properties [ property ] ) ) {
5154+ properties [ property ] . id = properties [ property ] . name ;
5155+ properties [ property ] = [ properties [ property ] ] ;
5156+ }
5157+ } ) ;
5158+ return properties ;
5159+ }
5160+
51475161 this . contentTypes = Object . keys ( contentTypes ) . sort ( ) ;
51485162 this . selected = this . contentTypes [ 0 ] ;
51495163
@@ -5163,8 +5177,23 @@ RAML.Inspector = (function() {
51635177 //For RAML 0.8 formParameters should be defined, but for RAML 1.0 properties node
51645178 if ( definition . formParameters ) {
51655179 definitions [ contentType ] = new RAML . Services . TryIt . NamedParameters ( definition . formParameters ) ;
5166- } else if ( definition . properties ) {
5167- definitions [ contentType ] = new RAML . Services . TryIt . BodyType ( definition . properties ) ;
5180+ } else {
5181+ var type = definition . type [ 0 ] ;
5182+ var isNativeType = RAML . Inspector . Types . isNativeType ( type ) ;
5183+
5184+ var inlineProperties ;
5185+ if ( definition . properties ) {
5186+ inlineProperties = toObjectArray ( definition . properties ) ;
5187+ }
5188+
5189+ var rootProperties ;
5190+ if ( ! isNativeType && types ) {
5191+ var rootType = RAML . Inspector . Types . findType ( type , types ) ;
5192+ rootProperties = rootType && rootType . properties ? toObjectArray ( rootType . properties ) : undefined ;
5193+ }
5194+
5195+ var properties = Object . assign ( { } , inlineProperties , rootProperties ) ;
5196+ definitions [ contentType ] = new RAML . Services . TryIt . NamedParameters ( properties ) ;
51685197 }
51695198 break ;
51705199 default :
@@ -5277,7 +5306,7 @@ RAML.Inspector = (function() {
52775306( function ( ) {
52785307 'use strict' ;
52795308
5280- var Context = function ( baseUriParameters , resource , method ) {
5309+ var Context = function ( baseUriParameters , resource , method , types ) {
52815310 this . headers = new RAML . Services . TryIt . NamedParameters ( method . headers . plain , method . headers . parameterized ) ;
52825311 this . queryParameters = new RAML . Services . TryIt . NamedParameters ( method . queryParameters ) ;
52835312
@@ -5296,7 +5325,7 @@ RAML.Inspector = (function() {
52965325 this . uriParameters = new RAML . Services . TryIt . NamedParameters ( resource . uriParametersForDocumentation ) ;
52975326
52985327 if ( method . body ) {
5299- this . bodyContent = new RAML . Services . TryIt . BodyContent ( method . body ) ;
5328+ this . bodyContent = new RAML . Services . TryIt . BodyContent ( method . body , types ) ;
53005329 }
53015330
53025331 this . pathBuilder = new RAML . Client . PathBuilder . create ( resource . pathSegments ) ;
@@ -5444,7 +5473,6 @@ RAML.Inspector = (function() {
54445473 NamedParameters . prototype . remove = function ( name ) {
54455474 delete this . plain [ name ] ;
54465475 delete this . values [ name ] ;
5447- return ;
54485476 } ;
54495477
54505478 NamedParameters . prototype . data = function ( ) {
@@ -6945,26 +6973,36 @@ RAML.Inspector = (function() {
69456973 } ;
69466974
69476975 /**
6948- * Check a string is not smaller than a minimum length.
6976+ * Check a string (or file) is not smaller than a minimum length.
6977+ * This facet can be defined for string and file
69496978 *
69506979 * @param {Number } min
69516980 * @return {Function }
69526981 */
69536982 var isMinimumLength = function ( min ) {
69546983 return function ( check ) {
6955- return check . length >= min ;
6984+ if ( check . constructor === File ) {
6985+ return check . size <= min ;
6986+ } else {
6987+ return check . length >= min ;
6988+ }
69566989 } ;
69576990 } ;
69586991
69596992 /**
6960- * Check a string does not exceed a maximum length.
6993+ * Check a string (or file) does not exceed a maximum length.
6994+ * This facet can be defined for string and file
69616995 *
69626996 * @param {Number } max
69636997 * @return {Function }
69646998 */
69656999 var isMaximumLength = function ( max ) {
69667000 return function ( check ) {
6967- return check . length <= max ;
7001+ if ( check . constructor === File ) {
7002+ return check . size <= max ;
7003+ } else {
7004+ return check . length <= max ;
7005+ }
69687006 } ;
69697007 } ;
69707008
@@ -7002,7 +7040,7 @@ RAML.Inspector = (function() {
70027040 */
70037041 var isValidFileTypes = function ( values ) {
70047042 return function ( check ) {
7005- check = check . toLowerCase ( ) ;
7043+ check = check . type ;
70067044 var checkInValue = values . find ( function ( value ) {
70077045 return value . toLowerCase ( ) === check
70087046 } ) ;
@@ -7827,7 +7865,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
78277865 " <option ng-repeat=\"enum in unique(getEnum(param))\" value=\"{{enum}}\" ng-selected=\"{{param.example === enum}}\">{{enum}}</option>\n" +
78287866 " </select>\n" +
78297867 "\n" +
7830- " <input id=\"{{param.id}}\" ng-hide =\"! isDefault(param)\" class=\"raml-console-sidebar-input\" ng-model=\"model[0]\" ng-class=\"{'raml-console-sidebar-field-no-default': !hasExampleValue(param)}\" validate=\"param\" dynamic-name=\"param.id\" ng-change=\"onChange()\"/>\n" +
7868+ " <input id=\"{{param.id}}\" ng-if =\"isDefault(param)\" class=\"raml-console-sidebar-input\" ng-model=\"model[0]\" ng-class=\"{'raml-console-sidebar-field-no-default': !hasExampleValue(param)}\" validate=\"param\" dynamic-name=\"param.id\" ng-change=\"onChange()\"/>\n" +
78317869 "\n" +
78327870 " <input ng-if=\"isFile(param)\" id=\"{{param.id}}\" type=\"file\" class=\"raml-console-sidebar-input-file\" ng-model=\"model[0]\" validate=\"param\"\n" +
78337871 " dynamic-name=\"param.id\"\n" +
@@ -8301,35 +8339,20 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
83018339 "\n" +
83028340 " <div ng-switch-when=\"true\">\n" +
83038341 "\n" +
8304- " <div ng-switch=\"hasFormParameters\">\n" +
8305- " <div ng-switch-when=\"true\">\n" +
8306- " <p class=\"raml-console-sidebar-input-container\" ng-repeat=\"param in context.bodyContent.definitions[context.bodyContent.selected].plain\">\n" +
8307- " <span class=\"raml-console-sidebar-input-tooltip-container\" ng-init=\"paramDescription = param.definitions[0].description\" ng-if=\"paramDescription\">\n" +
8308- " <button tabindex=\"-1\" class=\"raml-console-sidebar-input-tooltip\"><span class=\"raml-console-visuallyhidden\">Show documentation</span></button>\n" +
8309- " <span class=\"raml-console-sidebar-tooltip-flyout\">\n" +
8310- " <span markdown=\"paramDescription\" class=\"raml-console-marked-content\"></span>\n" +
8311- " </span>\n" +
8312- " </span>\n" +
8313- "\n" +
8314- " <raml-field context=\"context\" type=\"type\" types=\"types\" param=\"param.definitions[0]\" model=\"context.bodyContent.definitions[context.bodyContent.selected].values[param.definitions[0].id]\"></raml-field>\n" +
8315- " </p>\n" +
8316- " </div>\n" +
8317- "\n" +
8318- " <div ng-switch-when=\"false\">\n" +
8319- " <p class=\"raml-console-sidebar-input-container\" ng-repeat=\"(key, param) in context.bodyContent.definitions[context.bodyContent.selected].contentType\">\n" +
8320- " <span class=\"raml-console-sidebar-input-tooltip-container\" ng-init=\"paramDescription = param.description\" ng-if=\"paramDescription\">\n" +
8321- " <button tabindex=\"-1\" class=\"raml-console-sidebar-input-tooltip\"><span class=\"raml-console-visuallyhidden\">Show documentation</span></button>\n" +
8322- " <span class=\"raml-console-sidebar-tooltip-flyout\">\n" +
8323- " <span markdown=\"paramDescription\" class=\"raml-console-marked-content\"></span>\n" +
8324- " </span>\n" +
8325- " </span>\n" +
8326- "\n" +
8327- " <span ng-init=\"paramModel = getExample(param)\">\n" +
8328- " <raml-field context=\"context\" type=\"type\" types=\"types\" param=\"param\" model=\"paramModel\"></raml-field>\n" +
8329- " </span>\n" +
8330- " </p>\n" +
8331- " </div>\n" +
8332- " </div>\n" +
8342+ " <p class=\"raml-console-sidebar-input-container\"\n" +
8343+ " ng-repeat=\"param in context.bodyContent.definitions[context.bodyContent.selected].plain\">\n" +
8344+ " <span class=\"raml-console-sidebar-input-tooltip-container\"\n" +
8345+ " ng-init=\"paramDescription = param.definitions[0].description\" ng-if=\"paramDescription\">\n" +
8346+ " <button tabindex=\"-1\" class=\"raml-console-sidebar-input-tooltip\"><span\n" +
8347+ " class=\"raml-console-visuallyhidden\">Show documentation</span></button>\n" +
8348+ " <span class=\"raml-console-sidebar-tooltip-flyout\">\n" +
8349+ " <span markdown=\"paramDescription\" class=\"raml-console-marked-content\"></span>\n" +
8350+ " </span>\n" +
8351+ " </span>\n" +
8352+ "\n" +
8353+ " <raml-field context=\"context\" type=\"type\" types=\"types\" param=\"param.definitions[0]\"\n" +
8354+ " model=\"context.bodyContent.definitions[context.bodyContent.selected].values[param.definitions[0].id]\"></raml-field>\n" +
8355+ " </p>\n" +
83338356 "\n" +
83348357 " </div>\n" +
83358358 " </div>\n" +
0 commit comments