@@ -849,6 +849,54 @@ describe('generator', () => {
849849 ] ) ;
850850 } ) ;
851851
852+ test ( 'with defined security' , ( ) => {
853+ const appRouter = t . router ( {
854+ protectedEndpoint : t . procedure
855+ . meta ( {
856+ openapi : { method : 'POST' , path : '/secure/endpoint' , protect : [ 'a' , 'b' ] } ,
857+ } )
858+ . input ( z . object ( { name : z . string ( ) } ) )
859+ . output ( z . object ( { name : z . string ( ) } ) )
860+ . query ( ( { input } ) => ( { name : input . name } ) ) ,
861+ } ) ;
862+
863+ const openApiDocument = generateOpenApiDocument ( appRouter , {
864+ ...defaultDocOpts ,
865+ securitySchemes : {
866+ a : {
867+ type : 'apiKey' ,
868+ name : 'a' ,
869+ in : 'header' ,
870+ } ,
871+ b : {
872+ type : 'apiKey' ,
873+ name : 'b' ,
874+ in : 'header' ,
875+ } ,
876+ } ,
877+ } ) ;
878+
879+ expect ( openApiSchemaValidator . validate ( openApiDocument ) . errors ) . toEqual ( [ ] ) ;
880+ expect ( openApiDocument . paths [ '/secure/endpoint' ] ! . post ! . security ) . toEqual ( [
881+ { a : [ ] } ,
882+ { b : [ ] } ,
883+ ] ) ;
884+ } ) ;
885+
886+ test ( 'with missing securityScheme' , ( ) => {
887+ const appRouter = t . router ( {
888+ protectedEndpoint : t . procedure
889+ . meta ( { openapi : { method : 'POST' , path : '/secure/endpoint' , protect : [ 'a' , 'b' ] } } )
890+ . input ( z . object ( { name : z . string ( ) } ) )
891+ . output ( z . object ( { name : z . string ( ) } ) )
892+ . query ( ( { input } ) => ( { name : input . name } ) ) ,
893+ } ) ;
894+
895+ expect ( ( ) => {
896+ generateOpenApiDocument ( appRouter , defaultDocOpts ) ;
897+ } ) . toThrowError ( '[query.protectedEndpoint] - "a,b" must exists in "securitySchemes"' ) ;
898+ } ) ;
899+
852900 test ( 'with schema descriptions' , ( ) => {
853901 const appRouter = t . router ( {
854902 createUser : t . procedure
0 commit comments