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

Proposal for an official JSON Schema for semver #431

Open
jenkin opened this issue Oct 10, 2023 · 1 comment
Open

Proposal for an official JSON Schema for semver #431

jenkin opened this issue Oct 10, 2023 · 1 comment

Comments

@jenkin
Copy link

jenkin commented Oct 10, 2023

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.

@michaelmior
Copy link

@jenkin Given that semver officially has no size limit, I would suggest removing maxLength. minLength also feels unnecessary since any valid version will be at least that long anyway.

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