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: preprocess enable except on response? #1601

Open
mktktmr opened this issue Aug 28, 2024 · 7 comments
Open

Zod: preprocess enable except on response? #1601

mktktmr opened this issue Aug 28, 2024 · 7 comments
Labels
good first issue Good for newcomers zod Zod related issue

Comments

@mktktmr
Copy link

mktktmr commented Aug 28, 2024

Thanks developers for this awesome tool.

I have a question for zod preprocess.

Expectation

zod preprocess is enabled on body. (In my environment, preprocess is enabled on response only)

Version

  System:
    OS: macOS 13.6.7
    CPU: (8) arm64 Apple M1 Pro
    Memory: 84.08 MB / 32.00 GB
    Shell: 3.2.57 - /bin/bash
  npmPackages:
    axios: ^1.7.4 => 1.7.4
    msw: ^2.3.0 => 2.3.0
    orval: ^7.0.1 => 7.0.1
    react: ^18 => 18.3.1
    swr: ^2.2.5 => 2.2.5
    zod: ^3.23.8 => 3.23.8

My configuration

https://orval.dev/reference/configuration/output#preprocess

orval.config.js

module.exports = {
  client: {
    input: {
      target: './swagger.yaml',
    },
    output: {
      mode: 'tags-split',
      client: 'swr',
      target: 'src/gen/endpoints',
      schemas: 'src/gen/models',
      mock: true,
    },
  },
  zod: {
    input: {
      target: './swagger.yaml',
    },
    output: {
      mode: 'tags-split',
      client: 'zod',
      target: 'src/gen/endpoints',
      fileExtension: '.zod.ts',
      override: {
        zod: {
          strict: {
            response: true,
            query: true,
            param: true,
            header: true,
            body: true
          },
          coerce: {
            response: true,
            query: true,
            param: true,
            header: true,
            body: true
          },
          preprocess: {
            body: { // This does not work
              name: 'bar',
              path: './src/mutators.ts',
            },
          },
        },
      },
    },
  },
}
@mktktmr
Copy link
Author

mktktmr commented Aug 28, 2024

I read this code and I was convinced preprocess is enabled on response only now.
Do you have a plan to be enable preprocess except on response?
In addition, do you have method to enable preprocess except on response without orval.config.js at the moment?

@melloware melloware added the zod Zod related issue label Aug 28, 2024
@melloware melloware changed the title [Question] Is zod preprocess enable except on response? Zod: preprocess enable except on response? Aug 28, 2024
@melloware
Copy link
Collaborator

@mktktmr is this your issue: #1586 ???

@mktktmr
Copy link
Author

mktktmr commented Aug 28, 2024

@mktktmr is this your issue: #1586 ???

@melloware No. I want to use zod preprocess in request body.
So, I think #1586 is different to this issue.

@melloware
Copy link
Collaborator

How about this one #1575 ???

@mktktmr
Copy link
Author

mktktmr commented Aug 29, 2024

@melloware Thanks. #1575 is almost same. I think the both issues mention that preprocess does not work except on response.

      // ...
      override: {
        zod: {
          preprocess: {
            response: { /**/ }, // work well
            body: { /**/ }, // This does not work (mentioned by this issue)
            query: { /**/ }, // This does not work (mentioned by #1575)
            param: { /**/ }, // Maybe this does not work too
            header: { /**/ }, // Maybe This does not work too
          },

@melloware
Copy link
Collaborator

@mktktmr thanks for the clarification. Interested in investigating and providing a PR? If it works for Resposne then it should be easy to implement that code for the other sections?

@melloware melloware added the good first issue Good for newcomers label Aug 29, 2024
@mktktmr
Copy link
Author

mktktmr commented Aug 30, 2024

@melloware I see. I'll give it a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers zod Zod related issue
Projects
None yet
Development

No branches or pull requests

2 participants