Open anussel5559 opened 1 week ago
What is the concrete workflow you'd like to enable with this? Currently when I start a new collection file I usually just copy and paste an example from the docs, or a previous file, and edit from there. It's definitely not great, so I'm curious how you think we can leverage a schema to make that process easier.
Sure! So my thought is it'd be nice to not have to copy-paste. The IDE can be powerful if it knows what the schema is, it's mostly useless without it.
Today, unless you copy-paste and don't make any mistakes when modifying that pasted bit of config, you'd never know that you may have an invalid config file until you startup the app when it parses. This feels slightly wasteful since the IDE could've told the user that well before running the app.
Additionally, these configs make use of custom yaml tags, which the generic YAML validator knows nothing about (and thus complains) -
Ultimately this is a minor inconvenience and FAR from a boundary to successfully writing a valid config.
@anussel5559 What would the artifact of schema generation look like? You mentioned schemars, are you picturing slumber spitting out a JSONSchema file? How would that get loaded into the IDE? How do we tell the IDE that slumber.yml
should be parsed according to that schema?
@LucasPickering yup, yaml schema is just JSON schema and that's what schemars would generate.
There's a few ways the JSON schema can be associated to the yaml file to enable validation/hinting/docs/etc... (checkout this article), but likely the easiest way is to host the schema, and document that schema validation can be enabled by setting:
# yaml-language-server: $schema=https://my.url.to/the/schema
at the top of the config file.
Yeah I like this idea! I just opened a related feature #376 to add a subcommand slumber new
, which would generate a new collection file. This file would include that comment at the top so users don't have to write it manually. And we could host the YAML file on the website, since that is already a process that generates static files in CI and hosts them.
I'm going to do the slumber new
thing, do you want to work on this issue?
awesome! That makes a lot of sense. I'm definitely interested in helping out with this, likely after I get some solid movement on the collection ref stuff.
Did you search for existing issues already? Yup!
Is your feature request related to a problem? Please describe. Nope
Describe the solution you'd like Currently, when building or editing a slumber yaml configuration, there's no schema available - this isn't a huge deal, but leaves the user to their own devices as far as building a valid config file.
With a generated schema, the user's IDE can help guide them through building a valid config, and call out potential issues before they go to run the app.
Describe alternatives you've considered None
Additional context I looked a bit in to schemars to generate the schema from the
Collection
struct, but there was enough sprawl there that it made more sense to bring it up and talk about this potential feature more generally.