Skip to content

Proposal for an official JSON Schema for semver #431

@jenkin

Description

@jenkin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions