omar-dulaimi / prisma-zod-generator

Prisma 2+ generator to emit Zod schemas from your Prisma schema
MIT License
535 stars 45 forks source link

Property hiding #75

Open bring-shrubbery opened 1 year ago

bring-shrubbery commented 1 year ago

Problem

Currently you are able to hide whole models by using /// @@Gen.model(hide: true) doc string. There's no ability to hide individual properties on demand.

Suggested solution

User should be able to add a doc string to a property to hide that property, similarly to the model hiding:

model SomeModel {
  id String @id 
  /// @@Gen.property(hide: true)
  hiddenField String
}

Which would generate zod schema with just id:

const SomeModel = z.object({
  id: z.string()
});

Alternatives

This solution follows the same approach as the model hiding does, so I don't have alternative solutions here.

Additional context

I've already implemented this feature in a fork, there will be a PR for this.