@@ -27,25 +27,25 @@ describe('Filter', () => {
2727 responses : responses ?? { '200' : { description : 'OK' } }
2828 } as any ) ;
2929
30- describe ( 'path filtering' , ( ) => {
31- it ( 'should include all operations when targetGroups is null ' , ( ) => {
30+ describe ( 'operation group filtering' , ( ) => {
31+ it ( 'should include operations matching target groups ' , ( ) => {
3232 const spec = createSpec ( {
3333 '/pets' : {
3434 get : createOperation ( 'pets.list' , 'listPets' ) ,
3535 post : createOperation ( 'pets.create' , 'createPet' )
3636 }
3737 } ) ;
3838
39- const pathsMap = new Map < string , Set < string > | null > ( [ [ '/ pets' , null ] ] ) ;
40- const filter = new Filter ( spec , pathsMap ) ;
39+ const targetGroups = new Set ( [ ' pets.list' ] ) ;
40+ const filter = new Filter ( spec , targetGroups ) ;
4141 const result = filter . filter ( ) ;
4242
4343 expect ( result . paths [ '/pets' ] ) . toBeDefined ( ) ;
4444 expect ( ( result . paths [ '/pets' ] as any ) . get ) . toBeDefined ( ) ;
45- expect ( ( result . paths [ '/pets' ] as any ) . post ) . toBeDefined ( ) ;
45+ expect ( ( result . paths [ '/pets' ] as any ) . post ) . toBeUndefined ( ) ;
4646 } ) ;
4747
48- it ( 'should filter operations by x- operation-group ' , ( ) => {
48+ it ( 'should include multiple operation groups ' , ( ) => {
4949 const spec = createSpec ( {
5050 '/pets' : {
5151 get : createOperation ( 'pets.list' , 'listPets' ) ,
@@ -54,45 +54,44 @@ describe('Filter', () => {
5454 }
5555 } ) ;
5656
57- const pathsMap = new Map < string , Set < string > | null > ( [
58- [ '/pets' , new Set ( [ 'pets.list' , 'pets.create' ] ) ]
59- ] ) ;
60- const filter = new Filter ( spec , pathsMap ) ;
57+ const targetGroups = new Set ( [ 'pets.list' , 'pets.create' ] ) ;
58+ const filter = new Filter ( spec , targetGroups ) ;
6159 const result = filter . filter ( ) ;
6260
6361 expect ( ( result . paths [ '/pets' ] as any ) . get ) . toBeDefined ( ) ;
6462 expect ( ( result . paths [ '/pets' ] as any ) . post ) . toBeDefined ( ) ;
6563 expect ( ( result . paths [ '/pets' ] as any ) . delete ) . toBeUndefined ( ) ;
6664 } ) ;
6765
68- it ( 'should skip paths not in targetPathsMap ' , ( ) => {
66+ it ( 'should discover paths automatically based on operation group ' , ( ) => {
6967 const spec = createSpec ( {
7068 '/pets' : { get : createOperation ( 'pets.list' , 'listPets' ) } ,
69+ '/pets/{id}' : { get : createOperation ( 'pets.list' , 'getPet' ) } ,
7170 '/users' : { get : createOperation ( 'users.list' , 'listUsers' ) }
7271 } ) ;
7372
74- const pathsMap = new Map < string , Set < string > | null > ( [ [ '/ pets' , null ] ] ) ;
75- const filter = new Filter ( spec , pathsMap ) ;
73+ const targetGroups = new Set ( [ ' pets.list' ] ) ;
74+ const filter = new Filter ( spec , targetGroups ) ;
7675 const result = filter . filter ( ) ;
7776
78- expect ( result . paths [ '/pets' ] ) . toBeDefined ( ) ;
77+ // Should discover both /pets and /pets/{id} since both have pets.list group
78+ // But they get merged, so only one remains
79+ expect ( Object . keys ( result . paths ) . length ) . toBe ( 1 ) ;
7980 expect ( result . paths [ '/users' ] ) . toBeUndefined ( ) ;
8081 } ) ;
8182
82- it ( 'should handle path not found in spec gracefully ' , ( ) => {
83+ it ( 'should skip paths with no matching operation group ' , ( ) => {
8384 const spec = createSpec ( {
84- '/pets' : { get : createOperation ( 'pets.list' , 'listPets' ) }
85+ '/pets' : { get : createOperation ( 'pets.list' , 'listPets' ) } ,
86+ '/users' : { get : createOperation ( 'users.list' , 'listUsers' ) }
8587 } ) ;
8688
87- const pathsMap = new Map < string , Set < string > | null > ( [
88- [ '/pets' , null ] ,
89- [ '/nonexistent' , null ]
90- ] ) ;
91- const filter = new Filter ( spec , pathsMap ) ;
89+ const targetGroups = new Set ( [ 'pets.list' ] ) ;
90+ const filter = new Filter ( spec , targetGroups ) ;
9291 const result = filter . filter ( ) ;
9392
9493 expect ( result . paths [ '/pets' ] ) . toBeDefined ( ) ;
95- expect ( result . paths [ '/nonexistent ' ] ) . toBeUndefined ( ) ;
94+ expect ( result . paths [ '/users ' ] ) . toBeUndefined ( ) ;
9695 } ) ;
9796 } ) ;
9897
@@ -112,11 +111,8 @@ describe('Filter', () => {
112111 }
113112 } ) ;
114113
115- const pathsMap = new Map < string , Set < string > | null > ( [
116- [ '/pets' , null ] ,
117- [ '/pets/{petId}' , null ]
118- ] ) ;
119- const filter = new Filter ( spec , pathsMap ) ;
114+ const targetGroups = new Set ( [ 'pets.list' ] ) ;
115+ const filter = new Filter ( spec , targetGroups ) ;
120116 const result = filter . filter ( ) ;
121117
122118 // Should merge to first path with merged parameters
@@ -143,11 +139,8 @@ describe('Filter', () => {
143139 }
144140 } ) ;
145141
146- const pathsMap = new Map < string , Set < string > | null > ( [
147- [ '/pets' , null ] ,
148- [ '/pets/{id}' , null ]
149- ] ) ;
150- const filter = new Filter ( spec , pathsMap ) ;
142+ const targetGroups = new Set ( [ 'pets.list' ] ) ;
143+ const filter = new Filter ( spec , targetGroups ) ;
151144 const result = filter . filter ( ) ;
152145
153146 const operation = ( result . paths [ '/pets' ] as any ) ?. get ;
@@ -174,11 +167,8 @@ describe('Filter', () => {
174167 }
175168 } ) ;
176169
177- const pathsMap = new Map < string , Set < string > | null > ( [
178- [ '/pets' , null ] ,
179- [ '/pets/{id}' , null ]
180- ] ) ;
181- const filter = new Filter ( spec , pathsMap ) ;
170+ const targetGroups = new Set ( [ 'pets.list' ] ) ;
171+ const filter = new Filter ( spec , targetGroups ) ;
182172 const result = filter . filter ( ) ;
183173
184174 const operation = ( result . paths [ '/pets' ] as any ) ?. get ;
@@ -192,8 +182,8 @@ describe('Filter', () => {
192182 }
193183 } ) ;
194184
195- const pathsMap = new Map < string , Set < string > | null > ( [ [ '/ pets' , null ] ] ) ;
196- const filter = new Filter ( spec , pathsMap ) ;
185+ const targetGroups = new Set ( [ ' pets.list' ] ) ;
186+ const filter = new Filter ( spec , targetGroups ) ;
197187 const result = filter . filter ( ) ;
198188
199189 const operation = ( result . paths [ '/pets' ] as any ) ?. get ;
@@ -214,11 +204,8 @@ describe('Filter', () => {
214204 }
215205 } ) ;
216206
217- const pathsMap = new Map < string , Set < string > | null > ( [
218- [ '/pets' , null ] ,
219- [ '/pets/{id}' , null ]
220- ] ) ;
221- const filter = new Filter ( spec , pathsMap ) ;
207+ const targetGroups = new Set ( [ 'pets.create' ] ) ;
208+ const filter = new Filter ( spec , targetGroups ) ;
222209
223210 expect ( ( ) => filter . filter ( ) ) . toThrow ( / i n c o n s i s t e n t r e q u e s t B o d y / ) ;
224211 } ) ;
@@ -235,11 +222,8 @@ describe('Filter', () => {
235222 }
236223 } ) ;
237224
238- const pathsMap = new Map < string , Set < string > | null > ( [
239- [ '/pets' , null ] ,
240- [ '/pets/{id}' , null ]
241- ] ) ;
242- const filter = new Filter ( spec , pathsMap ) ;
225+ const targetGroups = new Set ( [ 'pets.list' ] ) ;
226+ const filter = new Filter ( spec , targetGroups ) ;
243227
244228 expect ( ( ) => filter . filter ( ) ) . toThrow ( / i n c o n s i s t e n t r e s p o n s e s / ) ;
245229 } ) ;
@@ -257,11 +241,8 @@ describe('Filter', () => {
257241 }
258242 } ) ;
259243
260- const pathsMap = new Map < string , Set < string > | null > ( [
261- [ '/pets' , null ] ,
262- [ '/pets/{id}' , null ]
263- ] ) ;
264- const filter = new Filter ( spec , pathsMap ) ;
244+ const targetGroups = new Set ( [ 'pets.create' ] ) ;
245+ const filter = new Filter ( spec , targetGroups ) ;
265246
266247 expect ( ( ) => filter . filter ( ) ) . not . toThrow ( ) ;
267248 } ) ;
@@ -276,11 +257,8 @@ describe('Filter', () => {
276257 }
277258 } ) ;
278259
279- const pathsMap = new Map < string , Set < string > | null > ( [
280- [ '/pets' , null ] ,
281- [ '/pets/{id}' , null ]
282- ] ) ;
283- const filter = new Filter ( spec , pathsMap ) ;
260+ const targetGroups = new Set ( [ 'pets.list' ] ) ;
261+ const filter = new Filter ( spec , targetGroups ) ;
284262
285263 expect ( ( ) => filter . filter ( ) ) . not . toThrow ( ) ;
286264 } ) ;
@@ -317,9 +295,9 @@ describe('Filter', () => {
317295 parameters : { }
318296 } ) ;
319297
320- const pathsMap = new Map < string , Set < string > | null > ( [ [ '/ pets' , null ] ] ) ;
298+ const targetGroups = new Set ( [ ' pets.list' ] ) ;
321299 const excludedSchemas = new Set ( [ 'ExcludedSchema' ] ) ;
322- const filter = new Filter ( spec , pathsMap , excludedSchemas ) ;
300+ const filter = new Filter ( spec , targetGroups , excludedSchemas ) ;
323301 const result = filter . filter ( ) ;
324302
325303 expect ( result . components ?. schemas ?. [ 'PetList' ] ) . toBeDefined ( ) ;
@@ -351,8 +329,8 @@ describe('Filter', () => {
351329 schemas : { }
352330 } ) ;
353331
354- const pathsMap = new Map < string , Set < string > | null > ( [ [ '/ pets' , null ] ] ) ;
355- const filter = new Filter ( spec , pathsMap ) ;
332+ const targetGroups = new Set ( [ ' pets.list' ] ) ;
333+ const filter = new Filter ( spec , targetGroups ) ;
356334 const result = filter . filter ( ) ;
357335
358336 expect ( result . components ?. parameters ?. [ 'limit' ] ) . toBeDefined ( ) ;
@@ -396,8 +374,8 @@ describe('Filter', () => {
396374 responses : { }
397375 } ) ;
398376
399- const pathsMap = new Map < string , Set < string > | null > ( [ [ '/ pets' , null ] ] ) ;
400- const filter = new Filter ( spec , pathsMap ) ;
377+ const targetGroups = new Set ( [ ' pets.list' ] ) ;
378+ const filter = new Filter ( spec , targetGroups ) ;
401379 const result = filter . filter ( ) ;
402380
403381 expect ( result . components ?. schemas ?. [ 'PetList' ] ) . toBeDefined ( ) ;
0 commit comments