Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

schema is not generated with validation when comment includes Japanese #118

Closed
manak1 opened this issue Apr 1, 2023 · 4 comments
Closed

Comments

@manak1
Copy link
Contributor

manak1 commented Apr 1, 2023

Hello, Thank you for creating a wonderful package!
I have a problem generating schema with validation using Japanese error message.
Is there any workaround for this problem? 馃憖

datasource db {
  provider  = "postgres"
}

generator zod {
  provider = "zod-prisma-types"
}

model User {
  id String @id @default(uuid())
  /// @zod.string({ required_error: 'required' })
  email String 
  /// @zod.string({ required_error: '蹇呴爤闋呯洰銇с仚' })
  password String
}

Expected output

export const UserSchema = z.object({
  id: z.string().uuid(),
  email: z.string({ required_error: 'required' }),
  password: z.string({ required_error: '蹇呴爤闋呯洰銇с仚' }),
})

Actual output

export const UserSchema = z.object({
  id: z.string().uuid(),
  email: z.string({ required_error: 'required' }),
  /**
   * ({ required_error: '蹇呴爤闋呯洰銇с仚' })
   */
  password: z.string(),
})
@chrishoermann
Copy link
Owner

chrishoermann commented Apr 2, 2023

@manak1 thanks for pointing this out. since I'm using regexes quite heavily to validate if the user input is valid this problem happens becaues I do not check for Japanese characters since I do not speak nor can I read your language - so sadly Ihave no idea how to check for these characters 馃槩

maybe you could open a PR or provide some info on how to check for Japanese in a regex?

@manak1
Copy link
Contributor Author

manak1 commented Apr 4, 2023

@chrishoermann
Thank you for your response!
I'm not really familiar with regex but I will check it out 馃憖

@dbtl88
Copy link

dbtl88 commented Apr 17, 2023

Not sure how helpful this still might be, but this should work to match all Japanese text:

[\p{sc=Hira}\p{sc=Kana}\p{sc=Han}]

Which is the same as (using the combined hiragana / katakana unicode script identifier):

[\p{sc=Hrkt}\p{sc=Han}]

Explanations can be found here:
how to do regex on Unicode script identifiers (section 1.2.6)
the list of Unicode script identifiers

Note I've also included the 'Han' script identifier, i.e. all of the possible Kanji.

EDIT: I've validated through a regex validator, and the "Hrkt" identifier doesn't work on ECMAScript regex, so please use the first version, with the separate hiragana / katakana identifiers.

@chrishoermann
Copy link
Owner

I implemented the behaviour as suggested by @dbtl88 and according to my tests it works. Would be nice if someone could confirm this with a more extended range of japanese characters than the ones I used in my tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants