@@ -69,7 +69,9 @@ const mapTypesResponse = (
69
69
70
70
const responses : Record < string , OpenAPIV3 . MediaTypeObject > = { }
71
71
72
- for ( const type of types )
72
+ for ( const type of types ) {
73
+ // console.log(schema)
74
+
73
75
responses [ type ] = {
74
76
schema :
75
77
typeof schema === 'string'
@@ -78,6 +80,7 @@ const mapTypesResponse = (
78
80
}
79
81
: { ...( schema as any ) }
80
82
}
83
+ }
81
84
82
85
return responses
83
86
}
@@ -101,6 +104,12 @@ export const generateOperationId = (method: string, paths: string) => {
101
104
return operationId
102
105
}
103
106
107
+ const cloneHook = < T > ( hook : T ) => {
108
+ if ( ! hook ) return
109
+
110
+ return { ...hook }
111
+ }
112
+
104
113
export const registerSchemaPath = ( {
105
114
schema,
106
115
path,
@@ -114,7 +123,7 @@ export const registerSchemaPath = ({
114
123
method : HTTPMethod
115
124
hook ?: LocalHook < any , any , any , any , any , any , any >
116
125
models : Record < string , TSchema >
117
- } ) => {
126
+ } ) => {
118
127
const contentType = hook ?. type ?? [
119
128
'application/json' ,
120
129
'multipart/form-data' ,
@@ -126,13 +135,13 @@ export const registerSchemaPath = ({
126
135
const contentTypes =
127
136
typeof contentType === 'string'
128
137
? [ contentType ]
129
- : contentType ?? [ 'application/json' ]
138
+ : ( contentType ?? [ 'application/json' ] )
130
139
131
- const bodySchema = hook ?. body
132
- const paramsSchema = hook ?. params
133
- const headerSchema = hook ?. headers
134
- const querySchema = hook ?. query
135
- let responseSchema = hook ?. response as unknown as OpenAPIV3 . ResponsesObject
140
+ const bodySchema = cloneHook ( hook ?. body )
141
+ const paramsSchema = cloneHook ( hook ?. params )
142
+ const headerSchema = cloneHook ( hook ?. headers )
143
+ const querySchema = cloneHook ( hook ?. query )
144
+ let responseSchema : OpenAPIV3 . ResponsesObject = cloneHook ( hook ?. response )
136
145
137
146
if ( typeof responseSchema === 'object' ) {
138
147
if ( Kind in responseSchema ) {
@@ -292,36 +301,36 @@ export const registerSchemaPath = ({
292
301
}
293
302
294
303
export const filterPaths = (
295
- paths : Record < string , any > ,
296
- docsPath : string ,
297
- {
298
- excludeStaticFile = true ,
299
- exclude = [ ]
300
- } : {
301
- excludeStaticFile : boolean
302
- exclude : ( string | RegExp ) [ ]
303
- }
304
+ paths : Record < string , any > ,
305
+ docsPath : string ,
306
+ {
307
+ excludeStaticFile = true ,
308
+ exclude = [ ]
309
+ } : {
310
+ excludeStaticFile : boolean
311
+ exclude : ( string | RegExp ) [ ]
312
+ }
304
313
) => {
305
314
const newPaths : Record < string , any > = { }
306
315
307
- // exclude docs path and OpenAPI json path
308
- const excludePaths = [ `/${ docsPath } ` , `/${ docsPath } /json` ] . map ( ( p ) =>
316
+ // exclude docs path and OpenAPI json path
317
+ const excludePaths = [ `/${ docsPath } ` , `/${ docsPath } /json` ] . map ( ( p ) =>
309
318
normalize ( p )
310
319
)
311
320
312
- for ( const [ key , value ] of Object . entries ( paths ) )
313
- if (
314
- ! exclude . some ( ( x ) => {
315
- if ( typeof x === 'string' ) return key === x
316
-
317
- return x . test ( key )
318
- } ) &&
319
- ! excludePaths . includes ( key ) &&
320
- ! key . includes ( '*' ) &&
321
- ( excludeStaticFile ? ! key . includes ( '.' ) : true )
322
- ) {
323
- Object . keys ( value ) . forEach ( ( method ) => {
324
- const schema = value [ method ]
321
+ for ( const [ key , value ] of Object . entries ( paths ) )
322
+ if (
323
+ ! exclude . some ( ( x ) => {
324
+ if ( typeof x === 'string' ) return key === x
325
+
326
+ return x . test ( key )
327
+ } ) &&
328
+ ! excludePaths . includes ( key ) &&
329
+ ! key . includes ( '*' ) &&
330
+ ( excludeStaticFile ? ! key . includes ( '.' ) : true )
331
+ ) {
332
+ Object . keys ( value ) . forEach ( ( method ) => {
333
+ const schema = value [ method ]
325
334
326
335
if ( key . includes ( '{' ) ) {
327
336
if ( ! schema . parameters ) schema . parameters = [ ]
0 commit comments