resticprofile icon indicating copy to clipboard operation
resticprofile copied to clipboard

Global json schema (auto versioning)

Open jkellerer opened this issue 2 years ago β€’ 5 comments

This PR:

  • Generates a JSON schema that redirects to versioned schemas based on version and global.restic-version properties (see also SchemaStore).
  • Adds an URL for the schema: https://creativeprojects.github.io/resticprofile/jsonschema/config.json
  • Fixes generate --config-reference filename
  • Simplifies config-1 schema files (schema in additionalProperties instead of via regex matching with negative lookbehind)

The is the first step to add the schema to the schemastore catalog (we need a single schema for this) and is also more convenient if the URL doesn't need to be changed πŸ˜€

jkellerer avatar Apr 17 '23 20:04 jkellerer

Codecov Report

Patch coverage: 95.00% and project coverage change: +0.04 :tada:

Comparison is base (7f8554f) 76.02% compared to head (d458c2f) 76.05%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #195      +/-   ##
==========================================
+ Coverage   76.02%   76.05%   +0.04%     
==========================================
  Files          93       93              
  Lines        9777     9784       +7     
==========================================
+ Hits         7432     7441       +9     
  Misses       2086     2086              
+ Partials      259      257       -2     
Impacted Files Coverage Ξ”
config/global.go 84.21% <ΓΈ> (ΓΈ)
config/jsonschema/model.go 94.26% <92.86%> (-0.16%) :arrow_down:
commands.go 55.65% <100.00%> (+0.93%) :arrow_up:
config/jsonschema/schema.go 97.98% <100.00%> (-0.04%) :arrow_down:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

codecov[bot] avatar Apr 17 '23 20:04 codecov[bot]

After some adjustments it works well for YAML and JSON now. "Even better TOML" doesn't support if/then/else, but without it, YAML and JSON report errors incorrectly, since not setting a version is also an error when only using implication and it is the first and only reported error in this case.

One improvement for "Even better TOML" however is that the updated version-1 schema now also works correctly. Previously it didn't support profile commands due to the lack of full regex support in the editor plugin.

For testing with local references, run:

SCHEMA_BASE_URL="http://localhost:1313/resticprofile/jsonschema" \
resticprofile generate --config-reference contrib/templates/config-schema.gojson > docs/static/jsonschema/config.json

Auto selection then works with:

# yaml-language-server: $schema=http://localhost:1313/resticprofile/jsonschema/config.json
version: "2"

global:
  restic-version: "0.15"

jkellerer avatar Apr 19 '23 13:04 jkellerer

This looks good to me, thanks for this PR πŸ‘πŸ»

I was trying the new configuration locally but it seems that it doesn't recognise the version 2. Am I doing something wrong?

Screenshot 2023-04-22 at 23 13 53

creativeprojects avatar Apr 22 '23 22:04 creativeprojects

Might be due to implication. While most examples indicate that it should be fine to use it for versioning, I think it needs to be updated to select all versions first using if/then/else and only when this validates, choose a schema for the rest of the document. Otherwise editors will always struggle with priority of errors (or fail to select a different schema).

Will update the template.

jkellerer avatar Apr 23 '23 11:04 jkellerer

Thanks!

I had a quick look at the JSON schema specs and hmmm it does look cutting edge 😐

creativeprojects avatar Apr 23 '23 12:04 creativeprojects