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

Regexes are not added to the usage site instead of the schema declaration #158

Open
WilliamABradley opened this issue Jun 20, 2023 · 0 comments

Comments

@WilliamABradley
Copy link

Current:

const UserId = z.string();
const User = z.object({
    _id: UserId.regex(/^user_[a-z0-9]{25,27}$/),
    full_name: z.string().optional(),
    email: z.string().optional(),
});

Expected:

const UserId = z.string().regex(/^user_[a-z0-9]{25,27}$/);
const User = z.object({
    _id: UserId,
    full_name: z.string().optional(),
    email: z.string().optional(),
});

Spec:

"UserId": {
  "type": "string",
  "format": "cuid",
  "pattern": "^user_[a-z0-9]{25,27}$"
},
"User": {
  "type": "object",
  "properties": {
    "_id": {
      "$ref": "#/components/schemas/UserId"
    },
    "full_name": {
      "type": "string"
    },
    "email": {
      "type": "string"
    }
  },
  "required": [
    "_id"
  ]
},

This is a problem if we want to pick out and validate UserId on it's own.

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

1 participant