Skip to content

Round 41: schema_type! private-path refusals and layout/stale edge cases - #522

Open
owjs3901 wants to merge 1 commit into
mainfrom
fix/schema-round41
Open

owjs3901 wants to merge 1 commit into
mainfrom
fix/schema-round41

Conversation

@owjs3901

Copy link
Copy Markdown
Contributor

Round-41 schema_macro fixes (findings from the round-41 audit of crates/vespera_macro/src/schema_macro/** and schema_impl*).

Fixed

  • R41-SM1-1 (medium) crate_layout::layout_for: a call site under tests/ / examples/ / benches/ whose target directory has no named root (custom [[test]] name = "integration" path = "tests/main.rs", helper tests/common/mod.rs) fell through to the library layout, so crate:: resolved against src/ and the helper's module path was crate. It now falls through to the compiler's root like a custom target does. Test: custom_test_root_helper_module.
  • R41-B2-01 (medium) the source container's #[serde(default = "fn")] was carried into the DTO's default helper without the serde-path readability check, so a private fn of the source module was E0603 in the emitted DTO. Checked when the helper is emitted (buildable DTOs). Tests: private_container_default_fn_is_refused_from_another_module, ..._is_ignored_when_the_dto_is_not_built.
  • R41-B2-02 (medium, carry-over 2 / R41-SM3-01) inline relation DTO fields (HasMany picked, circular HasOne/BelongsTo) kept re-rooted serde function paths with no readability check. The inline type now records the first unreadable path and the caller refuses it with the same spanned error. Tests: private_serde_default_of_a_picked_has_many_item_is_refused, private_serde_default_of_a_circular_inline_type_is_refused.
  • R41-B2-04 (low) serde(transparent) was refused for a multipart DTO that never carries it. Test: a new multipart_carries_no_transparent case plus transparent_source_is_not_refused_for_a_multipart_dto.
  • R41-SM3-02 (medium) one-name types resolved through a use import or a glob were emitted as crate:: paths without path_readable_from, so a pub(super) enum reached through use super::memo::MemoStatus; was E0603 instead of the spanned error. Tests: pub_super_enum_reached_through_an_import_is_refused, ..._through_a_glob_is_refused.
  • R41-SM4-01 (low, same class) the locals branch checked only the item's own visibility, not the modules on its path (pub enum in a private mod user;); an import of an item of a private module was also unchecked. Both now use the path() rule (refuse_unreadable). Tests: pub_enum_of_a_private_module_reached_through_an_import_is_refused, pub_local_of_a_private_module_is_refused.
  • R41-SM3-03 (low) an empty component name (schema_type!(.., name = ""), #[schema(name = "")]) was accepted and registered as the "" key. Both paths now refuse it with a spanned error. Tests: empty_schema_type_name_is_refused, empty_schema_name_is_compile_error.
  • R41-SM0-L1 (low, IDE-only) the round-40 generated-record gate in schema_impl/stale.rs scanned the whole file for a variant (Scope::Module), so a same-named schema_type! in a sibling mod on the same line kept a deleted variant alive. The invocation lines are now read from the variant's own module (module_own_items), and the record pruning uses the same scope. Test: sibling_module_invocation_on_the_same_line_does_not_keep_a_variant.

type_utils.rs (985 lines before) moved get_type_default and its ecosystem-name table into type_utils/type_default.rs (re-exported, so no caller changes) to stay under the 1000-line cap.

Refuted

  • R41-B2-03 (low, schema_type! DTO garde derive names ::garde): not changed. The DTO's #[derive(::garde::Validate)] exists only for source fields with a #[garde(..)] attribute. The garde helper attribute is declared only by a garde::Validate derive, so the source struct already has to name the user's garde crate, and garde_derive 0.23 emits absolute ::garde::... paths (garde_derive-0.23.0/src/emit.rs:35,42,146,407,428). A ::vespera::__validation::garde derive would still emit ::garde inside its output, so the DTO is no more dependent on the user's garde than the source already is. Rules coming from #[schema(..)] constraints go through garde_emit and never touch the DTO's derive. No test added for this.

Notes

  • openapi.json of examples/axum-example is not affected: no fix changes the output of a valid input (all changes refuse or prune invalid or unreadable cases).
  • The changepack file .changepacks/changepack_log_schema_round41.json lists all seven packages at Patch.

🤖 Generated with Claude Code

…(round 41)

schema_type! refuses a private item at the call site with the spanned
"is private to" error instead of letting rustc report E0603 in the DTO:
the source container's serde default fn, a related model's serde paths in
an inline relation type (HasMany picked and circular), and a one-name type
reached through an import, a glob or a private module of its source.

A serde(transparent) source no longer refuses a multipart DTO, which never
carries the attribute. An empty schema name is a spanned compile error
(schema_type! and #[schema(name = "")]).

A call site under a custom test/example/bench root whose named root is
absent is rooted at the compiler's root, so crate:: resolves from that
root and not from src/. The stale-variant check reads a schema_type!
invocation from its own inline module, not the whole file.

get_type_default moves to type_utils/type_default.rs (re-exported) to keep
type_utils.rs under the 1000-line cap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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