@@ -69,7 +69,9 @@ const mapTypesResponse = (
6969
7070 const responses : Record < string , OpenAPIV3 . MediaTypeObject > = { }
7171
72- for ( const type of types )
72+ for ( const type of types ) {
73+ // console.log(schema)
74+
7375 responses [ type ] = {
7476 schema :
7577 typeof schema === 'string'
@@ -78,6 +80,7 @@ const mapTypesResponse = (
7880 }
7981 : { ...( schema as any ) }
8082 }
83+ }
8184
8285 return responses
8386}
@@ -101,6 +104,12 @@ export const generateOperationId = (method: string, paths: string) => {
101104 return operationId
102105}
103106
107+ const cloneHook = < T > ( hook : T ) => {
108+ if ( ! hook ) return
109+
110+ return { ...hook }
111+ }
112+
104113export const registerSchemaPath = ( {
105114 schema,
106115 path,
@@ -114,7 +123,7 @@ export const registerSchemaPath = ({
114123 method : HTTPMethod
115124 hook ?: LocalHook < any , any , any , any , any , any , any >
116125 models : Record < string , TSchema >
117- } ) => {
126+ } ) => {
118127 const contentType = hook ?. type ?? [
119128 'application/json' ,
120129 'multipart/form-data' ,
@@ -126,13 +135,13 @@ export const registerSchemaPath = ({
126135 const contentTypes =
127136 typeof contentType === 'string'
128137 ? [ contentType ]
129- : contentType ?? [ 'application/json' ]
138+ : ( contentType ?? [ 'application/json' ] )
130139
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 )
136145
137146 if ( typeof responseSchema === 'object' ) {
138147 if ( Kind in responseSchema ) {
@@ -292,36 +301,36 @@ export const registerSchemaPath = ({
292301}
293302
294303export 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+ }
304313) => {
305314 const newPaths : Record < string , any > = { }
306315
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 ) =>
309318 normalize ( p )
310319 )
311320
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 ]
325334
326335 if ( key . includes ( '{' ) ) {
327336 if ( ! schema . parameters ) schema . parameters = [ ]
0 commit comments