Skip to content

Commit

Permalink
fix(core): support transform effect zod type for swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyijun committed May 17, 2023
1 parent 9e81b00 commit defc9fd
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/core/src/utils/zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,18 @@ export const zodTypeToSwagger = (
};
}

// TO-DO: Improve swagger output for zod schema with refinement (validate through JS functions)
if (config instanceof ZodEffects && config._def.effect.type === 'refinement') {
return {
type: 'object',
description: 'Validator function',
};
if (config instanceof ZodEffects) {
if (config._def.effect.type === 'transform') {
return zodTypeToSwagger(config._def.schema);
}

// TO-DO: Improve swagger output for zod schema with refinement (validate through JS functions)
if (config._def.effect.type === 'refinement') {
return {
type: 'object',
description: 'Validator function',
};
}
}

throw new RequestError('swagger.invalid_zod_type', config);
Expand Down

0 comments on commit defc9fd

Please sign in to comment.