@@ -17,7 +17,7 @@ import { AdditionalReference, AdditionalReferences } from '../types'
1717import { Kind , TObject } from '@sinclair/typebox/type'
1818
1919const matchRoute = / : E l y s i a < ( .* ) > / gs
20- const matchStatus = / ( \d { 3 } ) : / gs
20+ const matchStatus = / ( \d { 3 } ) : / g
2121const wrapStatusInQuote = ( value : string ) => value . replace ( matchStatus , '"$1":' )
2222
2323const exec = ( command : string , cwd : string ) =>
@@ -156,13 +156,19 @@ export const fromTypes =
156156 // 1 2 3 4 5
157157 // We want the 4th one
158158 for ( let i = 0 ; i < 3 ; i ++ )
159- instance = instance . slice ( instance . indexOf ( '}, {' , 3 ) )
159+ instance = instance . slice (
160+ instance . indexOf (
161+ '}, {' ,
162+ // remove just ` }, `, leaving `{`
163+ 3
164+ )
165+ )
160166
161- const routesString =
162- wrapStatusInQuote ( instance ) . slice (
163- 3 ,
164- instance . indexOf ( '}, {' , 3 )
165- ) + '}\n}\n'
167+ const routesString = wrapStatusInQuote (
168+ // Intentionally not adding " }"
169+ // to avoid mismatched bracket in loop below
170+ instance . slice ( 3 , instance . indexOf ( '}, {' , 4 ) )
171+ )
166172
167173 const routes : AdditionalReference = { }
168174
@@ -171,13 +177,8 @@ export const fromTypes =
171177 // instead of being nested in a route object
172178 for ( const route of routesString . slice ( 1 ) . split ( '} & {' ) ) {
173179 // as ' } & {' is removed, we need to add it back
174- let schema = TypeBox ( `{${ route } }}` )
175- if ( schema . type !== 'object' ) {
176- // just in case
177- schema = TypeBox ( `{${ route } }` )
178-
179- if ( schema . type !== 'object' ) continue
180- }
180+ let schema = TypeBox ( `{${ route } }` )
181+ if ( schema . type !== 'object' ) continue
181182
182183 const paths = [ ]
183184
0 commit comments