atproto made easy crates.io/crates/jacquard

lexgen: generate actual enums for enum strings #29

Closed nonbinary.computer
Closed opened by and assigned to nonbinary.computer

Right now the generator will see the following and generate a Cowstr that isn't validated to be one of the possible closed values instead of a type safe enum.

"sortBy": {
   "type": "string",
   "enum": ["newest", "oldest", "top"],
   "default": "newest"
}

It would be a major improvement to change this behaviour.

Looking deeper I see that an unreleased commit did some implementation for knownValues, however this does not seem to lead to an open enum generation on query types, and possibly procedures too. It also is still not quite ideal as it's an open enum instead of a closed one.

queries and procedures let me take a look.

but yes, the next release will have improvements on this front. FYI, the reason i avoid making closed enums as much as possible is because i don't want someone to start getting deserialization errors because the lexicon changed and they hadn't re-generated their docs.

That makes sense but I guess I also think that breaks lexicon evolution rules anyway so that kind of thing shouldn't happen. I'm happy either way really

Sign up or Sign in to add to the discussion.