creativeprojects / resticprofile

Configuration profiles manager and scheduler for restic backup
https://creativeprojects.github.io/resticprofile/
GNU General Public License v3.0
743 stars 33 forks source link

JSON Schemas are invalid #400

Closed jlledo closed 1 month ago

jlledo commented 2 months ago

The JSON schemas provided in the docs are invalid, and can't be parsed by e.g. the "Even Better TOML" v0.19.2 VS Code extension—suggested in the docs too. I have confirmed schema parsing also fails with the boon v0.6.0 validator.

I hope I'm not making a mistake—given how easy this is to reproduce you'd think someone would've reported the issue earlier.

The specific error shown in the "Even Better TOML LSP" output is:

ERROR document_change:publish_diagnostics:collect_schema_errors: schema validation failed error=invalid schema https://creativeprojects.github.io/resticprofile/jsonschema/config-1.json

Caused by:
    invalid schema: relative URL without a base document_url=file:///<REDACTED>

I believe this is because the 2019-09 JSON Schema draft requires the $id keyword to be an absolute URI:

If present, the value for this keyword MUST be a string, and MUST represent a valid URI-reference. This URI-reference SHOULD be normalized, and MUST resolve to an absolute-URI (without a fragment).

whereas the resticprofile schema $id is just a path: /resticprofile/jsonschema/config-1.json.

Could you please change the $id to an absolute URI to make the schema parseable and conform to the spec?

creativeprojects commented 1 month ago

Sorry I was away the last few weeks.

Funny enough I did notice something was wrong with it just before going away.

I'll have a look, thanks for the investigation

creativeprojects commented 1 month ago

I was (finally) looking into it today:

I'm also getting the error you mentioned from the Even Better TOML LSP so I will make the change (it used to work so they must have changed something)

Our tests are using ajv which is considering the schema valid. But then I also tried the tool you mentioned without any issue:

% boon -c -f https://creativeprojects.github.io/resticprofile/jsonschema/config-2.json
schema https://creativeprojects.github.io/resticprofile/jsonschema/config-2.json: ok
%

(It can't parse version 1 but it's because of an incompatible regex)

I'm just trying to avoid getting any related error in the future by making sure the tool we're using to validate our schemas in the pipeline are efficient.

How did you get the error with boon validator?

jlledo commented 1 month ago

My bad regarding boon, I misremembered the actual error with v1 when I wrote my first comment. Thanks for fixing the $id issue.

creativeprojects commented 1 month ago

Ok, thanks for the confirmation.

As it turns out, it's a fairly recent bug from the extension: The schema was valid, as the $id is supposed to be concatenated with the URL where the schema was downloaded from.

They're both valid anyway so adding the full URL made the extension happy 👍🏻