Skip to content

fix(assign): preserve input coercion when merging structs#1300

Open
xianjianlf2 wants to merge 1 commit into
ianstormtaylor:mainfrom
xianjianlf2:fix/assign-coercion-791
Open

fix(assign): preserve input coercion when merging structs#1300
xianjianlf2 wants to merge 1 commit into
ianstormtaylor:mainfrom
xianjianlf2:fix/assign-coercion-791

Conversation

@xianjianlf2

Copy link
Copy Markdown

Problem

assign rebuilt the merged struct via object()/type() from the combined schemas, discarding any top-level coercer the input structs carried (e.g. defaulted, trimmed). As a result, wrapping a struct with defaulted and then passing it to assign silently dropped the default values during create.

Fix

Compose the inputs' coercers into the merged struct's coercer. The merged struct's own coercer still runs last so masking is applied once against the combined schema, and the inputs run with masking disabled so they don't strip keys owned by the other structs being assigned.

Testing

Added test/validation/assign/coerce-defaulted.ts, which exercises create on an assign-merged struct wrapped with defaulted and asserts the default values are preserved.

Closes #791

`assign` rebuilt the merged struct via `object()`/`type()` from the
combined schemas, discarding any top-level coercer the input structs
carried (e.g. `defaulted`, `trimmed`). As a result, wrapping a struct
with `defaulted` and then passing it to `assign` silently dropped the
default values during `create`.

Compose the inputs' coercers into the merged struct's coercer. The
merged struct's own coercer still runs last so masking is applied once
against the combined schema, and the inputs run with masking disabled so
they don't strip keys owned by the other structs being assigned.

Closes ianstormtaylor#791
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.

assign breaks coercion

1 participant