@@ -488,7 +488,14 @@ function schemaTypes(schema: JsonSchemaRecord): Set<string> {
488488 return new Set ( ) ;
489489}
490490
491- function schemaAlternatives ( schema : JsonSchemaRecord ) : JsonSchemaRecord [ ] {
491+ function schemaAlternatives (
492+ schema : JsonSchemaRecord ,
493+ seen = new Set < JsonSchemaRecord > ( ) ,
494+ ) : JsonSchemaRecord [ ] {
495+ if ( seen . has ( schema ) ) {
496+ return [ ] ;
497+ }
498+ seen . add ( schema ) ;
492499 const alternatives : JsonSchemaRecord [ ] = [ schema ] ;
493500 for ( const key of [ "anyOf" , "oneOf" , "allOf" ] as const ) {
494501 const entries = schema [ key ] ;
@@ -497,15 +504,19 @@ function schemaAlternatives(schema: JsonSchemaRecord): JsonSchemaRecord[] {
497504 }
498505 for ( const entry of entries ) {
499506 if ( isSchemaRecord ( entry ) ) {
500- alternatives . push ( ...schemaAlternatives ( entry ) ) ;
507+ alternatives . push ( ...schemaAlternatives ( entry , seen ) ) ;
501508 }
502509 }
503510 }
504511 return alternatives ;
505512}
506513
507514function schemaLooksArray ( schema : JsonSchemaRecord ) : boolean {
508- return schemaTypes ( schema ) . has ( "array" ) || isSchemaRecord ( schema . items ) ;
515+ return (
516+ schemaTypes ( schema ) . has ( "array" ) ||
517+ isSchemaRecord ( schema . items ) ||
518+ Array . isArray ( schema . items )
519+ ) ;
509520}
510521
511522function schemaLooksObject ( schema : JsonSchemaRecord ) : boolean {
@@ -522,8 +533,14 @@ function propertySchema(schema: JsonSchemaRecord, segment: PathSegment): JsonSch
522533 const schemas : JsonSchemaRecord [ ] = [ ] ;
523534 for ( const alternative of schemaAlternatives ( schema ) ) {
524535 if ( schemaLooksArray ( alternative ) ) {
525- if ( isIndexSegment ( segment ) && isSchemaRecord ( alternative . items ) ) {
526- schemas . push ( alternative . items ) ;
536+ if ( isIndexSegment ( segment ) ) {
537+ const index = Number . parseInt ( segment , 10 ) ;
538+ const indexedItem = Array . isArray ( alternative . items )
539+ ? alternative . items [ index ]
540+ : alternative . items ;
541+ if ( isSchemaRecord ( indexedItem ) ) {
542+ schemas . push ( indexedItem ) ;
543+ }
527544 }
528545 continue ;
529546 }
0 commit comments