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

Property hiding

Open bring-shrubbery opened this issue 2 years ago • 5 comments

Please see the contributing guidelines for how to create and submit a high-quality PR for this repo.

Description

This PR adds a way of hiding properties of models using a doc string. The API is the same as hiding models, but uses .property instead of .model in the doc string.

Also, here's a list of the things done in this PR:

  • Implements property hiding.
  • Adds example of property hiding to the example Prisma schema file.
  • Adds small documentation section in README for how to use this feature.

References

Implements solution for #75

bring-shrubbery avatar Feb 24 '23 15:02 bring-shrubbery

@omar-dulaimi Tagging you to review this, since you were the one to implement the @@Gen.model(hide: true) feature, hope you don't mind me tagging you :)

bring-shrubbery avatar Feb 24 '23 16:02 bring-shrubbery

Hey @bring-shrubbery Thanks for the PR! I'll take a look

omar-dulaimi avatar Feb 26 '23 17:02 omar-dulaimi

It seems to be working fine. But I noticed this validation error:

Property 'hiddenField' is missing in type '{ value: string; key: string; }' but required in type 'MapCreateInput'.ts(2322)

It happens in MapCreateInput.schema.ts:

import { z } from 'zod';

import type { Prisma } from '@prisma/client';

const Schema: z.ZodType<Prisma.MapCreateInput> = z
  .object({
    key: z.string(),
    value: z.string(),
  })
  .strict();

export const MapCreateInputObjectSchema = Schema;

To solve it I think we should get rid of the type casting this library currently do z.ZodType<Prisma.MapCreateInput>.

But that would cause issues reported in the past about schemas that reference themselves. I read somewhere that wrapping all generated schemas with z.lazy should solve the issue, but haven't tried that yet.

Also, there seems to be a current problem while ignoring fields, when ignoring the same field hidden, the while create map schemas disappears despite having two remaining fields.

These are all my thoughts so far.

omar-dulaimi avatar Feb 26 '23 18:02 omar-dulaimi

@omar-dulaimi Nice catch! I'll take a look at it this week and will try to implement a fix using your suggestions.

bring-shrubbery avatar Feb 26 '23 22:02 bring-shrubbery

Hey @bring-shrubbery Any update on this?

omar-dulaimi avatar Apr 28 '23 07:04 omar-dulaimi