Repository navigation
fix(schema): expose the serde aliases the exported schema was hiding - #423
Merged
Merged
Conversation
schemars does not emit #[serde(alias = ...)]: it writes only the canonical name. Every aliased spelling was therefore declared invalid by `rustmotion schema` while the engine accepts it perfectly -- and the exported schema is the file a generator reads to know what to write. Two mechanisms, both post-processed after generation: - variant aliases widen the `enum` array they belong to: float_3d, progress_bar, flex-start/flex_start, flex-end/flex_end, space-between/around/evenly. - field aliases add a property mirroring the canonical one's schema. BorderRadius is the case: its corners are declared as top-left and carry alias = "top_left", and the branch is deny_unknown_fields, so a scenario written the snake_case way was rejected outright. The tables are keyed by definition name, not by value. Keying by value would have been shorter and wrong: another enum with a `start` variant and no aliases would have inherited spellings the engine rejects, which turns a false negative into a false positive. Drift is covered by reading the sources rather than trusting the table: every_serde_alias_in_the_sources_is_reachable_from_the_exported_schema scans every .rs for `alias = "..."` and fails naming any that the exported schema does not contain. A new alias therefore fails CI instead of quietly falling out of the schema. Proven on minimal documents, since the examples are too noisy to isolate it: a scenario using `float_3d` or `progress_bar` was rejected by the exported schema and is accepted now. What this does not fix, and what the issue attributed to it: the repository's examples still fail schema validation, 62 paths before and after. Their causes are elsewhere -- templating placeholders ($delay, $d) are not modelled as anything but numbers, and Draft-7 anyOf reporting picks an arbitrary branch, so the messages name the wrong variant. Filed separately.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #162.
The defect
schemars does not emit
#[serde(alias = ...)]— it writes only the canonicalname. Every aliased spelling was therefore declared invalid by
rustmotion schemawhile the engine accepts it perfectly, and the exported schema is the file a
generator reads to know what to write.
Proven on minimal documents, validated with
jsonschema(Draft 7):{ "name": "float_3d" }in an animation{ "type": "progress_bar" }Two mechanisms
enumarray they belong to:float_3d,progress_bar,flex-start/flex_start,flex-end/flex_end,space-between/-around/-evenly.BorderRadiusis the case the issue did not mention: its corners are declaredas
top-leftand carryalias = "top_left", and the branch isdeny_unknown_fields, so a scenario written the snake_case way was rejectedoutright.
Keyed by definition, not by value
Keying by value would have been shorter and wrong: another enum with a
startvariant and no aliases would have inherited spellings the engine rejects — turning
a false negative into a false positive, which is the worse direction.
an_enum_that_shares_a_variant_name_but_not_its_aliases_is_left_alonepins it.Drift is covered by reading the sources
every_serde_alias_in_the_sources_is_reachable_from_the_exported_schemascansevery
.rsin the workspace foralias = "..."and fails naming any that theexported schema does not contain. A new alias fails CI instead of quietly falling
out of the schema — the table cannot silently go stale.
What this does not fix
The issue attributes the examples' schema failures to this: "All trace back to
'float_3d' is not one of ['float3d']". Measured, that is not so — the examplesfail on 62 paths before and after, unchanged. Their causes are elsewhere:
$delay,$d) are not modelled as anything butnumbers, so any templated scenario is invalid to the schema and fine to the
engine — the same class of defect, a different cause;
anyOfrelevance reporting picks an arbitrary branch, so the messagesname the wrong variant (
'fade_in' is not one of ['fade_in_up']) and the realcause is unreadable.
Filed as its own issue rather than folded in here.
Gate
cargo fmt --all --checkclean ·cargo clippy --workspace --all-targets --features rustmotion/studio -D warningsclean ·cargo test --workspace1814 passed.