///|
/// Make a field optional: absent keys pass; explicit null is validated normally.
/// Rules chained after `.optional()` are pushed through to the inner schema
/// via `append_rule`, so `string().optional().min(3)` works correctly.
pub fn Schema::optional(self : Schema) -> Schema {
{
id: new_schema_id(),
schema_type: OptionalType(self),
rules: [],
description: self.description,
required_error: self.required_error,
invalid_type_error: self.invalid_type_error,
name: self.name,
brand: self.brand,
}
}
///|
pub fn Schema::parse_optional(
self : Schema,
inner : Schema,
json : Json,
path_stack : Array[String],
) -> RawSchemaResult {
parse_inner(
{ ..self, id: new_schema_id(), schema_type: OptionalType(inner), },
json,
path_stack,
)
}