@@ -548,7 +548,7 @@ describe('generator', () => {
548548 "get": Object {
549549 "description": undefined,
550550 "operationId": "readUsers",
551- "parameters": undefined ,
551+ "parameters": Array [] ,
552552 "responses": Object {
553553 "200": Object {
554554 "content": Object {
@@ -888,7 +888,7 @@ describe('generator', () => {
888888 expect ( Object . keys ( openApiDocument . paths ) . length ) . toBe ( 0 ) ;
889889 } ) ;
890890
891- test ( 'with summary, description & single tag ' , ( ) => {
891+ test ( 'with summary, description & multiple tags ' , ( ) => {
892892 const appRouter = trpc . router < any , OpenApiMeta > ( ) . query ( 'all.metadata' , {
893893 meta : {
894894 openapi : {
@@ -897,7 +897,7 @@ describe('generator', () => {
897897 method : 'GET' ,
898898 summary : 'Short summary' ,
899899 description : 'Verbose description' ,
900- tag : 'tag' ,
900+ tags : [ 'tagA' , 'tagB' ] ,
901901 } ,
902902 } ,
903903 input : z . object ( { name : z . string ( ) } ) ,
@@ -914,19 +914,18 @@ describe('generator', () => {
914914 expect ( openApiSchemaValidator . validate ( openApiDocument ) . errors ) . toEqual ( [ ] ) ;
915915 expect ( openApiDocument . paths [ '/metadata/all' ] ! . get ! . summary ) . toBe ( 'Short summary' ) ;
916916 expect ( openApiDocument . paths [ '/metadata/all' ] ! . get ! . description ) . toBe ( 'Verbose description' ) ;
917- expect ( openApiDocument . paths [ '/metadata/all' ] ! . get ! . tags ) . toEqual ( [ 'tag ' ] ) ;
917+ expect ( openApiDocument . paths [ '/metadata/all' ] ! . get ! . tags ) . toEqual ( [ 'tagA' , 'tagB '] ) ;
918918 } ) ;
919919
920- test ( 'with summary, description & multiple tags' , ( ) => {
920+ // @deprecated
921+ test ( 'with single tag' , ( ) => {
921922 const appRouter = trpc . router < any , OpenApiMeta > ( ) . query ( 'all.metadata' , {
922923 meta : {
923924 openapi : {
924925 enabled : true ,
925926 path : '/metadata/all' ,
926927 method : 'GET' ,
927- summary : 'Short summary' ,
928- description : 'Verbose description' ,
929- tags : [ 'tagA' , 'tagB' ] ,
928+ tag : 'tag' ,
930929 } ,
931930 } ,
932931 input : z . object ( { name : z . string ( ) } ) ,
@@ -941,9 +940,7 @@ describe('generator', () => {
941940 } ) ;
942941
943942 expect ( openApiSchemaValidator . validate ( openApiDocument ) . errors ) . toEqual ( [ ] ) ;
944- expect ( openApiDocument . paths [ '/metadata/all' ] ! . get ! . summary ) . toBe ( 'Short summary' ) ;
945- expect ( openApiDocument . paths [ '/metadata/all' ] ! . get ! . description ) . toBe ( 'Verbose description' ) ;
946- expect ( openApiDocument . paths [ '/metadata/all' ] ! . get ! . tags ) . toEqual ( [ 'tagA' , 'tagB' ] ) ;
943+ expect ( openApiDocument . paths [ '/metadata/all' ] ! . get ! . tags ) . toEqual ( [ 'tag' ] ) ;
947944 } ) ;
948945
949946 test ( 'with security' , ( ) => {
@@ -1185,7 +1182,7 @@ describe('generator', () => {
11851182 } ) ;
11861183
11871184 expect ( openApiSchemaValidator . validate ( openApiDocument ) . errors ) . toEqual ( [ ] ) ;
1188- expect ( openApiDocument . paths [ '/void' ] ! . get ! . parameters ) . toMatchInlineSnapshot ( `undefined` ) ;
1185+ expect ( openApiDocument . paths [ '/void' ] ! . get ! . parameters ) . toEqual ( [ ] ) ;
11891186 expect ( openApiDocument . paths [ '/void' ] ! . get ! . responses [ 200 ] ) . toMatchInlineSnapshot ( `
11901187 Object {
11911188 "content": Object {
@@ -2125,4 +2122,53 @@ describe('generator', () => {
21252122 }
21262123 ` ) ;
21272124 } ) ;
2125+
2126+ test ( 'with custom header' , ( ) => {
2127+ const appRouter = trpc . router < any , OpenApiMeta > ( ) . query ( 'echo' , {
2128+ meta : {
2129+ openapi : {
2130+ enabled : true ,
2131+ path : '/echo' ,
2132+ method : 'GET' ,
2133+ headers : [
2134+ {
2135+ name : 'x-custom-header' ,
2136+ required : true ,
2137+ description : 'Some custom header' ,
2138+ } ,
2139+ ] ,
2140+ } ,
2141+ } ,
2142+ input : z . object ( { id : z . string ( ) } ) ,
2143+ output : z . object ( { id : z . string ( ) } ) ,
2144+ resolve : ( { input } ) => ( { id : input . id } ) ,
2145+ } ) ;
2146+
2147+ const openApiDocument = generateOpenApiDocument ( appRouter , {
2148+ title : 'tRPC OpenAPI' ,
2149+ version : '1.0.0' ,
2150+ baseUrl : 'http://localhost:3000/api' ,
2151+ } ) ;
2152+
2153+ expect ( openApiSchemaValidator . validate ( openApiDocument ) . errors ) . toEqual ( [ ] ) ;
2154+ expect ( openApiDocument . paths [ '/echo' ] ! . get ! . parameters ) . toMatchInlineSnapshot ( `
2155+ Array [
2156+ Object {
2157+ "description": "Some custom header",
2158+ "in": "header",
2159+ "name": "x-custom-header",
2160+ "required": true,
2161+ },
2162+ Object {
2163+ "description": undefined,
2164+ "in": "query",
2165+ "name": "id",
2166+ "required": true,
2167+ "schema": Object {
2168+ "type": "string",
2169+ },
2170+ },
2171+ ]
2172+ ` ) ;
2173+ } ) ;
21282174} ) ;
0 commit comments