schemars
schemars copied to clipboard
Set regex for Array String items
trafficstars
For the following code:
#[derive(Serialize, Deserialize, JsonSchema)]
pub struct Team {
/// # Users
/// A list of users.
#[schemars(regex(pattern = r"^(.*)$"))]
pub users: Vec<String>
}
This is the output I currently see for the users field:
"users": {
"title": "Users",
"description": "A list users.",
"type": "array",
"items": {
"type": "string"
}
},
As you can see, the regex is simply getting omitted entirely.
What I would like to see is:
"users": {
"title": "Users",
"description": "A list users.",
"type": "array",
"items": {
"pattern": "^(.*)$",
"type": "string"
}
},
Since regex doesn't make sense for an array, it should bubble down to the contained String type.
I would also expect this to work when setting length(max = 39) on the users field, where it isn't applied to the array, but to the underlying String.