Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic committed Oct 13, 2023
1 parent 8dfc323 commit 255c1bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ UserContract.conform(%{text: "HELLO"})

### Atomized maps

You can define a schema that will atomize the input map using `atomize: true` option:
You can define a schema that will atomize the input map using `atomize: true` option. Only keys that you specified will be atomized, any unexpected key will be ignored. Here's an example:

```elixir
defmodule UserContract do
Expand All @@ -264,6 +264,8 @@ defmodule UserContract do
end

UserContract.conform(%{
"unexpected" => "value",
"this" => "should not be here",
"name" => "Jane",
"age" => 21,
"tags" => [
Expand All @@ -272,6 +274,13 @@ UserContract.conform(%{
%{"name" => "blue"}
]
})
# {:ok,
# %{
# name: "Jane",
# age: 21,
# tags: [%{name: "red"}, %{name: "green"}, %{name: "blue"}]
# }}

# {:ok,
# %{
# name: "Jane",
Expand Down
2 changes: 2 additions & 0 deletions examples/readme/schemas-07.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ defmodule UserContract do
end

UserContract.conform(%{
"unexpected" => "value",
"this" => "should not be here",
"name" => "Jane",
"age" => 21,
"tags" => [
Expand Down

0 comments on commit 255c1bd

Please sign in to comment.