@@ -236,12 +236,14 @@ angular
236236
237237 function formatResult ( deferred , data , status , headers , config ) {
238238 var query = '' ;
239- if ( config . params ) {
239+ if ( config . params ) {
240240 var parts = [ ] ;
241- for ( var key in config . params ) {
241+ for ( var key in config . params ) {
242242 parts . push ( key + '=' + encodeURIComponent ( config . params [ key ] ) ) ;
243243 }
244- query = '?' + parts . join ( '&' ) ;
244+ if ( parts . length > 0 ) {
245+ query = '?' + parts . join ( '&' ) ;
246+ }
245247 }
246248 deferred . resolve ( {
247249 url : config . url + query ,
@@ -322,7 +324,6 @@ angular
322324 } ;
323325
324326 } ] ) ;
325-
326327/*
327328 * angular-swagger-ui
328329 * http://github.com/maales/angular-swagger-ui
@@ -373,18 +374,18 @@ angular
373374 */
374375 function getSampleObj ( swagger , schema ) {
375376 var sample ;
376- if ( schema . $ref ) {
377+ if ( schema . properties ) {
378+ sample = { } ;
379+ for ( var name in schema . properties ) {
380+ sample [ name ] = getSampleObj ( swagger , schema . properties [ name ] ) ;
381+ }
382+ } else if ( schema . $ref ) {
377383 // complex object
378384 var def = swagger . definitions && swagger . definitions [ getClassName ( schema ) ] ;
379385 if ( def ) {
380386 if ( ! objCache [ schema . $ref ] ) {
381387 // object not in cache
382- var obj = { } ;
383- for ( var name in def . properties ) {
384- obj [ name ] = getSampleObj ( swagger , def . properties [ name ] ) ;
385- }
386- // cache generated object
387- objCache [ schema . $ref ] = obj ;
388+ objCache [ schema . $ref ] = getSampleObj ( swagger , def ) ;
388389 }
389390 sample = objCache [ schema . $ref ] ;
390391 }
@@ -445,83 +446,97 @@ angular
445446 return json ;
446447 } ;
447448
449+ var countInLine = 0 ;
450+
448451 /**
449452 * generates object's model
450453 */
451- var generateModel = this . generateModel = function ( swagger , schema ) {
454+ var generateModel = this . generateModel = function ( swagger , schema , modelName ) {
452455 var model = '' ;
453456
454457 function isRequired ( item , name ) {
455458 return item . required && item . required . indexOf ( name ) !== - 1 ;
456459 }
457460
458- console . log ( schema . type )
459-
460- if ( schema . $ref ) {
461+ if ( schema . properties ) {
462+ modelName = modelName || ( 'Inline Model' + countInLine ++ ) ;
463+ var buffer = [ '<div><strong>' + modelName + ' {</strong>' ] ,
464+ submodels = [ ] ;
465+
466+ for ( var propertyName in schema . properties ) {
467+ var property = schema . properties [ propertyName ] ;
468+ buffer . push ( '<div class="pad"><strong>' , propertyName , '</strong> (<span class="type">' ) ;
469+ // build type
470+ if ( property . properties ) {
471+ var name = 'Inline Model' + countInLine ++ ;
472+ buffer . push ( name ) ;
473+ submodels . push ( generateModel ( swagger , property , name ) ) ;
474+ } else if ( property . $ref ) {
475+ buffer . push ( getClassName ( property ) ) ;
476+ submodels . push ( generateModel ( swagger , property ) ) ;
477+ } else if ( property . type === 'array' ) {
478+ buffer . push ( 'Array[' ) ;
479+ if ( property . items . properties ) {
480+ var name = 'Inline Model' + countInLine ++ ;
481+ buffer . push ( name ) ;
482+ submodels . push ( generateModel ( swagger , property , name ) ) ;
483+ } else if ( property . items . $ref ) {
484+ buffer . push ( getClassName ( property . items ) ) ;
485+ submodels . push ( generateModel ( swagger , property . items ) ) ;
486+ } else {
487+ buffer . push ( getType ( property . items ) ) ;
488+ }
489+ buffer . push ( ']' ) ;
490+ } else {
491+ buffer . push ( getType ( property ) ) ;
492+ }
493+ buffer . push ( '</span>' ) ;
494+ // is required ?
495+ if ( ! isRequired ( schema , propertyName ) ) {
496+ buffer . push ( ', ' , '<em>optional</em>' ) ;
497+ }
498+ buffer . push ( ')' ) ;
499+ // has description
500+ if ( property . description ) {
501+ buffer . push ( ': ' , property . description ) ;
502+ }
503+ // is enum
504+ if ( property . enum ) {
505+ buffer . push ( ' = ' , angular . toJson ( property . enum ) . replace ( / , / g, ' or ' ) ) ;
506+ }
507+ buffer . push ( ',</div>' ) ;
508+ }
509+ buffer . pop ( ) ;
510+ buffer . push ( '</div>' ) ;
511+ buffer . push ( '<strong>}</strong>' ) ;
512+ buffer . push ( submodels . join ( '' ) , '</div>' ) ;
513+ model = buffer . join ( '' ) ;
514+ } else if ( schema . $ref ) {
461515 var className = getClassName ( schema ) ,
462516 def = swagger . definitions && swagger . definitions [ className ] ;
463517
464518 if ( def ) {
465519 if ( ! modelCache [ schema . $ref ] ) {
466- // object not in cache
467- var strModel = [ '<div><strong>' + className + ' {</strong>' ] ,
468- buffer = [ ] ;
469-
470- for ( var name in def . properties ) {
471- var prop = def . properties [ name ] ,
472- propModel = [ '<div class="pad"><strong>' + name + '</strong> (<span class="type">' ] ;
473-
474- // build type
475- if ( prop . $ref ) {
476- propModel . push ( getClassName ( prop ) ) ;
477- buffer . push ( generateModel ( swagger , prop ) ) ;
478- } else if ( prop . type === 'array' ) {
479- propModel . push ( 'Array[' ) ;
480- if ( prop . items . $ref ) {
481- propModel . push ( getClassName ( prop . items ) ) ;
482- buffer . push ( generateModel ( swagger , prop . items ) ) ;
483- } else {
484- propModel . push ( getType ( prop . items ) ) ;
485- }
486- propModel . push ( ']' ) ;
487- } else {
488- propModel . push ( getType ( prop ) ) ;
489- }
490- propModel . push ( '</span>' ) ;
491- // is required ?
492- if ( ! isRequired ( def , name ) ) {
493- propModel . push ( ', ' , '<em>optional</em>' ) ;
494- }
495- propModel . push ( ')' ) ;
496- // has description
497- if ( prop . description ) {
498- propModel . push ( ': ' , prop . description ) ;
499- }
500- // is enum
501- if ( prop . enum ) {
502- propModel . push ( ' = ' , angular . toJson ( prop . enum ) . replace ( / , / g, ' or ' ) ) ;
503- }
504- propModel . push ( ',</div>' ) ;
505- strModel . push ( propModel . join ( '' ) ) ;
506- }
507- strModel . push ( '<strong>}</strong>' ) ;
508- strModel . push ( buffer . join ( '' ) , '</div>' ) ;
509520 // cache generated object
510- modelCache [ schema . $ref ] = strModel . join ( '' ) ;
521+ modelCache [ schema . $ref ] = generateModel ( swagger , def , className ) ;
511522 }
512523 model = modelCache [ schema . $ref ] ;
513524 }
514525 } else if ( schema . type === 'array' ) {
515- var parts = [ '<strong>Array [' ] ;
526+ var buffer = [ '<strong>Array [' ] ;
516527 var sub = '' ;
517- if ( schema . items . $ref ) {
518- parts . push ( getClassName ( schema . items ) ) ;
528+ if ( schema . items . properties ) {
529+ var name = 'Inline Model' + countInLine ++ ;
530+ buffer . push ( name ) ;
531+ sub = generateModel ( swagger , schema . items , name ) ;
532+ } else if ( schema . items . $ref ) {
533+ buffer . push ( getClassName ( schema . items ) ) ;
519534 sub = generateModel ( swagger , schema . items ) ;
520535 } else {
521536 parts . push ( getType ( schema . items ) ) ;
522537 }
523- parts . push ( ']</strong><br><br>' , sub ) ;
524- model = parts . join ( '' ) ;
538+ buffer . push ( ']</strong><br><br>' , sub ) ;
539+ model = buffer . join ( '' ) ;
525540 } else if ( schema . type === 'object' ) {
526541 model = '<strong>Inline Model {<br>}</strong>' ;
527542 }
0 commit comments