@@ -43,10 +43,11 @@ export class SchemaModifier {
4343 this . handleAdditionalPropertiesUndefined ( schema )
4444
4545 } ,
46- onSchema : ( schema ) => {
46+ onSchema : ( schema , schemaName ) => {
4747 if ( ! schema || isReferenceObject ( schema ) ) return ;
4848 this . simplifySingleMapSchema ( schema , visit )
4949 this . handleAdditionalPropertiesUndefined ( schema )
50+ this . markOneOfExtensions ( schema , schemaName ) ;
5051 } ,
5152 } ) ;
5253 return this . root
@@ -479,7 +480,8 @@ export class SchemaModifier {
479480 /**
480481 * Marks schemas and properties with oneOf extensions.
481482 * Adds x-oneof to properties when schema has minProperties=1 and maxProperties=1.
482- * Adds x-oneof-constraint to top-level schemas that contain such patterns.
483+ * Adds x-oneof-constraint to schemas that have the min/max pattern AND to parent schemas
484+ * that contain nested schemas with the pattern.
483485 **/
484486 markOneOfExtensions ( schema : OpenAPIV3 . SchemaObject , schemaName ?: string ) : void {
485487 // Check if this schema or nested items have the oneOf pattern
@@ -490,21 +492,24 @@ export class SchemaModifier {
490492 return ;
491493 }
492494
493- // Add x-oneof to properties of this schema if it has the pattern
494- if ( hasDirectPattern && schema . properties ) {
495- for ( const propName in schema . properties ) {
496- const prop = schema . properties [ propName ] as any ;
497- if ( prop && typeof prop === 'object' ) {
498- prop [ 'x-oneof' ] = true ;
495+ // Only mark with x-oneof-constraint if the schema directly has the pattern
496+ // OR if it has nested patterns (parent schemas that contain oneOf)
497+ if ( hasDirectPattern ) {
498+ // Add x-oneof to properties of this schema if it has the direct pattern
499+ if ( schema . properties ) {
500+ for ( const propName in schema . properties ) {
501+ const prop = schema . properties [ propName ] as any ;
502+ if ( prop && typeof prop === 'object' ) {
503+ prop [ 'x-oneof' ] = true ;
504+ }
499505 }
500506 }
501- this . logger . info ( `Added x-oneof to properties with minProperties=1 and maxProperties=1` ) ;
502- }
503-
504- // Add x-oneof-constraint to top-level schemas (not nested in allOf/anyOf/oneOf)
505- if ( schemaName && ! [ 'allOf' , 'anyOf' , 'oneOf' ] . includes ( schemaName ) ) {
506507 ( schema as any ) [ 'x-oneof-constraint' ] = true ;
507- this . logger . info ( `Marked schema with x-oneof-constraint` ) ;
508+ this . logger . info ( `Added x-oneof to properties and marked schema with x-oneof-constraint` ) ;
509+ } else if ( hasNestedPattern ) {
510+ // Mark parent schemas that contain nested oneOf patterns
511+ ( schema as any ) [ 'x-oneof-constraint' ] = true ;
512+ this . logger . info ( `Marked parent schema with x-oneof-constraint (contains nested oneOf pattern)` ) ;
508513 }
509514 }
510515
0 commit comments