resticprofile
resticprofile copied to clipboard
JSON Schema
Is there a JSON Schema for restic(profile) configuration files?
I see a JSON Schema especially useful if the editor supports it (e.g. VS Code), because the editing of a supported file is much more comfortable.
some examples from other projects you might know:
- JavaScript
package.json
-
docker-compose.yaml
I couldn't find any information about an existing schema for resticprofile, so maybe there isn't one? If this is not yet planned, this issue is more a feature request/enhancement idea.
No, there's no schema available yet. But I was planning to do so.
I need to look up how to do it, as I've never published any before
Had a quick look on libs that can generate a schema (as a starting point):
- https://github.com/atombender/go-jsonschema - very simple implementation, could be taken as source and adjusted to work on
mapstructure
tags. - https://github.com/invopop/jsonschema - is more complete, maintained and should also be usable on the structs when defining an
AdditionalFields
callback that mapsmapstructure
tags tojson
tags.
Oh excellent!
It means little maintenance. I like that 😉
Maybe we could also read the cobra flags from restic repo so they get added automatically (wishful thinking at best).
Maybe we could also read the cobra flags from restic repo so they get added automatically (wishful thinking at best)
This is not so hard, I think. Cobra generates manual pages that are quite well structured and not too difficult to parse. From there we can get commands, options and even descriptions. We'd only need to decide if that happens during build time (my preference), runtime or both (when manual pages exist already). Build time means we'd need to reference restic as dependency and build it. As a side effect this enables real integration tests.
Knowing all restic commands and valid options would enable more than just json-schema, it also allows to validate the config, filter CLI args (e.g. replace the static list I added few days ago) and improve shell completion.
Knowing all restic commands and valid options would enable more than just json-schema, it also allows to validate the config, filter CLI args (e.g. replace the static list I added few days ago) and improve shell completion.
Originally I was thinking about running the restic initialisation code and get the flags definition from cobra. But since it's all happening in a main
package that's not an option.
But you're right, it shouldn't be too difficult to parse the generated help for each command 👍🏻
Another option would be to let some tooling generate the initial json schema and then convert that into a CUE definition: https://cuelang.org/docs/usecases/datadef/
CUE can then export that in various formats and cue can even be reused to directly generate and validate the user's configuration.
@creativeprojects: Had played a bit with restic command dictionary, here's a working prototype: #107
Let me know what you think then I'll try to add json-schema generation (and tests).
@megamorf - Thanks for the hint 👍. We're looking for low maintenance solutions that continuously generate the information from code. cue-lang does look interesting and might have the ability to work with this use-case.
However cue-lang to json-schema conversion is not ready https://github.com/cue-lang/cue/issues/929. So we probably implement json-schema for now only. But if you want a cue schema you can still generated it from the json-schema using the cue tools.
Let me know what you think then I'll try to add json-schema generation (and tests).
Yes please, it's really cool
Now available in v0.21.0 👍🏻 See Documentation