@@ -60,7 +60,8 @@ suite(name, function () {
6060 title : 'Test App' ,
6161 version : '1.0.0'
6262 } ,
63- paths : { }
63+ paths : { } ,
64+ tags : [ ]
6465 } )
6566 } )
6667
@@ -653,6 +654,189 @@ suite(name, function () {
653654 } )
654655 } )
655656
657+ test ( 'support tags' , ( done ) => {
658+ const app = express ( )
659+ const oapi = openapi ( )
660+
661+ const firstTag = oapi . path ( {
662+ tags : [
663+ 'first-tag'
664+ ] ,
665+ responses : {
666+ 204 : {
667+ description : 'Successful response' ,
668+ content : {
669+ 'application/json' : { }
670+ }
671+ }
672+ }
673+ } )
674+
675+ app . get ( '/endpoint' , firstTag , ( req , res ) => {
676+ res . status ( 204 ) . send ( )
677+ } )
678+
679+ const secondTag = oapi . path ( {
680+ tags : [
681+ 'second-tag' ,
682+ 'third-tag'
683+ ] ,
684+ responses : {
685+ 204 : {
686+ description : 'Successful response' ,
687+ content : {
688+ 'application/json' : { }
689+ }
690+ }
691+ }
692+ } )
693+
694+ app . get ( '/another-endpoint' , secondTag , ( req , res ) => {
695+ res . status ( 204 ) . send ( )
696+ } )
697+
698+ app . use ( oapi )
699+
700+ supertest ( app )
701+ . get ( `${ openapi . defaultRoutePrefix } .json` )
702+ . expect ( 200 , ( err , res ) => {
703+ assert ( ! err , err )
704+ SwaggerParser . validate ( res . body , ( err , api ) => {
705+ if ( err ) {
706+ logDocument ( api )
707+
708+ done ( err )
709+ }
710+
711+ assert ( Object . keys ( api . paths ) . length === 2 )
712+
713+ assert . deepStrictEqual ( api . tags , [ {
714+ name : 'first-tag'
715+ } , {
716+ name : 'second-tag'
717+ } , {
718+ name : 'third-tag'
719+ } ] )
720+
721+ done ( )
722+ } )
723+ } )
724+ } )
725+
726+ test ( 'support tags with base document' , ( done ) => {
727+ const app = express ( )
728+ const oapi = openapi ( {
729+ tags : [
730+ {
731+ name : 'first-tag'
732+ }
733+ ]
734+ } )
735+
736+ const secondTag = oapi . path ( {
737+ tags : [
738+ 'second-tag' ,
739+ 'third-tag'
740+ ] ,
741+ responses : {
742+ 204 : {
743+ description : 'Successful response' ,
744+ content : {
745+ 'application/json' : { }
746+ }
747+ }
748+ }
749+ } )
750+
751+ app . get ( '/another-endpoint' , secondTag , ( req , res ) => {
752+ res . status ( 204 ) . send ( )
753+ } )
754+
755+ app . use ( oapi )
756+
757+ supertest ( app )
758+ . get ( `${ openapi . defaultRoutePrefix } .json` )
759+ . expect ( 200 , ( err , res ) => {
760+ assert ( ! err , err )
761+ SwaggerParser . validate ( res . body , ( err , api ) => {
762+ if ( err ) {
763+ logDocument ( api )
764+
765+ done ( err )
766+ }
767+
768+ assert ( Object . keys ( api . paths ) . length === 1 )
769+
770+ assert . deepStrictEqual ( api . tags , [ {
771+ name : 'first-tag'
772+ } , {
773+ name : 'second-tag'
774+ } , {
775+ name : 'third-tag'
776+ } ] )
777+
778+ done ( )
779+ } )
780+ } )
781+ } )
782+
783+ test ( 'prefer global tags over method tags' , ( done ) => {
784+ const app = express ( )
785+ const oapi = openapi ( {
786+ tags : [
787+ {
788+ name : 'first-tag' ,
789+ description : 'Description of first tag'
790+ }
791+ ]
792+ } )
793+
794+ const firstTag = oapi . path ( {
795+ tags : [
796+ 'first-tag' ,
797+ 'second-tag'
798+ ] ,
799+ responses : {
800+ 204 : {
801+ description : 'Successful response' ,
802+ content : {
803+ 'application/json' : { }
804+ }
805+ }
806+ }
807+ } )
808+
809+ app . get ( '/endpoint' , firstTag , ( req , res ) => {
810+ res . status ( 204 ) . send ( )
811+ } )
812+
813+ app . use ( oapi )
814+
815+ supertest ( app )
816+ . get ( `${ openapi . defaultRoutePrefix } .json` )
817+ . expect ( 200 , ( err , res ) => {
818+ assert ( ! err , err )
819+ SwaggerParser . validate ( res . body , ( err , api ) => {
820+ if ( err ) {
821+ logDocument ( api )
822+
823+ done ( err )
824+ }
825+
826+ assert ( Object . keys ( api . paths ) . length === 1 )
827+
828+ assert . deepStrictEqual ( api . tags , [ {
829+ name : 'first-tag' ,
830+ description : 'Description of first tag'
831+ } , {
832+ name : 'second-tag'
833+ } ] )
834+
835+ done ( )
836+ } )
837+ } )
838+ } )
839+
656840 // Other tests
657841 require ( './_validate' ) ( )
658842 require ( './_regexRoutes' ) ( )
0 commit comments