Skip to content

Commit

Permalink
fix: intersection union model
Browse files Browse the repository at this point in the history
  • Loading branch information
ItMaga committed Apr 12, 2023
1 parent fec4a42 commit bc839f9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/generators/IntersectionGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import type BaseGenerator from './BaseGenerator';

export default class IntersectionGenerator<T extends z.ZodIntersection<z.ZodTypeAny, z.ZodTypeAny>> implements BaseGenerator<T> {
public generate(schema: T) {
if ('typeName' in schema._def.left && 'typeName' in schema._def.right) {
if (schema._def.left.typeName === 'ZodUnion' && schema._def.right.typeName === 'ZodUnion') {
const sharedOptions = schema._def.left._def.options.filter((leftOption: z.ZodTypeAny) => {
return schema._def.right._def.options.some((rightOption: z.ZodTypeAny) => rightOption._def.typeName === leftOption._def.typeName);
const { _def: leftDef } = schema._def.left;
const { _def: rightDef } = schema._def.right;

if ('typeName' in leftDef && 'typeName' in rightDef) {
if (leftDef.typeName === 'ZodUnion' && rightDef.typeName === 'ZodUnion') {
const sharedOptions = leftDef.options.filter((leftOption: z.ZodTypeAny) => {
return rightDef.options.some((rightOption: z.ZodTypeAny) => rightOption._def.typeName === leftOption._def.typeName);
});

const mockGenerator = new MockGenerator(z.union(sharedOptions));
Expand Down

0 comments on commit bc839f9

Please sign in to comment.