Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Schema #103

Closed
rampd2 opened this issue Apr 18, 2022 · 10 comments
Closed

JSON Schema #103

rampd2 opened this issue Apr 18, 2022 · 10 comments
Labels
documentation Improvements or additions to documentation
Milestone

Comments

@rampd2
Copy link

rampd2 commented Apr 18, 2022

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:

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.

@creativeprojects
Copy link
Owner

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

@jkellerer
Copy link
Collaborator

Had a quick look on libs that can generate a schema (as a starting point):

@creativeprojects
Copy link
Owner

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).

@jkellerer
Copy link
Collaborator

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.

@creativeprojects
Copy link
Owner

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 👍🏻

@megamorf
Copy link

megamorf commented Apr 23, 2022

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.

@jkellerer
Copy link
Collaborator

jkellerer commented Apr 23, 2022

@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).

@jkellerer
Copy link
Collaborator

@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 cue-lang/cue#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.

@creativeprojects
Copy link
Owner

Let me know what you think then I'll try to add json-schema generation (and tests).

Yes please, it's really cool

@jkellerer jkellerer mentioned this issue Apr 24, 2022
6 tasks
@creativeprojects creativeprojects added the documentation Improvements or additions to documentation label Apr 25, 2022
@creativeprojects creativeprojects added this to the v0.18.0 milestone Apr 25, 2022
@creativeprojects creativeprojects modified the milestones: v0.18.0, v0.19.0 Aug 17, 2022
@creativeprojects creativeprojects modified the milestones: v0.19.0, v0.20.0 Nov 7, 2022
@creativeprojects creativeprojects modified the milestones: v0.20.0, v0.21.0 Jan 21, 2023
jkellerer added a commit to jkellerer/resticprofile that referenced this issue Feb 25, 2023
Squashed commits:

Fixed: use correct decoder for GenericSection
Fixed: restic version when flag/opt was removed
Added notice how to gen the reference
Fixed arg filtering and verbose arg with value
Added extra examples for http hook headers
Added failing test for inconsistent mixin-use
Added "user_logged_on" to schedule privilege
Added list-append to json-schema
Add examples to global.default-command
Added tests & cleanup
Fixed flags `use-fs-snapshot` (win) and `verbose`
Dynamically implement generic restic commands
Removed manual config reference (is generated now)
Generate JSON schema into documentation
Added v2 mixins to JSON schema
Initial support for "generate --json-schema"
Initial support for "generate --config-reference"
Moved PGP validation to go-selfupdate
Added restic 1.4 (make generate-restic)
Rebased & updated interfaces
Initial profile info API
Refactored restic, added versioning and install
Include a lookup table for restic commands
Adds build target "generate-restic-commands" to update the table
jkellerer added a commit that referenced this issue Feb 25, 2023
Squashed commits:

Fixed: use correct decoder for GenericSection
Fixed: restic version when flag/opt was removed
Added notice how to gen the reference
Fixed arg filtering and verbose arg with value
Added extra examples for http hook headers
Added failing test for inconsistent mixin-use
Added "user_logged_on" to schedule privilege
Added list-append to json-schema
Add examples to global.default-command
Added tests & cleanup
Fixed flags `use-fs-snapshot` (win) and `verbose`
Dynamically implement generic restic commands
Removed manual config reference (is generated now)
Generate JSON schema into documentation
Added v2 mixins to JSON schema
Initial support for "generate --json-schema"
Initial support for "generate --config-reference"
Moved PGP validation to go-selfupdate
Added restic 1.4 (make generate-restic)
Rebased & updated interfaces
Initial profile info API
Refactored restic, added versioning and install
Include a lookup table for restic commands
Adds build target "generate-restic-commands" to update the table
@creativeprojects
Copy link
Owner

Now available in v0.21.0 👍🏻
See Documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

4 participants