Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[zod-mock] Support for ZodReadonly #195

Open
ericyoungberg opened this issue Mar 28, 2024 · 1 comment
Open

[zod-mock] Support for ZodReadonly #195

ericyoungberg opened this issue Mar 28, 2024 · 1 comment

Comments

@ericyoungberg
Copy link

ericyoungberg commented Mar 28, 2024

Looks like support for ZodReadonly was added to zod-openapi but not for zod-mock. The issue that I am running into is nearly identical to the issue that was resolved by the linked PR, except that it is in regards to the generateMock function instead of generateSchema.

@jaroel
Copy link

jaroel commented Oct 5, 2024

I used backupMocks to get around that.

import { type GenerateMockOptions, generateMock } from "@anatine/zod-mock";
import { type AnyZodObject, type ZodReadonly, z } from "zod";

const schema = z.object({});

const mockData = generateMock(schema, {
  backupMocks: {
    ZodReadonly: (zodRef: AnyZodObject, options?: GenerateMockOptions) => {
      const zodRef_ = zodRef as unknown as ZodReadonly<typeof schema>;
      return generateMock(zodRef_.unwrap(), options);
    },
  },
});

console.log({ mockData });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants