Skip to content

Conversation

@jdenen
Copy link

@jdenen jdenen commented Aug 19, 2025

Current State

@ksherman doesn't like that he can't unset a field by explicitly setting it to null through APIs that define parameters with defparams. This happens because the library strips all null-value fields, regardless of how they're null.

With this PR

This PR introduces nullable field types (e.g. :string_nullable) that allow you to explicitly set a value to null and see that null value after validating params. Fields that are not explicitly set will continue to be ignored.

Example

defparams foo(%{
  one: :integer, 
  two: :integer_nullable
})

# explicit nil values for *_nullable type fields make it through
%{one: 1, two: nil} |> foo() |> Params.to_map()
#=> %{one: 1, two: nil}

# they don't make it through unless explicitly set to nil
%{one: 1} |> foo() |> Params.to_map()
#=> %{one: 1}

# non *_nullable type fields continue to ignore explicit nulls
%{one: nil, two: 2} |> foo() |> Params.to_map()
#=> %{two: 2}

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.

2 participants