11import  {  describe ,  it ,  expect  }  from  'bun:test' 
2- import  {  getPossiblePath  }  from  '../src/openapi' 
2+ import  {  Elysia ,  t  }  from  'elysia' 
3+ import  {  getPossiblePath ,  toOpenAPISchema  }  from  '../src/openapi' 
34
45describe ( 'OpenAPI utilities' ,  ( )  =>  { 
56	it ( 'getPossiblePath' ,  ( )  =>  { 
@@ -12,3 +13,54 @@ describe('OpenAPI utilities', () => {
1213		] ) 
1314	} ) 
1415} ) 
16+ 
17+ describe ( 'Convert Elysia routes to OpenAPI 3.0.3 paths schema' ,  ( )  =>  { 
18+ 	describe ( 'with path, header, query and cookie params' ,  ( )  =>  { 
19+ 		const  app  =  new  Elysia ( ) . get ( '/' ,  ( )  =>  'hi' ,  { 
20+ 			response : t . String ( {  description : 'sample description'  } ) , 
21+ 			headers : t . Object ( { 
22+ 				testheader : t . String ( ) 
23+ 			} ) , 
24+ 			params : t . Object ( { 
25+ 				testparam : t . String ( ) 
26+ 			} ) , 
27+ 			query : t . Object ( { 
28+ 				testquery : t . String ( ) 
29+ 			} ) , 
30+ 			cookie : t . Cookie ( { 
31+ 				testcookie : t . String ( ) 
32+ 			} ) 
33+ 		} ) 
34+ 
35+ 		const  { 
36+ 			paths : {  [ '/' ] : path  } 
37+ 		}  =  toOpenAPISchema ( app ) 
38+ 
39+ 		const  parameters  =  path ?. get ?. parameters  ??  [ ] 
40+ 
41+ 		it ( 'includes all expected parameters' ,  ( )  =>  { 
42+ 			const  names  =  parameters . map ( ( p : any )  =>  p . name ) 
43+ 			expect ( names ) . toEqual ( 
44+ 				expect . arrayContaining ( [ 
45+ 					'testheader' , 
46+ 					'testparam' , 
47+ 					'testquery' , 
48+ 					'testcookie' 
49+ 				] ) 
50+ 			) 
51+ 			expect ( names ) . toHaveLength ( 4 ) 
52+ 		} ) 
53+ 
54+ 		it ( 'marks each parameter with the correct OpenAPI parameter location' ,  ( )  =>  { 
55+ 			const  map  =  Object . fromEntries ( 
56+ 				parameters . map ( ( p : any )  =>  [ p . name ,  p . in ] ) 
57+ 			) 
58+ 			expect ( map ) . toMatchObject ( { 
59+ 				testheader : 'header' , 
60+ 				testparam : 'path' , 
61+ 				testquery : 'query' , 
62+ 				testcookie : 'cookie' 
63+ 			} ) 
64+ 		} ) 
65+ 	} ) 
66+ } ) 
0 commit comments