125125 templateUrl : 'directives/documentation.tpl.html' ,
126126 replace : true ,
127127 controller : function ( $scope ) {
128+ var defaultSchemaKey = Object . keys ( $scope . securitySchemes ) . sort ( ) [ 0 ] ;
129+ var defaultSchema = $scope . securitySchemes [ defaultSchemaKey ] ;
130+
128131 $scope . markedOptions = RAML . Settings . marked ;
132+ $scope . documentationSchemeSelected = defaultSchema ;
133+
134+ $scope . isSchemeSelected = function isSchemeSelected ( scheme ) {
135+ return scheme . id === $scope . documentationSchemeSelected . id ;
136+ } ;
137+
138+ $scope . selectDocumentationScheme = function selectDocumentationScheme ( scheme ) {
139+ $scope . documentationSchemeSelected = scheme ;
140+ } ;
141+
142+ $scope . schemaSettingsDocumentation = function schemaSettingsDocumentation ( settings ) {
143+ var doc = settings ;
144+
145+ if ( typeof settings === 'object' ) {
146+ doc = settings . join ( ', ' ) ;
147+ }
148+
149+ return doc ;
150+ }
129151
130152 $scope . unique = function ( arr ) {
131153 return arr . filter ( function ( v , i , a ) { return a . indexOf ( v ) === i ; } ) ;
185207 $scope . parameterDocumentation = function ( parameter ) {
186208 var result = '' ;
187209
188- if ( parameter . required ) {
189- result += 'required, ' ;
190- }
210+ if ( parameter ) {
211+ if ( parameter . required ) {
212+ result += 'required, ' ;
213+ }
191214
192- if ( parameter . enum ) {
193- var enumValues = $scope . unique ( parameter . enum ) ;
215+ if ( parameter . enum ) {
216+ var enumValues = $scope . unique ( parameter . enum ) ;
194217
195- if ( enumValues . length > 1 ) {
196- result += 'one of ' ;
197- }
218+ if ( enumValues . length > 1 ) {
219+ result += 'one of ' ;
220+ }
198221
199- result += '(' + enumValues . join ( ', ' ) + ')' ;
222+ result += '(' + enumValues . join ( ', ' ) + ')' ;
200223
201- } else {
202- result += parameter . type ;
203- }
224+ } else {
225+ result += parameter . type || '' ;
226+ }
204227
205- if ( parameter . pattern ) {
206- result += ' matching ' + parameter . pattern ;
207- }
228+ if ( parameter . pattern ) {
229+ result += ' matching ' + parameter . pattern ;
230+ }
208231
209- if ( parameter . minLength && parameter . maxLength ) {
210- result += ', ' + parameter . minLength + '-' + parameter . maxLength + ' characters' ;
211- } else if ( parameter . minLength && ! parameter . maxLength ) {
212- result += ', at least ' + parameter . minLength + ' characters' ;
213- } else if ( parameter . maxLength && ! parameter . minLength ) {
214- result += ', at most ' + parameter . maxLength + ' characters' ;
215- }
232+ if ( parameter . minLength && parameter . maxLength ) {
233+ result += ', ' + parameter . minLength + '-' + parameter . maxLength + ' characters' ;
234+ } else if ( parameter . minLength && ! parameter . maxLength ) {
235+ result += ', at least ' + parameter . minLength + ' characters' ;
236+ } else if ( parameter . maxLength && ! parameter . minLength ) {
237+ result += ', at most ' + parameter . maxLength + ' characters' ;
238+ }
216239
217240
218- if ( parameter . minimum && parameter . maximum ) {
219- result += ' between ' + parameter . minimum + '-' + parameter . maximum ;
220- } else if ( parameter . minimum && ! parameter . maximum ) {
221- result += ' ≥ ' + parameter . minimum ;
222- } else if ( parameter . maximum && ! parameter . minimum ) {
223- result += ' ≤ ' + parameter . maximum ;
224- }
241+ if ( parameter . minimum && parameter . maximum ) {
242+ result += ' between ' + parameter . minimum + '-' + parameter . maximum ;
243+ } else if ( parameter . minimum && ! parameter . maximum ) {
244+ result += ' ≥ ' + parameter . minimum ;
245+ } else if ( parameter . maximum && ! parameter . minimum ) {
246+ result += ' ≤ ' + parameter . maximum ;
247+ }
225248
226- if ( parameter . repeat ) {
227- result += ', repeatable' ;
228- }
249+ if ( parameter . repeat ) {
250+ result += ', repeatable' ;
251+ }
229252
230- if ( parameter [ 'default' ] ) {
231- result += ', default: ' + parameter [ 'default' ] ;
253+ if ( parameter [ 'default' ] ) {
254+ result += ', default: ' + parameter [ 'default' ] ;
255+ }
232256 }
233257
234258 return result ;
10901114 $scope . currentSchemeType = defaultSchema . type ;
10911115 $scope . currentScheme = defaultSchema . id ;
10921116 $scope . currentProtocol = $scope . raml . protocols [ 0 ] ;
1117+ $scope . documentationSchemeSelected = defaultSchema ;
10931118 } ) ;
10941119
10951120 $scope . cancelRequest = function ( ) {
12371262 cleanSchemeMetadata ( $scope . methodInfo . headers . plain , $scope . context . headers ) ;
12381263 cleanSchemeMetadata ( $scope . methodInfo . queryParameters , $scope . context . queryParameters ) ;
12391264
1265+ $scope . documentationSchemeSelected = $scope . securitySchemes [ name ] ;
1266+
12401267 if ( type === 'x-custom' ) {
12411268 if ( ! $scope . methodInfo . headers . plain ) {
12421269 $scope . methodInfo . headers . plain = { } ;
@@ -5061,7 +5088,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
50615088 " <section class=\"raml-console-resource-section\" id=\"docs-headers\" ng-if=\"methodInfo.headers.plain\">\n" +
50625089 " <h3 class=\"raml-console-resource-heading-a\">Headers</h3>\n" +
50635090 "\n" +
5064- " <div class=\"raml-console-resource-param\" ng-repeat=\"header in methodInfo.headers.plain\">\n" +
5091+ " <div class=\"raml-console-resource-param\" ng-repeat=\"header in methodInfo.headers.plain\" ng-if=\"!header[0].isFromSecurityScheme\" >\n" +
50655092 " <h4 class=\"raml-console-resource-param-heading\">{{header[0].displayName}}<span class=\"raml-console-resource-param-instructional\">{{parameterDocumentation(header[0])}}</span></h4>\n" +
50665093 "\n" +
50675094 " <p marked=\"header[0].description\" opts=\"markedOptions\"></p>\n" +
@@ -5075,7 +5102,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
50755102 " <section class=\"raml-console-resource-section\" id=\"docs-query-parameters\" ng-if=\"methodInfo.queryParameters\">\n" +
50765103 " <h3 class=\"raml-console-resource-heading-a\">Query Parameters</h3>\n" +
50775104 "\n" +
5078- " <div class=\"raml-console-resource-param\" ng-repeat=\"queryParam in methodInfo.queryParameters\">\n" +
5105+ " <div class=\"raml-console-resource-param\" ng-repeat=\"queryParam in methodInfo.queryParameters\" ng-if=\"!queryParam[0].isFromSecurityScheme\" >\n" +
50795106 " <h4 class=\"raml-console-resource-param-heading\">{{queryParam[0].displayName}}<span class=\"raml-console-resource-param-instructional\">{{parameterDocumentation(queryParam[0])}}</span></h4>\n" +
50805107 "\n" +
50815108 " <p marked=\"queryParam[0].description\" opts=\"markedOptions\"></p>\n" +
@@ -5086,6 +5113,62 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
50865113 " </div>\n" +
50875114 " </section>\n" +
50885115 "\n" +
5116+ " <section class=\"raml-console-resource-section raml-console-documentation-schemes\">\n" +
5117+ " <h3 class=\"raml-console-resource-heading-a\">Security Schemes</h3>\n" +
5118+ " <ol class=\"raml-console-documentation-security-scheme\">\n" +
5119+ " <li class=\"raml-console-documentation-scheme\" ng-class=\"{'raml-console-is-active':isSchemeSelected(value)}\" ng-click=\"selectDocumentationScheme(value)\" ng-repeat=\"(key, value) in securitySchemes\">{{value.name}}</li>\n" +
5120+ " </ol>\n" +
5121+ "\n" +
5122+ " <p ng-if\"documentationSchemeSelected.description\" marked=\"documentationSchemeSelected.description\" opts=\"markedOptions\"></p>\n" +
5123+ "\n" +
5124+ " <section class=\"raml-console-resource-section raml-console-scheme-headers\" ng-if=\"documentationSchemeSelected.describedBy.headers\">\n" +
5125+ " <h4 class=\"raml-console-resource-heading-a\">Headers</h4>\n" +
5126+ "\n" +
5127+ " <div class=\"raml-console-resource-param\" ng-repeat=\"(key, header) in documentationSchemeSelected.describedBy.headers\">\n" +
5128+ " <h4 class=\"raml-console-resource-param-heading\">{{key}}<span class=\"raml-console-resource-param-instructional\">{{parameterDocumentation(header)}}</span></h4>\n" +
5129+ "\n" +
5130+ " <p marked=\"header.description\" opts=\"markedOptions\"></p>\n" +
5131+ "\n" +
5132+ " <p ng-if=\"header.example\">\n" +
5133+ " <span class=\"raml-console-resource-param-example\"><b>Example:</b> {{header.example}}</span>\n" +
5134+ " </p>\n" +
5135+ " </div>\n" +
5136+ " </section>\n" +
5137+ "\n" +
5138+ " <section class=\"raml-console-resource-section raml-console-scheme-query-parameters\" ng-if=\"documentationSchemeSelected.describedBy.queryParameters\">\n" +
5139+ " <h4 class=\"raml-console-resource-heading-a\">Query Parameters</h4>\n" +
5140+ "\n" +
5141+ " <div class=\"raml-console-resource-param\" ng-repeat=\"(key, queryParameter) in documentationSchemeSelected.describedBy.queryParameters\">\n" +
5142+ " <h4 class=\"raml-console-resource-param-heading\">{{key}}<span class=\"raml-console-resource-param-instructional\">{{parameterDocumentation(queryParameter)}}</span></h4>\n" +
5143+ "\n" +
5144+ " <p marked=\"queryParameter.description\" opts=\"markedOptions\"></p>\n" +
5145+ "\n" +
5146+ " <p ng-if=\"queryParameter.example\">\n" +
5147+ " <span class=\"raml-console-resource-param-example\"><b>Example:</b> {{queryParameter.example}}</span>\n" +
5148+ " </p>\n" +
5149+ " </div>\n" +
5150+ " </section>\n" +
5151+ "\n" +
5152+ " <section class=\"raml-console-resource-section raml-console-scheme-responses\" ng-if=\"documentationSchemeSelected.describedBy.responses\">\n" +
5153+ " <h4 class=\"raml-console-resource-heading-a\">Responses</h4>\n" +
5154+ "\n" +
5155+ " <div class=\"raml-console-resource-param\" ng-repeat=\"(code, info) in documentationSchemeSelected.describedBy.responses\">\n" +
5156+ " <h4 class=\"raml-console-resource-param-heading\">{{code}}</h4>\n" +
5157+ " <p marked=\"info.description\" opts=\"markedOptions\"></p>\n" +
5158+ " </div>\n" +
5159+ " </section>\n" +
5160+ "\n" +
5161+ " <section class=\"raml-console-resource-section raml-console-scheme-settings\" ng-if=\"documentationSchemeSelected.settings\">\n" +
5162+ " <h4 class=\"raml-console-resource-heading-a\">Settings</h4>\n" +
5163+ "\n" +
5164+ " <div class=\"raml-console-resource-param\" ng-repeat=\"(key, config) in documentationSchemeSelected.settings\">\n" +
5165+ " <h4 class=\"raml-console-resource-param-heading\">{{key}}</h4>\n" +
5166+ " <p>{{schemaSettingsDocumentation(config)}}</p>\n" +
5167+ " </div>\n" +
5168+ " </section>\n" +
5169+ " </section>\n" +
5170+ "\n" +
5171+ "\n" +
50895172 " <section class=\"raml-console-resource-section\" ng-if=\"methodInfo.body\">\n" +
50905173 " <h3 class=\"raml-console-resource-heading-a\">\n" +
50915174 " Body\n" +
0 commit comments