Skip to content

Commit

Permalink
feat(walker): additionalItems
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed Jan 22, 2024
1 parent a98ecbd commit 3dd29fc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
31 changes: 27 additions & 4 deletions src/__tests__/__snapshots__/tree.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -300,31 +300,54 @@ exports[`SchemaTree output should generate valid tree for arrays/additional-empt
"└─ #
├─ types
│ └─ 0: array
└─ primaryType: array
├─ primaryType: array
└─ children
└─ 0
└─ #/additionalItems
"
`;

exports[`SchemaTree output should generate valid tree for arrays/additional-false.json 1`] = `
"└─ #
├─ types
│ └─ 0: array
└─ primaryType: array
├─ primaryType: array
└─ children
└─ 0
└─ #/additionalItems
└─ value: false
"
`;

exports[`SchemaTree output should generate valid tree for arrays/additional-schema.json 1`] = `
"└─ #
├─ types
│ └─ 0: array
└─ primaryType: array
├─ primaryType: array
└─ children
└─ 0
└─ #/additionalItems
├─ types
│ └─ 0: object
├─ primaryType: object
└─ children
└─ 0
└─ #/additionalItems/properties/baz
├─ types
│ └─ 0: number
└─ primaryType: number
"
`;

exports[`SchemaTree output should generate valid tree for arrays/additional-true.json 1`] = `
"└─ #
├─ types
│ └─ 0: array
└─ primaryType: array
├─ primaryType: array
└─ children
└─ 0
└─ #/additionalItems
└─ value: true
"
`;

Expand Down
19 changes: 14 additions & 5 deletions src/walker/walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,20 @@ export class Walker extends EventEmitter<WalkerEmitter> {
this.path.push('items', String(i));
this.walk();
}
} else if (isObjectLiteral(fragment.items)) {
this.fragment = fragment.items;
this.restoreInternalWalkerState(state);
this.path.push('items');
this.walk();
} else {
if (isObjectLiteral(fragment.items)) {
this.fragment = fragment.items;
this.restoreInternalWalkerState(state);
this.path.push('items');
this.walk();
}

if (isValidSchemaFragment(fragment.additionalItems)) {
this.fragment = fragment.additionalItems;
this.restoreInternalWalkerState(state);
this.path.push('additionalItems');
this.walk();
}
}

break;
Expand Down

0 comments on commit 3dd29fc

Please sign in to comment.