Skip to content

Commit

Permalink
fix: avoid call union generator in intersection
Browse files Browse the repository at this point in the history
  • Loading branch information
ItMaga committed Apr 12, 2023
1 parent ceb024e commit d990b73
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/generators/IntersectionGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from 'zod';
import type { z } from 'zod';
import MockGenerator from '../MockGenerator';
import type BaseGenerator from './BaseGenerator';

Expand All @@ -12,8 +12,10 @@ export default class IntersectionGenerator<T extends z.ZodIntersection<z.ZodType
const sharedOptions = leftDef.options.filter((leftOption: z.ZodTypeAny) => {
return rightDef.options.some((rightOption: z.ZodTypeAny) => rightOption._def.typeName === leftOption._def.typeName);
});
const randomIndex = Math.floor(Math.random() * sharedOptions.length);
const randomOption = sharedOptions[randomIndex];

const mockGenerator = new MockGenerator(z.union(sharedOptions));
const mockGenerator = new MockGenerator(randomOption);
return mockGenerator.generate();
}
}
Expand Down

0 comments on commit d990b73

Please sign in to comment.