Skip to content

fix: pass proper options to object field casting - #2368

Open
waw666waw666 wants to merge 1 commit into
jquense:masterfrom
waw666waw666:fix/object-field-cast-options
Open

waw666waw666 wants to merge 1 commit into
jquense:masterfrom
waw666waw666:fix/object-field-cast-options

Conversation

@waw666waw666

Copy link
Copy Markdown

Array and tuple casting have passed per-element options (value, originalValue, parent, index, path) to nested casts since #2305, and transforms can read them from their fourth options argument since #2306. Object casting missed the same treatment: ObjectSchema._cast only updated path (and parent) on the options it passes to each field's cast.

As a result, a transform or default function on an object field saw:

  • options.value / options.originalValue as undefined on a plain cast(),
  • the whole parent object's values during validate(), or when the object was nested inside an array/tuple element.

This sets value, originalValue, and key per field in ObjectSchema._cast, mirroring what ArraySchema and TupleSchema pass per element (key matches what asNestedTest already sets for object fields on the validation side).

Tests: two new cases in test/object.ts mirroring the array coverage from #2305/#2306 — one for cast(), one for validate(). Full suite: 871 passed / 2 skipped, up from 867 passed / 2 skipped on master, no other changes.

ObjectSchema._cast did not set value, originalValue, or key on the
options passed to each field's cast, unlike ArraySchema and
TupleSchema which have passed per-element options since jquense#2305.
Transforms (which receive options as their fourth argument since
jquense#2306) and default functions in object fields therefore saw an
undefined value/originalValue on a plain cast, or the whole parent
object's values when validating or nested inside an array.
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