File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -314,7 +314,12 @@ export function toOpenAPISchema(
314
314
315
315
if (
316
316
( excludeStaticFile && route . path . includes ( '.' ) ) ||
317
- excludePaths . includes ( route . path ) ||
317
+ excludePaths . some ( match => {
318
+ if ( typeof match === 'string' ) {
319
+ return match === route . path
320
+ }
321
+ return match . exec ( route . path ) ;
322
+ } ) ||
318
323
excludeMethods . includes ( method )
319
324
)
320
325
continue
Original file line number Diff line number Diff line change @@ -272,4 +272,27 @@ describe('Swagger', () => {
272
272
const response = await res . json ( )
273
273
expect ( Object . keys ( response . paths [ '/all' ] ) ) . toBeArrayOfSize ( 8 )
274
274
} )
275
+
276
+ // https://github.com/elysiajs/elysia-openapi/issues/275
277
+ it ( 'should exclude entry points excluded by `exclude.path` option' , async ( ) => {
278
+ const app = new Elysia ( )
279
+ . use (
280
+ openapi ( {
281
+ exclude : {
282
+ paths : [ / ^ \/ v 1 / , "/v2" ] ,
283
+ } ,
284
+ } )
285
+ )
286
+ . get ( "/" , ( ) => "index" )
287
+ . get ( "/v1" , ( ) => "v1" )
288
+ . get ( "/v1/foo" , ( ) => "v1" )
289
+ . get ( "/v2" , ( ) => "v2" ) ;
290
+
291
+ await app . modules
292
+
293
+ const res = await app . handle ( req ( '/openapi/json' ) )
294
+ expect ( res . status ) . toBe ( 200 )
295
+ const response = await res . json ( )
296
+ expect ( Object . keys ( response . paths ) ) . toStrictEqual ( [ "/" ] )
297
+ } )
275
298
} )
You can’t perform that action at this time.
0 commit comments