-
Notifications
You must be signed in to change notification settings - Fork 301
Open
Description
Semver has an official regex for validation.
We can use it to offer an official JSON Schema to validate a semver compliant string.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://semver.org/semver.schema.json",
"type": "string",
"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-]+)*))?$",
"minLength": 5,
"maxLength": 256,
"description": "A semver.org compliant version number."
}So in a custom schema you can refer to the official one using $ref attribute without copy-pasting anything.
{
"type": "object",
"properties": {
"version": {
"$ref": "https://semver.org/semver.schema.json"
}
}
}See also this issue in json-schema-spec repository: json-schema-org/json-schema-spec#1108.
paolomainardi, grota, ailequal, michaelmior, danielbayley and 2 more
Metadata
Metadata
Assignees
Labels
No labels