Skip to content

Commit

Permalink
updated to official regex pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarTawfik authored and GREsau committed Aug 27, 2023
1 parent 96afd85 commit 951583f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion schemars/src/json_schema_impls/semver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ impl JsonSchema for Version {
SchemaObject {
instance_type: Some(InstanceType::String.into()),
string: Some(Box::new(StringValidation {
pattern: Some(r"^\d+\.\d+\.\d+([\-\+].+)?$".to_owned()),
// https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
pattern: Some(r"^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$".to_owned()),
..Default::default()
})),
..Default::default()
Expand Down
2 changes: 1 addition & 1 deletion schemars/tests/expected/semver.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"properties": {
"version": {
"type": "string",
"pattern": "^\\d+\\.\\d+\\.\\d+([\\-\\+].+)?$"
"pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$"
}
}
}

0 comments on commit 951583f

Please sign in to comment.