File tree Expand file tree Collapse file tree 4 files changed +23
-2
lines changed Expand file tree Collapse file tree 4 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -110,8 +110,10 @@ export const swagger = async <Path extends string = '/swagger'>(
110
110
111
111
if ( routes . length !== totalRoutes ) {
112
112
totalRoutes = routes . length
113
-
113
+
114
114
routes . forEach ( ( route : InternalRoute ) => {
115
+ if ( route . hooks ?. detail ?. hide === true ) return
116
+ // TODO: route.hooks?.detail?.hide !== false add ability to hide: false to prevent excluding
115
117
if ( excludeMethods . includes ( route . method ) ) return
116
118
117
119
registerSchemaPath ( {
Original file line number Diff line number Diff line change @@ -118,7 +118,7 @@ export const registerSchemaPath = ({
118
118
models : Record < string , TSchema >
119
119
} ) => {
120
120
if ( hook ) hook = deepClone ( hook )
121
-
121
+
122
122
const contentType = hook ?. type ?? [
123
123
'application/json' ,
124
124
'multipart/form-data' ,
Original file line number Diff line number Diff line change @@ -200,4 +200,23 @@ describe('Swagger', () => {
200
200
const response = await res . json ( )
201
201
expect ( response . paths ) . toContainKey ( '/id/{id}' )
202
202
} )
203
+
204
+ it ( 'should hide routes with hide = true from paths' , async ( ) => {
205
+ const app = new Elysia ( ) . use ( swagger ( ) )
206
+ . get ( "/public" , "omg" )
207
+ . guard ( {
208
+ detail : {
209
+ hide : true
210
+ }
211
+ } )
212
+ . get ( "/hidden" , "ok" )
213
+
214
+ await app . modules
215
+
216
+ const res = await app . handle ( req ( '/swagger/json' ) )
217
+ expect ( res . status ) . toBe ( 200 )
218
+ const response = await res . json ( )
219
+ expect ( response . paths [ '/public' ] ) . not . toBeUndefined ( ) ;
220
+ expect ( response . paths [ '/hidden' ] ) . toBeUndefined ( ) ;
221
+ } )
203
222
} )
You can’t perform that action at this time.
0 commit comments