Skip to content

Commit ae8f1f4

Browse files
authored
fix(core/schema): allow structiterator call on unit schema (#1609)
1 parent d1d04c0 commit ae8f1f4

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

.changeset/serious-waves-cheat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@smithy/core": patch
3+
---
4+
5+
allow struct iterator acquisition on unit schema

packages/core/src/submodules/schema/schemas/NormalizedSchema.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ describe(NormalizedSchema.name, () => {
185185
expect(schema.getMergedTraits()).toEqual(entrySchema.getMergedTraits());
186186
}
187187
});
188+
189+
it("can acquire structIterator on the unit schema type and its iteration is empty", () => {
190+
const iteration = Array.from(NormalizedSchema.of("unit").structIterator());
191+
expect(iteration.length).toBe(0);
192+
});
188193
});
189194

190195
describe("traits", () => {

packages/core/src/submodules/schema/schemas/NormalizedSchema.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,9 @@ export class NormalizedSchema implements INormalizedSchema {
401401
* This avoids the overhead of calling Object.entries(ns.getMemberSchemas()).
402402
*/
403403
public *structIterator(): Generator<[string, NormalizedSchema], undefined, undefined> {
404+
if (this.isUnitSchema()) {
405+
return;
406+
}
404407
if (!this.isStructSchema()) {
405408
throw new Error("@smithy/core/schema - cannot acquire structIterator on non-struct schema.");
406409
}

0 commit comments

Comments
 (0)