Open zi-gae opened 3 weeks ago
@zi-gae as far as I know the Zod stuff is generated for all responses see this closed request as completed: https://github.com/orval-labs/orval/issues/1380
I submitted a PR to update the docs for zod but you should be able to do this.
module.exports = {
petstore: {
output: {
...
override: {
zod: {
generateEachHttpStatus: true,
},
},
},
...
},
};
@melloware I am using the following configuration in my project:
module.exports = {
petstore: {
output: {
mode: 'tags-split',
target: 'src/gen/endpoints',
schemas: 'src/model',
client: 'react-query',
mock: true,
override: {
zod: {
generateEachHttpStatus: true,
},
},
},
input: {
target: './api.json',
},
},
petstoreZod: {
input: {
target: './api.json',
},
output: {
mode: 'tags-split',
client: 'zod',
target: 'src/gen/endpoints',
fileExtension: '.zod.ts',
},
},
};
The issue I'm encountering is that while request parameter schema validation is correctly generated, the response schema validation for the GET method is not being generated.
I suspect that I might be missing something in the configuration, but I cannot pinpoint what exactly is causing this issue. Any advice or suggestions on what might be going wrong here would be greatly appreciated!
Thank you in advance!
Swagger URL: https://admin-dev-api.bluekeydsat.com/v3/api-docs
don't you need the override on the zod client itself?
module.exports = {
petstore: {
output: {
mode: 'tags-split',
target: 'src/gen/endpoints',
schemas: 'src/model',
client: 'react-query',
mock: true,
},
input: {
target: './api.json',
},
},
petstoreZod: {
input: {
target: './api.json',
},
output: {
mode: 'tags-split',
client: 'zod',
target: 'src/gen/endpoints',
fileExtension: '.zod.ts',
override: {
zod: {
generateEachHttpStatus: true,
},
},
},
},
};
@melloware
When running the command npx orval --config ./orval.config.cjs
with the configuration below, the Zod schema for validating response values from GET methods is not being generated. Instead, only the Zod schemas for request parameters and body values are being created.
// orval.config.cjs
module.exports = {
petstore: {
output: {
mode: 'tags-split',
target: 'src/gen/endpoints',
schemas: 'src/model',
client: 'react-query',
mock: true,
},
input: {
target: './api.json',
},
},
petstoreZod: {
input: {
target: './api.json',
},
output: {
mode: 'tags-split',
client: 'zod',
target: 'src/gen/endpoints',
fileExtension: '.zod.ts',
override: {
zod: {
generateEachHttpStatus: true,
},
},
},
},
};
Expected Behavior: Zod schemas should be generated for both the response values and the request parameters/body values when using GET methods.
Actual Behavior: Only the request parameters and body value schemas are being generated. The Zod schema for response values from GET methods is missing.
Could you please provide guidance or a fix for ensuring that Zod schemas for GET method responses are generated correctly?
You will have to look at the code and provide a PR to fix. Or ask one of the other devs who made zod fixes to see if they can help...
Description:
Hi there,
I am using Orval with the react-query option and the zod option for request validation. I have successfully validated the request parameters using the Zod schema, but I would like to validate the response schema as well.
Questions:
Is there currently a way to validate the response schema using Zod in this setup? If not, is there a particular reason why response validation with Zod is not supported?