Skip to content

fix(vespera_macro): parser round 49 findings - #571

Merged
owjs3901 merged 1 commit into
mainfrom
fix/parser-round49
Nov 29, 2026
Merged

owjs3901 merged 1 commit into
mainfrom
fix/parser-round49

Conversation

@owjs3901

Copy link
Copy Markdown
Contributor

Round 49 parser findings (crates/vespera_macro/src/parser/**, schema_assertions untouched, trybuild untouched).

Fixed

  • R49-P3-M1 (MED), rewritten. Under the outer deny_unknown_fields, a flattened struct that has a flatten field of its own is read by serde through deserialize_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 an Option-wrapped member, and for a required and an optional enum: serde rejects every key of that shape (unknown field Text, and also the plain id2), and accepts {"id":1}. Fix: such a member lists none of its keys (assemble, request + deny_unknown_fields + !rejected gate); the closed object then rejects them, as serde does.
  • R49-P0-L2 (LOW). handler_fn prefers the routed same-named fn over an attribute-less cfg-gated variant; the attribute-less fn is only the fallback. A legacy Json<Local> no longer shadows the routed Json<Body> that follows it.
  • R49-P0-L1 (LOW). The merge_path_extractor_parameters doc now matches the code (a later non-string Path extractor refines a string one). New test: Path<String> then Path<u64> documents an integer.
  • R49-P4-L1 (LOW). push_type_segments doc: injective only for argument types whose schema depends on their spelling; the rest share _.Value (documented as any-value).
  • R49-P4-L2 (LOW). aliased_serde_json_value_documents_like_the_bare_value also asserts the any-value form {}.
  • R49-P4-L3 (LOW). polymorphic_recursion_is_capped_per_top_level_instance walks the expansion and asserts the innermost cut level is the depth-limit description object, instead of contains("{}") anywhere.

Refuted / not done as written

  • R49-P3-M1's stated mechanism and fix are wrong. The pending finding says serde takes Text and leaves Bytes for 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 snapshots flatten_nested_enum_outer_deny and flatten_newtype_nested_outer_deny change only by dropping the listed Text / Bytes properties (plus oneOf becoming anyOf on 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.
  • Direct 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 (includes flatten_optional_enum_deny with the nested serde pin and schema_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.
  • File sizes: extractor_validation.rs 998 (was 985), flatten.rs 856 (was 943), all others under 1000.
  • Not run locally: tarpaulin 100% line coverage in CI's collapsed layout, the no-default-features clippy runs, trybuild, and examples/axum-example/openapi.json regeneration. No changed shape appears in the examples (StrictInput has no flatten; the flattened examples have no deny), so the committed openapi.json should be unaffected.

Changepack: .changepacks/changepack_log_parser_round49.json (all seven packages, Patch).

🤖 Generated with Claude Code

- 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>
@owjs3901
owjs3901 merged commit d331f55 into main Nov 29, 2026
27 of 28 checks passed
@owjs3901
owjs3901 deleted the fix/parser-round49 branch November 29, 2026 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant