python-jsonschema / check-jsonschema

A CLI and set of pre-commit hooks for jsonschema validation with built-in support for GitHub Workflows, Renovate, Azure Pipelines, and more!
https://check-jsonschema.readthedocs.io/en/stable
Other
206 stars 41 forks source link

Fail to validate Renovate.json file #450

Open pzelnip opened 3 months ago

pzelnip commented 3 months ago

With this renovate.json file:

{
    "$schema": "https://docs.renovatebot.com/renovate-schema.json",
    "packageRules": [
        {
            "groupName": "all non-major dependencies",
            "groupSlug": "all-minor-patch",
            "matchPackagePatterns": ["*"],
            "matchUpdateTypes": ["minor", "patch"]
        }
    ]
}

which Renovate happily accepts, I get validation errors when running check-jsonschema against it:

$ check-jsonschema --builtin-schema=vendor.renovate renovate.json 
Schema validation errors were encountered.
  .gitlab/renovate.json::$.packageRules[0].matchPackagePatterns: ['*'] is not valid under any of the given schemas
  Underlying errors caused this.

  Best Match:
    $.packageRules[0].matchPackagePatterns: ['*'] is not of type 'string'
  Best Deep Match:
    $.packageRules[0].matchPackagePatterns[0]: '*' is not a 'regex'
sirosen commented 3 months ago

My first thought is that the renovate schema (provided upstream) may not be accurate. I'm checking this now.

sirosen commented 3 months ago

Scratch that -- I removed the label -- their schema is fine. This seems like a simple case and I over-indexed on the Best Match. It's nice to see Best Deep Match providing value: '*' is, as it says, not a 'regex'.

Switching to ".*" for your pattern resolves it. Renovate may be lenient if the input pattern doesn't parse as a regex (e.g., they may failover to a globbing behavior), but I don't see a straightforward way for check-jsonschema to permit this.

If * is working to match on things, that would be a little interesting. If .* doesn't match, then I think that would make this into an upstream doc/schema issue -- it would mean that this field is not a regex.