124124 return {
125125 restrict : 'E' ,
126126 templateUrl : 'directives/documentation.tpl.html' ,
127- replace : true ,
128127 controller : [ '$scope' , function ( $scope ) {
129128 var defaultSchemaKey = Object . keys ( $scope . securitySchemes ) . sort ( ) [ 0 ] ;
130129 var defaultSchema = $scope . securitySchemes [ defaultSchemaKey ] ;
131130
132131 $scope . markedOptions = RAML . Settings . marked ;
133132 $scope . documentationSchemeSelected = defaultSchema ;
134133
134+ function mergeResponseCodes ( methodCodes , schemas ) {
135+ var extractSchema = function ( key ) { return schemas . hasOwnProperty ( key ) ? schemas [ key ] : undefined ; } ;
136+ var isValidSchema = function ( schema ) { return schema . describedBy && schema . describedBy . responses ; } ;
137+
138+ var codes = { } ;
139+
140+ // Copy all method codes
141+ Object . keys ( methodCodes ) . forEach ( function ( code ) {
142+ if ( methodCodes . hasOwnProperty ( code ) ) { codes [ code ] = methodCodes [ code ] ; }
143+ } ) ;
144+
145+ // Copy schema's code that are not present in the method
146+ Object . keys ( schemas )
147+ . map ( extractSchema )
148+ . filter ( isValidSchema )
149+ . forEach ( function ( schema ) { copyToCodesIfNotPresent ( codes , schema . describedBy . responses ) ; } ) ;
150+
151+ return codes ;
152+ }
153+
154+ function copyToCodesIfNotPresent ( codes , schemaCodes ) {
155+ if ( Array . isArray ( schemaCodes ) ) {
156+ schemaCodes . forEach ( function ( response ) {
157+ if ( ! codes . hasOwnProperty ( response . code ) ) {
158+ codes [ response . code ] = response . code ;
159+ }
160+ } ) ;
161+ } else {
162+ Object . keys ( schemaCodes ) . forEach ( function ( code ) {
163+ if ( schemaCodes . hasOwnProperty ( code ) && ! codes . hasOwnProperty ( code ) ) {
164+ codes [ code ] = schemaCodes [ code ] ;
165+ }
166+ } ) ;
167+ }
168+ }
169+ $scope . fullResponses = mergeResponseCodes ( $scope . methodInfo . responses || { } , $scope . methodInfo . securitySchemes ( ) ) ;
170+ $scope . fullResponseCodes = Object . keys ( $scope . fullResponses ) ;
171+
135172 $scope . isSchemeSelected = function isSchemeSelected ( scheme ) {
136173 return scheme . id === $scope . documentationSchemeSelected . id ;
137174 } ;
156193
157194 $scope . currentStatusCode = '200' ;
158195
159- if ( $scope . methodInfo . responseCodes && $scope . methodInfo . responseCodes . length > 0 ) {
160- $scope . currentStatusCode = $scope . methodInfo . responseCodes [ 0 ] ;
196+ if ( $scope . fullResponseCodes && $scope . fullResponseCodes . length > 0 ) {
197+ $scope . currentStatusCode = $scope . fullResponseCodes [ 0 ] ;
161198 }
162199
163200 $scope . $on ( 'resetData' , function ( ) {
164- if ( $scope . methodInfo . responseCodes && $scope . methodInfo . responseCodes . length > 0 ) {
165- $scope . currentStatusCode = $scope . methodInfo . responseCodes [ 0 ] ;
201+ if ( $scope . fullResponseCodes && $scope . fullResponseCodes . length > 0 ) {
202+ $scope . currentStatusCode = $scope . fullResponseCodes [ 0 ] ;
166203 }
167204 } ) ;
168205
314351 $elements . removeClass ( 'raml-console-is-active' ) ;
315352 $container . find ( '.raml-console-body-' + $scope . getBodyId ( value ) ) . addClass ( 'raml-console-is-active' ) ;
316353 } ) ;
317- } ]
354+ } ] ,
355+ replace : true
318356 } ;
319357 } ;
320358
373411 return [ {
374412 name : 'Example' ,
375413 content : ( typeof exampleContainer . example === 'object' ) ?
376- JSON . stringify ( exampleContainer . example ) : exampleContainer . example
414+ JSON . stringify ( exampleContainer . example , null , 2 ) : exampleContainer . example
377415 } ] ;
378416 } else if ( exampleContainer . examples ) {
379417 if ( Array . isArray ( exampleContainer . examples ) ) {
380418 return exampleContainer . examples . map ( function ( example , index ) {
381419 return {
382420 name : example . name || 'Example ' + index ,
383- content : JSON . stringify ( example . value , null , 2 )
421+ content : ( typeof example . value === 'object' ) ?
422+ JSON . stringify ( example . value , null , 2 ) : example . value
384423 } ;
385424 } ) ;
386425 } else {
30613100 return new RAML . Client . AuthStrategies . Oauth2 ( scheme , credentials ) ;
30623101 case 'OAuth 1.0' :
30633102 return new RAML . Client . AuthStrategies . Oauth1 ( scheme , credentials ) ;
3103+ case 'Pass Through' :
3104+ return RAML . Client . AuthStrategies . anonymous ( ) ;
30643105 case 'x-custom' :
30653106 return RAML . Client . AuthStrategies . anonymous ( ) ;
30663107 case 'Anonymous' :
@@ -6270,14 +6311,15 @@ RAML.Inspector = (function() {
62706311 * @return {Object }
62716312 */
62726313 return function ( value , key , object ) {
6273- // Short-circuit validation if the value is `null`.
6274- if ( value == null ) {
6275- return toValidationObject ( isOptional , 'required' , value , key ) ;
6276- }
62776314
62786315 // Switch validation type depending on if the value is an array or not.
62796316 var isArray = Array . isArray ( value ) ;
62806317
6318+ // Short-circuit validation if empty value
6319+ if ( value == null || ( isArray && value . length === 0 ) ) {
6320+ return toValidationObject ( isOptional , 'required' , value , key ) ;
6321+ }
6322+
62816323 // Select the validation stack to use based on the (repeated) value.
62826324 var values = isArray ? value : [ value ] ;
62836325 var validations = isArray ? repeatValidations : simpleValidations ;
@@ -6593,7 +6635,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
65936635 " </div>\n" +
65946636 "\n" +
65956637 " <!-- Response -->\n" +
6596- " <div ng-if=\"methodInfo.responseCodes \">\n" +
6638+ " <div ng-if=\"fullResponseCodes \">\n" +
65976639 " <header class=\"raml-console-resource-header\">\n" +
65986640 " <h3 class=\"raml-console-resource-head\">\n" +
65996641 " Response\n" +
@@ -6602,39 +6644,39 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
66026644 "\n" +
66036645 " <div class=\"raml-console-resource-response-jump\">\n" +
66046646 " <ul class=\"raml-console-resource-menu\">\n" +
6605- " <li class=\"raml-console-resource-btns raml-console-resource-menu-item\" ng-repeat=\"code in methodInfo.responseCodes \">\n" +
6647+ " <li class=\"raml-console-resource-btns raml-console-resource-menu-item\" ng-repeat=\"code in fullResponseCodes \">\n" +
66066648 " <button ng-click=\"showCodeDetails(code)\" class=\"raml-console-resource-btn raml-console-resource-menu-button raml-console-resource-menu-btn-{{getColorCode(code)}}\" ng-class=\"{ 'raml-console-button-is-active': isActiveCode(code) }\" href=\"#code{{code}}\">{{code}}</button>\n" +
66076649 " </li>\n" +
66086650 " </ul>\n" +
66096651 " </div>\n" +
66106652 "\n" +
66116653 " <div class=\"raml-console-resource-panel-primary-row raml-console-resource-panel-content raml-console-is-active raml-console-response-container\" ng-class=\"{'raml-console-is-active':showResponseDocumentation}\">\n" +
6612- " <section ng-if=\"isActiveCode(code)\" class=\"raml-console-resource-section raml-console-resource-response-section\" ng-repeat=\"code in methodInfo.responseCodes \">\n" +
6654+ " <section ng-if=\"isActiveCode(code)\" class=\"raml-console-resource-section raml-console-resource-response-section\" ng-repeat=\"code in fullResponseCodes \">\n" +
66136655 " <a name=\"code{{code}}\"></a>\n" +
66146656 " <h3 class=\"raml-console-resource-heading-a\">Status {{code}}</h3>\n" +
66156657 "\n" +
66166658 " <div class=\"raml-console-resource-response\">\n" +
6617- " <p markdown=\"methodInfo.responses [code].description\" class=\"raml-console-marked-content\"></p>\n" +
6659+ " <p markdown=\"fullResponses [code].description\" class=\"raml-console-marked-content\"></p>\n" +
66186660 " </div>\n" +
66196661 "\n" +
6620- " <div class=\"raml-console-resource-response\" ng-if=\"methodInfo.responses [code].headers\">\n" +
6662+ " <div class=\"raml-console-resource-response\" ng-if=\"fullResponses [code].headers\">\n" +
66216663 " <h4 class=\"raml-console-resource-body-heading\">Headers</h4>\n" +
6622- " <properties list=\"methodInfo.responses [code].headers\"></properties>\n" +
6664+ " <properties list=\"fullResponses [code].headers\"></properties>\n" +
66236665 " </div>\n" +
66246666 "\n" +
6625- " <div class=\"raml-console-resource-response\" ng-if=\"methodInfo.responses [code].body\">\n" +
6667+ " <div class=\"raml-console-resource-response\" ng-if=\"fullResponses [code].body\">\n" +
66266668 " <h4 class=\"raml-console-resource-body-heading\">\n" +
66276669 " Body\n" +
66286670 " <span\n" +
66296671 " ng-click=\"changeType($event, key, code)\"\n" +
66306672 " ng-class=\"{ 'raml-console-is-active': responseInfo[code].currentType === key}\"\n" +
66316673 " class=\"raml-console-flag\"\n" +
6632- " ng-repeat=\"(key, value) in methodInfo.responses [code].body\">\n" +
6674+ " ng-repeat=\"(key, value) in fullResponses [code].body\">\n" +
66336675 " {{key}}\n" +
66346676 " </span>\n" +
66356677 " </h4>\n" +
66366678 "\n" +
6637- " <div ng-repeat=\"(key, value) in methodInfo.responses [code].body\">\n" +
6679+ " <div ng-repeat=\"(key, value) in fullResponses [code].body\">\n" +
66386680 " <div ng-if=\"responseInfo[code].currentType === key\">\n" +
66396681 " <examples\n" +
66406682 " ng-if=\"responseInfo[code] && responseInfo[code].currentType\"\n" +
@@ -6698,7 +6740,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
66986740 " <div class=\"raml-console-sidebar-row\">\n" +
66996741 " <p class=\"raml-console-sidebar-input-container raml-console-sidebar-input-container-custom\" ng-repeat=\"customParam in context.customParameters[type]\">\n" +
67006742 " <button class=\"raml-console-sidebar-input-delete\" ng-click=\"removeCutomParam(customParam)\"></button>\n" +
6701- " <label for=\"custom-header\" class=\"raml-console-sidebar-label raml-console-sidebar-label-custom\">\n" +
6743+ " <label class=\"raml-console-sidebar-label raml-console-sidebar-label-custom\">\n" +
67026744 " <input class=\"raml-console-sidebar-custom-input-for-label\" ng-model=\"customParam.name\" placeholder=\"custom key\">\n" +
67036745 " </label>\n" +
67046746 " <input name=\"custom-header\" class=\"raml-console-sidebar-input raml-console-sidebar-input-custom\" placeholder=\"custom value\" ng-model=\"customParam.value\">\n" +
0 commit comments