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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zod: client generates wrong RegExp #889

Closed
irrvrsl opened this issue Jul 4, 2023 · 2 comments · Fixed by #1050
Closed

Zod: client generates wrong RegExp #889

irrvrsl opened this issue Jul 4, 2023 · 2 comments · Fixed by #1050
Assignees
Labels
bug Something isn't working zod Zod related issue
Milestone

Comments

@irrvrsl
Copy link

irrvrsl commented Jul 4, 2023

What are the steps to reproduce this issue?

  1. Have pattern property in your OpenAPI's Schema, e.g. "^\\+\\d{10, 15}" (took from schema.json, pattern for phone_number property)
  2. Generate Schema

What happens?

Output will have RegExp string without special character escapes "^+d{10, 15}"

What were you expecting to happen?

Output should have valid RegExp string "^\+\d{10, 15}"

Any logs, error output, etc?

N/A

Any other comments?

Currently I just omit this property with transformer function

What versions are you using?

Operating System: MacOS Ventura 13.4
Package Version: 6.16.0
Browser Version: Firefox 114.0.2

@melloware melloware added the bug Something isn't working label Nov 10, 2023
@melloware melloware changed the title Zod client generates wrong RegExp Zod: client generates wrong RegExp Nov 10, 2023
@melloware melloware self-assigned this Nov 14, 2023
@melloware melloware added this to the 6.21.0 milestone Nov 14, 2023
@melloware
Copy link
Collaborator

melloware commented Nov 14, 2023

I just wrote this test which is what the Zod generator is doing and it looks correct?

describe('string testing', () => {
  it('cleanse JS String', () => {
    expect(new RegExp(jsStringEscape('^\\+\\d{10, 15}'))).toEqual(
      /^\\+\\d{10, 15}/,
    );
  });
});

Have you tested against 6.20.0 ?

@melloware
Copy link
Collaborator

melloware commented Nov 14, 2023

@irrvrsl according to OpenAPI your regex is incorrect.

https://swagger.io/docs/specification/data-models/data-types/

The pattern should be in JS format already like...

pattern: '^\+\d{10, 15}'

@melloware melloware added the zod Zod related issue label Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working zod Zod related issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants