Repository navigation
fix(vespera_macro): parser round 49 findings - #571
Merged
Merged
Conversation
- R49-P3-M1: under the outer deny_unknown_fields a flattened struct that has
a flatten field of its own reads it through deserialize_map and consumes
none of its keys (serde leaves them in the buffer, so the outer struct
rejects them: probed with the workspace serde 1.0.229, both for a required
and an Option-wrapped member, and for a required or an optional enum). The
request view listed the nested enum's variant keys as accepted properties,
so `{"id":1,"Text":"a"}` passed the schema and failed serde. Such a member
now lists none of its keys; the closed object rejects them. The proposed
exactly-one-key-per-enum fix was refuted: it still accepted `{"Text":"a"}`.
- R49-P0-L2: handler lookup prefers the routed same-named fn over an
attribute-less cfg variant (a legacy `Json<Local>` no longer shadows the
routed `Json<Body>` that follows it).
- R49-P0-L1: merge_path_extractor_parameters doc now matches the code: a later
non-string Path extractor refines a string one. New String-then-u64 test.
- R49-P4-L1: generic instance encoding doc says injective only for argument
types whose schema depends on their spelling; the rest share `_.Value`.
- R49-P4-L2: aliased serde_json::Value asserts the any-value form too.
- R49-P4-L3: the polymorphic recursion test checks the innermost cut level
(depth-limit description only) instead of any `{}` anywhere.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Round 49 parser findings (crates/vespera_macro/src/parser/**, schema_assertions untouched, trybuild untouched).
Fixed
deny_unknown_fields, a flattened struct that has a flatten field of its own is read by serde throughdeserialize_map, and it consumes none of its keys: they stay in the buffer and the outer struct rejects them. The request schema listed the nested enum's variant keys as accepted properties, so{"id":1,"Text":"a"}passed the schema while serde rejected it. Probed with the workspace serde (1.0.229), for a required and anOption-wrapped member, and for a required and an optional enum: serde rejects every key of that shape (unknown field Text, and also the plainid2), and accepts{"id":1}. Fix: such a member lists none of its keys (assemble,request+deny_unknown_fields+!rejectedgate); the closed object then rejects them, as serde does.handler_fnprefers the routed same-named fn over an attribute-lesscfg-gated variant; the attribute-less fn is only the fallback. A legacyJson<Local>no longer shadows the routedJson<Body>that follows it.merge_path_extractor_parametersdoc now matches the code (a later non-stringPathextractor refines a string one). New test:Path<String>thenPath<u64>documents an integer.push_type_segmentsdoc: injective only for argument types whose schema depends on their spelling; the rest share_.Value(documented as any-value).aliased_serde_json_value_documents_like_the_bare_valuealso asserts the any-value form{}.polymorphic_recursion_is_capped_per_top_level_instancewalks the expansion and asserts the innermost cut level is the depth-limit description object, instead ofcontains("{}")anywhere.Refuted / not done as written
Textand leavesBytesfor the outer struct, so one key per optional enum should be exclusive. The probes show serde takes none of these keys under the outer deny, so the proposed exactly-one-key fix would still accept{"id":1,"Text":"a"}. The fix applied is the serde-accurate one above. The two existing unit tests that pinned the listing (deny_request_view_lists_a_nested_enums_keys_exclusively,deny_optional_struct_over_an_enum_takes_exactly_one_key) are rewritten as rejection tests; the snapshotsflatten_nested_enum_outer_denyandflatten_newtype_nested_outer_denychange only by dropping the listedText/Bytesproperties (plusoneOfbecominganyOfon the enum branch, which the closed object makes inert). Other deny-flatten snapshots are unchanged. The helpers that only served the listing (nested_keys,FlatPart::listed,enum_keys_among,exclusive_enums,optional_enum_keys,exclusive_branches,is_empty_schema) are removed.Option<Enum>under the outer deny (deny_optional_enum_takes_exactly_one_key,flatten_option_enum_outer_deny) is unchanged: serde does take one key there.Tests
cargo test -j 2 -p vespera_macro --lib: 6939 passed, 0 failed.cargo test -j 2 -p vespera: 247 passed, 0 failed (includesflatten_optional_enum_denywith the nested serde pin andschema_crate_alias).cargo fmt -p vespera_macro -p vespera -- --check: clean.cargo clippy -j 2 -p vespera_macro -p vespera --all-targets --all-features -- -D warnings: clean.extractor_validation.rs998 (was 985),flatten.rs856 (was 943), all others under 1000.examples/axum-example/openapi.jsonregeneration. No changed shape appears in the examples (StrictInputhas no flatten; the flattened examples have no deny), so the committedopenapi.jsonshould be unaffected.Changepack:
.changepacks/changepack_log_parser_round49.json(all seven packages, Patch).🤖 Generated with Claude Code