@@ -15,6 +15,7 @@ import type {
1515} from './types/JSONSchema'
1616import { Intersection , Types , getRootSchema , isBoolean , isPrimitive } from './types/JSONSchema'
1717import { generateName , log , maybeStripDefault } from './utils'
18+ import { generateType } from './generator'
1819
1920export type Processed = Map < NormalizedJSONSchema , Map < SchemaType , AST > >
2021
@@ -157,15 +158,42 @@ function parseNonLiteral(
157158 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
158159 type : 'BOOLEAN' ,
159160 }
160- case 'CUSTOM_TYPE' :
161+ case 'CUSTOM_TYPE' : {
162+ let customType : string
163+
164+ if ( schema . tsType ) {
165+ customType = schema . tsType
166+ } else if ( options . parserExtensions && schema . type && typeof schema . type === 'string' ) {
167+ const extension = options . parserExtensions [ schema . type ]
168+ if ( extension ) {
169+ // Create a compilation callback for nested schemas
170+ const compileSchema = ( nestedSchema : any ) : string => {
171+ // Clone the schema to avoid modifying the original
172+ const clonedSchema = { ...nestedSchema }
173+ if ( ! clonedSchema [ Types ] ) {
174+ applySchemaTyping ( clonedSchema , options )
175+ }
176+ const ast = parse ( clonedSchema , options , undefined , processed , usedNames )
177+ return generateType ( ast , options )
178+ }
179+
180+ customType = extension ( schema , compileSchema )
181+ } else {
182+ customType = 'any'
183+ }
184+ } else {
185+ customType = 'any'
186+ }
187+
161188 return {
162189 comment : schema . description ,
163190 deprecated : schema . deprecated ,
164191 keyName,
165- params : schema . tsType ! ,
192+ params : customType ,
166193 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
167194 type : 'CUSTOM_TYPE' ,
168195 }
196+ }
169197 case 'NAMED_ENUM' :
170198 return {
171199 comment : schema . description ,
@@ -271,7 +299,7 @@ function parseNonLiteral(
271299 params : ( schema . type as JSONSchema4TypeName [ ] ) . map ( type => {
272300 const member : LinkedJSONSchema = { ...omit ( schema , '$id' , 'description' , 'title' ) , type}
273301 maybeStripDefault ( member )
274- applySchemaTyping ( member )
302+ applySchemaTyping ( member , options )
275303 return parse ( member , options , undefined , processed , usedNames )
276304 } ) ,
277305 type : 'UNION' ,
0 commit comments