@@ -31,10 +31,10 @@ function getSchemaImportPath(
3131 refName : string ,
3232 context : ContextSpec ,
3333) : string | undefined {
34- if ( context . output . factoryMethods . mode === 'inline-with-schema ' ) {
34+ if ( context . output . factoryMethods ? .mode === 'single ' ) {
3535 return undefined ;
3636 }
37- let outputDir = context . output . factoryMethods . outputDirectory ;
37+ let outputDir = context . output . factoryMethods ? .outputDirectory ;
3838 let schemasPath = getSchemasPath ( context ) ;
3939
4040 if ( context . output . workspace ) {
@@ -128,14 +128,15 @@ export function generateFactory(
128128 name : string ,
129129 context : ContextSpec ,
130130) : { model : string ; imports : GeneratorImport [ ] } | undefined {
131- if ( ! canGenerateSchema ( schema ) ) return undefined ;
131+ if ( ! canGenerateSchema ( schema ) || ! context . output . factoryMethods )
132+ return undefined ;
132133
133134 const { functionNamePrefix, mode } = context . output . factoryMethods ;
134135 const factoryName = `${ functionNamePrefix } ${ pascal ( name ) } ` ;
135136 const imports : GeneratorImport [ ] = [ ] ;
136137 const payload = buildPayload ( schema , context , [ name ] , imports ) ;
137138
138- if ( mode !== 'inline-with-schema ' ) {
139+ if ( mode !== 'single ' ) {
139140 const schemaImportPath = getSchemaImportPath ( name , context ) ;
140141 imports . push ( { name, importPath : schemaImportPath } ) ;
141142 }
@@ -287,10 +288,11 @@ function buildRefPayload(
287288 return `{} as ${ refName } ` ;
288289 }
289290
290- const { functionNamePrefix, mode } = context . output . factoryMethods ;
291+ const { functionNamePrefix = 'create' , mode = 'single' } =
292+ context . output . factoryMethods ?? { } ;
291293 const refFactoryName = `${ functionNamePrefix } ${ pascal ( refName ) } ` ;
292294
293- if ( mode !== 'combined-separate-file ' ) {
295+ if ( mode !== 'single-split ' ) {
294296 const importPath = resolveImportPath ( mode , refName , context ) ;
295297 imports . push ( { name : refFactoryName , importPath, isConstant : true } ) ;
296298 }
@@ -310,13 +312,13 @@ function resolveImportPath(
310312) : string | undefined {
311313 const baseName = conventionName ( refName , context . output . namingConvention ) ;
312314 switch ( mode ) {
313- case 'separate-file ' : {
315+ case 'split ' : {
314316 return `./${ baseName } .factory` ;
315317 }
316- case 'combined-separate-file ' : {
318+ case 'single-split ' : {
317319 return `./${ conventionName ( 'factoryMethods' , context . output . namingConvention ) } ` ;
318320 }
319- case 'inline-with-schema ' : {
321+ case 'single ' : {
320322 return `./${ baseName } ` ;
321323 }
322324 }
@@ -350,7 +352,8 @@ function buildObjectPayload(
350352 parents : string [ ] ,
351353 imports : GeneratorImport [ ] ,
352354) : string {
353- const { optionalPropertyStrategy } = context . output . factoryMethods ;
355+ const { includeOptionalProperty = false } =
356+ context . output . factoryMethods ?? { } ;
354357 const props = getProperties ( schema ) ;
355358 const requiredProps : string [ ] =
356359 ( schema . required as string [ ] | undefined ) ?? [ ] ;
@@ -360,7 +363,7 @@ function buildObjectPayload(
360363 entries . sort ( ( [ a ] , [ b ] ) => a . localeCompare ( b ) ) ;
361364 }
362365
363- const includeOptional = optionalPropertyStrategy === 'include' ;
366+ const includeOptional = includeOptionalProperty ;
364367 const lines : string [ ] = [ ] ;
365368
366369 for ( const [ key , prop ] of entries ) {
0 commit comments