zod-prisma-types icon indicating copy to clipboard operation
zod-prisma-types copied to clipboard

integration with @hono/zod-openapi

Open takakikasuga opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe. we use @hono/zod-openapi. this is create openapi shema by using zod shema. we use prisma, so we use this library. but the generated schema is not compatible with @hono/zod-openapi... Can i request new feature??

I love this library because we need not create schema like template... if new feature is accepted and release, the developer who use cloudflare wokers in edge runtime with hono api will be happy!

takakikasuga avatar Nov 28 '24 00:11 takakikasuga

duplicate of https://github.com/chrishoermann/zod-prisma-types/issues/276

noqcks avatar Dec 03 '24 00:12 noqcks

For anyone else looking to ~~kludge~~ achieve this now, using patch-package:

patches/zod-prisma-types+3.2.4.patch:

diff --git a/node_modules/zod-prisma-types/dist/classes/fileWriter.js b/node_modules/zod-prisma-types/dist/classes/fileWriter.js
index b463964..b637392 100644
--- a/node_modules/zod-prisma-types/dist/classes/fileWriter.js
+++ b/node_modules/zod-prisma-types/dist/classes/fileWriter.js
@@ -39,6 +39,9 @@ class FileWriter {
         fs_1.default.writeFileSync(path, this.writer.toString());
     }
     writeImport(importName, importPath) {
+        if (importPath === 'zod') {
+            importPath = '@hono/zod-openapi';
+        }
         this.writer.writeLine(`import ${importName} from '${importPath}';`);
     }
     writeImportSet(strings) {
diff --git a/node_modules/zod-prisma-types/dist/functions/contentWriters/writeModelOrType.js b/node_modules/zod-prisma-types/dist/functions/contentWriters/writeModelOrType.js
index 3402e82..e97fb23 100644
--- a/node_modules/zod-prisma-types/dist/functions/contentWriters/writeModelOrType.js
+++ b/node_modules/zod-prisma-types/dist/functions/contentWriters/writeModelOrType.js
@@ -55,7 +55,7 @@ const writeModelOrType = ({ fileWriter: { writer, writeImport, writeImportSet, w
     if (model.zodCustomErrors) {
         writer.write(`, ${model.zodCustomErrors}`);
     }
-    writer.write(`)`);
+    writer.write(`).openapi('${model.name}');`);
     writer
         .blankLine()
         .write(`export type ${model.name} = z.infer<typeof ${model.name}Schema>`);

beaulac avatar Feb 25 '25 19:02 beaulac