@@ -453,38 +453,46 @@ function transformSchemaObjectCore(schemaObject: SchemaObject, options: Transfor
453
453
// properties
454
454
if ( Object . keys ( schemaObject . properties ?? { } ) . length ) {
455
455
for ( const [ k , v ] of getEntries ( schemaObject . properties ?? { } , options . ctx ) ) {
456
- if ( typeof v !== "object" || Array . isArray ( v ) ) {
456
+ if ( ( typeof v !== "object" && typeof v !== "boolean" ) || Array . isArray ( v ) ) {
457
457
throw new Error (
458
- `${ options . path } : invalid property ${ k } . Expected Schema Object, got ${
458
+ `${ options . path } : invalid property ${ k } . Expected Schema Object or boolean , got ${
459
459
Array . isArray ( v ) ? "Array" : typeof v
460
460
} `,
461
461
) ;
462
462
}
463
463
464
+ const { $ref, readOnly, hasDefault } =
465
+ typeof v === "object"
466
+ ? {
467
+ $ref : "$ref" in v && v . $ref ,
468
+ readOnly : "readOnly" in v && v . readOnly ,
469
+ hasDefault : "default" in v && v . default !== undefined ,
470
+ }
471
+ : { } ;
472
+
464
473
// handle excludeDeprecated option
465
474
if ( options . ctx . excludeDeprecated ) {
466
- const resolved = " $ref" in v ? options . ctx . resolve < SchemaObject > ( v . $ref ) : v ;
467
- if ( resolved ?. deprecated ) {
475
+ const resolved = $ref ? options . ctx . resolve < SchemaObject > ( $ref ) : v ;
476
+ if ( ( resolved as SchemaObject ) ?. deprecated ) {
468
477
continue ;
469
478
}
470
479
}
471
480
let optional =
472
481
schemaObject . required ?. includes ( k ) ||
473
482
( schemaObject . required === undefined && options . ctx . propertiesRequiredByDefault ) ||
474
- ( "default" in v &&
483
+ ( hasDefault &&
475
484
options . ctx . defaultNonNullable &&
476
485
! options . path ?. includes ( "parameters" ) &&
477
486
! options . path ?. includes ( "requestBody" ) &&
478
487
! options . path ?. includes ( "requestBodies" ) ) // can’t be required, even with defaults
479
488
? undefined
480
489
: QUESTION_TOKEN ;
481
- let type =
482
- "$ref" in v
483
- ? oapiRef ( v . $ref )
484
- : transformSchemaObject ( v , {
485
- ...options ,
486
- path : createRef ( [ options . path , k ] ) ,
487
- } ) ;
490
+ let type = $ref
491
+ ? oapiRef ( $ref )
492
+ : transformSchemaObject ( v , {
493
+ ...options ,
494
+ path : createRef ( [ options . path , k ] ) ,
495
+ } ) ;
488
496
489
497
if ( typeof options . ctx . transform === "function" ) {
490
498
const result = options . ctx . transform ( v as SchemaObject , options ) ;
@@ -500,7 +508,7 @@ function transformSchemaObjectCore(schemaObject: SchemaObject, options: Transfor
500
508
501
509
const property = ts . factory . createPropertySignature (
502
510
/* modifiers */ tsModifiers ( {
503
- readonly : options . ctx . immutable || ( " readOnly" in v && ! ! v . readOnly ) ,
511
+ readonly : options . ctx . immutable || readOnly ,
504
512
} ) ,
505
513
/* name */ tsPropertyIndex ( k ) ,
506
514
/* questionToken */ optional ,
0 commit comments