Skip to content

.passthrough()

Returns a copy of the schema that copies keys it does not declare into the output, without validating them. Non-string keys are converted with toString(). The default is to strip unknown keys. Only SchemaValidator has this method.

SchemaValidator<O> passthrough()

Code none. Default message: Adds no validation.

The generator emits .passthrough() when it cannot name every key the serializer may read: a field with @JsonKey(readValue:), a private field with @JsonKey(includeFromJson: true), or a @MappableClass(hook:).

final user = l.schema({'name': l.string().required()}).passthrough();
l.schema({'name': l.string().required()}).passthrough().validate(input)+1-1
  1. valid: {'name': 'Ada', 'role': 'admin'}
  2. invalid: {'role': 'admin'}name: name is required

Compare the three behaviours on the same input:

strip (default)
ValidationSuccess(data: {name: Ada})
passthrough
ValidationSuccess(data: {name: Ada, role: admin})
strict
ValidationFailure(errors: {role: [role is not an allowed key]})
role is not an allowed key