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

Prettier: true fails for zod when not generating a schema #1350

Open
Georgegriff opened this issue May 2, 2024 · 0 comments
Open

Prettier: true fails for zod when not generating a schema #1350

Georgegriff opened this issue May 2, 2024 · 0 comments
Labels
zod Zod related issue

Comments

@Georgegriff
Copy link
Sponsor

Georgegriff commented May 2, 2024

What are the steps to reproduce this issue?

1.With the following config

import { defineConfig } from "orval";

// eslint-disable-next-line import/no-default-export
export default defineConfig({
  zod: {
    input: {
      target: "./v2/schema.json",
    },
    output: {
      client: "zod",
      prettier: true,
      mode: "tags",
      target: "v2/generated/validation/file.ts",
    },
  },
});

2.It outputs "Prettier not found", but this is because the actual error message is swallowed

Error: Command failed with exit code 2: prettier --write /Users/xxxx/generated/validation/cms.ts /Users/george.griffiths/Code/platform-wrapper/mittens/packages/main/app/clients/openapi/v2/generated/validation/file.schemas.ts
[error] No files matching the pattern were found: "/Users/xxx/generated/validation/file.schemas.ts".

Your code
image

What happens?

Prettier fails to run on the zod code

What were you expecting to happen?

If it is possible to not generate the schema types.ts files then it should not error.

The longer version:

  • The entire reason i'm generating the zod schema separately is because you seemingly can't generated a react-query client and zod client in the same config, so this is my workaround.

Any logs, error output, etc?

Any other comments?

There is a workaround, i can just duplicate the schema in both configs e.g.

import { defineConfig } from "orval";

export default defineConfig({
  v2: {
    input: {
      target: "./v2/schema.json",
    },
    output: {
      mode: "tags-split",
      target: "v2/generated/schema.ts",
      // specify the schema again
      schemas: "v2/generated/types",
      client: "react-query",
      baseUrl: "/v2",
      prettier: true,
    },
  },
  v2_zod: {
    input: {
      target: "./v2/schema.json",
    },
    output: {
      client: "zod",
      prettier: true,
      mode: "tags",
      schemas: "v2/generated/types",
      target: "v2/generated/validation/file.ts",
    },
  },
});

What versions are you using?

Operating System:
Package Version:
Browser Version:

@melloware melloware added the zod Zod related issue label May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
zod Zod related issue
Projects
None yet
Development

No branches or pull requests

2 participants