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

expected validate path attribute to be a string: path = "..." #302

Closed
forest1102 opened this issue Jun 28, 2024 · 1 comment
Closed

expected validate path attribute to be a string: path = "..." #302

forest1102 opened this issue Jun 28, 2024 · 1 comment

Comments

@forest1102
Copy link

forest1102 commented Jun 28, 2024

Because of syntax difference in regex validation between Validator and schemars, compile error occurs when using regex.
In validators,

    #[validate(regex(path = *RE_TWO_CHARS))]

While schemars,

    #[validate(regex(path = "RE_TWO_CHARS"))]

Sample:

static RE_TWO_CHARS: Lazy<Regex> = Lazy::new(|| Regex::new(r"[a-z]{2}$").unwrap());

#[derive(Deserialize, Debug, Validate, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct SampleJdto {
    #[validate(regex(path = *RE_TWO_CHARS))]
    pub project_name: String,
}
@GREsau
Copy link
Owner

GREsau commented Aug 27, 2024

This is fixed in schemars 1.0.0-alpha.13 🙂

The schema generated from the sample given in this issue is now:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "SampleJdto",
  "type": "object",
  "properties": {
    "projectName": {
      "type": "string",
      "pattern": "[a-z]{2}$"
    }
  },
  "required": [
    "projectName"
  ]
}

@GREsau GREsau closed this as completed Aug 27, 2024
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

2 participants