@@ -68,20 +68,6 @@ describe('Path Item Object', () => {
6868 expect ( parseResult ) . to . contain . warning ( "'Path Item Object' contains unsupported key '$ref'" ) ;
6969 } ) ;
7070
71- it ( 'warns for a servers' , ( ) => {
72- const path = new namespace . elements . Member ( '/' , {
73- servers : '' ,
74- } ) ;
75-
76- const parseResult = parse ( context , path ) ;
77-
78- expect ( parseResult . length ) . to . equal ( 2 ) ;
79- expect ( parseResult . get ( 0 ) ) . to . be . instanceof ( namespace . elements . Resource ) ;
80- expect ( parseResult . get ( 0 ) . href . toValue ( ) ) . to . equal ( '/' ) ;
81-
82- expect ( parseResult ) . to . contain . warning ( "'Path Item Object' contains unsupported key 'servers'" ) ;
83- } ) ;
84-
8571 it ( 'does not provide warning for Info Object extensions' , ( ) => {
8672 const path = new namespace . elements . Member ( '/' , {
8773 'x-extension' : '' ,
@@ -419,4 +405,74 @@ describe('Path Item Object', () => {
419405 } ) ;
420406 } ) ;
421407 } ) ;
408+
409+ describe ( '#servers' , ( ) => {
410+ it ( 'warns when servers is not an array' , ( ) => {
411+ const path = new namespace . elements . Member ( '/' , {
412+ servers : { } ,
413+ } ) ;
414+
415+ const parseResult = parse ( context , path ) ;
416+
417+ expect ( parseResult . length ) . to . equal ( 2 ) ;
418+ expect ( parseResult . get ( 0 ) ) . to . be . instanceof ( namespace . elements . Resource ) ;
419+ expect ( parseResult . get ( 0 ) . href . toValue ( ) ) . to . equal ( '/' ) ;
420+
421+ expect ( parseResult ) . to . contain . warning ( "'Path Item Object' 'servers' is not an array" ) ;
422+ } ) ;
423+
424+ it ( 'exposes servers as an array in the resource' , ( ) => {
425+ const path = new namespace . elements . Member ( '/' , {
426+ servers : [
427+ {
428+ url : 'https://{username}.server.com/1.0' ,
429+ variables : {
430+ username : {
431+ default : 'Mario' ,
432+ enum : [ 'Tony' , 'Nina' ] ,
433+ } ,
434+ } ,
435+ } ,
436+ {
437+ url : 'https://user.server.com/2.0' ,
438+ description : 'The production API server' ,
439+ } ,
440+ ] ,
441+ } ) ;
442+
443+ const parseResult = parse ( context , path ) ;
444+
445+ expect ( parseResult . length ) . to . equal ( 1 ) ;
446+ expect ( parseResult . get ( 0 ) ) . to . be . instanceof ( namespace . elements . Resource ) ;
447+
448+ const hostsCategory = parseResult . get ( 0 ) . get ( 0 ) ;
449+ expect ( hostsCategory ) . to . be . instanceof ( namespace . elements . Category ) ;
450+ expect ( hostsCategory . classes . toValue ( ) ) . to . deep . equal ( [ 'hosts' ] ) ;
451+ expect ( hostsCategory . length ) . to . equal ( 2 ) ;
452+
453+ const firstHost = hostsCategory . get ( 0 ) ;
454+ expect ( firstHost ) . to . be . instanceof ( namespace . elements . Resource ) ;
455+ expect ( firstHost . href . toValue ( ) ) . to . equal ( 'https://{username}.server.com/1.0' ) ;
456+
457+ const { hrefVariables } = firstHost ;
458+ expect ( hrefVariables ) . to . be . instanceof ( namespace . elements . HrefVariables ) ;
459+ expect ( hrefVariables . length ) . to . equal ( 1 ) ;
460+
461+ const hrefVariable = hrefVariables . content . content [ 0 ] ;
462+ expect ( hrefVariable ) . to . be . instanceof ( namespace . elements . Member ) ;
463+ expect ( hrefVariable . key . toValue ( ) ) . to . equal ( 'username' ) ;
464+ expect ( hrefVariable . value . default ) . to . equal ( 'Mario' ) ;
465+
466+ const { enumerations } = hrefVariable . value ;
467+ expect ( enumerations ) . to . be . instanceof ( namespace . elements . Array ) ;
468+ expect ( enumerations . length ) . to . equal ( 2 ) ;
469+ expect ( enumerations . toValue ( ) ) . to . deep . equal ( [ 'Tony' , 'Nina' ] ) ;
470+
471+ const secondHost = hostsCategory . get ( 1 ) ;
472+ expect ( secondHost ) . to . be . instanceof ( namespace . elements . Resource ) ;
473+ expect ( secondHost . classes . toValue ( ) ) . to . deep . equal ( [ 'host' ] ) ;
474+ expect ( secondHost . description . toValue ( ) ) . to . equal ( 'The production API server' ) ;
475+ expect ( secondHost . href . toValue ( ) ) . to . equal ( 'https://user.server.com/2.0' ) ;
476+ } ) ;
477+ } ) ;
422478} ) ;
0 commit comments