@@ -494,6 +494,77 @@ describe('Operation Object', () => {
494494 } ) ;
495495 } ) ;
496496
497+ describe ( '#servers' , ( ) => {
498+ it ( 'warns when servers is not an array' , ( ) => {
499+ const operation = new namespace . elements . Member ( 'get' , {
500+ servers : { } ,
501+ responses : { } ,
502+ } ) ;
503+
504+ const parseResult = parse ( context , path , operation ) ;
505+
506+ expect ( parseResult . length ) . to . equal ( 2 ) ;
507+ expect ( parseResult . get ( 0 ) ) . to . be . instanceof ( namespace . elements . Transition ) ;
508+
509+ expect ( parseResult ) . to . contain . warning ( "'Operation Object' 'servers' is not an array" ) ;
510+ } ) ;
511+
512+ it ( 'exposes servers as an array in the transition' , ( ) => {
513+ const operation = new namespace . elements . Member ( 'get' , {
514+ servers : [
515+ {
516+ url : 'https://{username}.server.com/1.0' ,
517+ variables : {
518+ username : {
519+ default : 'Mario' ,
520+ enum : [ 'Tony' , 'Nina' ] ,
521+ } ,
522+ } ,
523+ } ,
524+ {
525+ url : 'https://user.server.com/2.0' ,
526+ description : 'The production API server' ,
527+ } ,
528+ ] ,
529+ responses : { } ,
530+ } ) ;
531+
532+ const parseResult = parse ( context , path , operation ) ;
533+
534+ expect ( parseResult . length ) . to . equal ( 1 ) ;
535+ expect ( parseResult . get ( 0 ) ) . to . be . instanceof ( namespace . elements . Transition ) ;
536+
537+ const hostsCategory = parseResult . get ( 0 ) . hosts ;
538+ expect ( hostsCategory ) . to . be . instanceof ( namespace . elements . Category ) ;
539+ expect ( hostsCategory . classes . toValue ( ) ) . to . deep . equal ( [ 'hosts' ] ) ;
540+ expect ( hostsCategory . length ) . to . equal ( 2 ) ;
541+
542+ const firstHost = hostsCategory . get ( 0 ) ;
543+ expect ( firstHost ) . to . be . instanceof ( namespace . elements . Resource ) ;
544+ expect ( firstHost . href . toValue ( ) ) . to . equal ( 'https://{username}.server.com/1.0' ) ;
545+
546+ const { hrefVariables } = firstHost ;
547+ expect ( hrefVariables ) . to . be . instanceof ( namespace . elements . HrefVariables ) ;
548+ expect ( hrefVariables . length ) . to . equal ( 1 ) ;
549+
550+ const hrefVariable = hrefVariables . content . content [ 0 ] ;
551+ expect ( hrefVariable ) . to . be . instanceof ( namespace . elements . Member ) ;
552+ expect ( hrefVariable . key . toValue ( ) ) . to . equal ( 'username' ) ;
553+ expect ( hrefVariable . value . default ) . to . equal ( 'Mario' ) ;
554+
555+ const { enumerations } = hrefVariable . value ;
556+ expect ( enumerations ) . to . be . instanceof ( namespace . elements . Array ) ;
557+ expect ( enumerations . length ) . to . equal ( 2 ) ;
558+ expect ( enumerations . toValue ( ) ) . to . deep . equal ( [ 'Tony' , 'Nina' ] ) ;
559+
560+ const secondHost = hostsCategory . get ( 1 ) ;
561+ expect ( secondHost ) . to . be . instanceof ( namespace . elements . Resource ) ;
562+ expect ( secondHost . classes . toValue ( ) ) . to . deep . equal ( [ 'host' ] ) ;
563+ expect ( secondHost . description . toValue ( ) ) . to . equal ( 'The production API server' ) ;
564+ expect ( secondHost . href . toValue ( ) ) . to . equal ( 'https://user.server.com/2.0' ) ;
565+ } ) ;
566+ } ) ;
567+
497568 describe ( '#security' , ( ) => {
498569 it ( 'parses correctly when there is a security requirement' , ( ) => {
499570 const operation = new namespace . elements . Member ( 'get' , {
0 commit comments