Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for string maps #5

Merged
merged 3 commits into from
Sep 12, 2023
Merged

Support for string maps #5

merged 3 commits into from
Sep 12, 2023

Conversation

solnic
Copy link
Owner

@solnic solnic commented Sep 12, 2023

This adds atomize: true | false option to schema DSL which can be used to have string-based maps turned into atom-based maps:

defmodule TestContract do
  use Drops.Contract

  schema(atomize: true) do
    %{
      required(:user) => %{
        required(:name) => type(:string, [:filled?]),
        required(:age) => type(:integer),
        required(:address) => %{
          required(:city) => type(:string, [:filled?]),
          required(:street) => type(:string, [:filled?]),
          required(:zipcode) => type(:string, [:filled?])
        }
      }
    }
  end
end

TestContract.conform(%{
 "user" => %{
   "name" => "John",
   "age" => 21,
   "address" => %{
     "city" => "New York",
     "street" => "Central Park",
     "zipcode" => "10001"
   }
 }
})
# {:ok,
#  %{
#    user: %{
#      name: "John",
#      address: %{city: "New York", street: "Central Park", zipcode: "10001"},
#      age: 21
#    }
#  }}

@solnic solnic changed the title Support-for-string-maps Support for string maps Sep 12, 2023
@solnic solnic force-pushed the support-for-string-maps branch 2 times, most recently from a394c1a to 25307da Compare September 12, 2023 11:25
@solnic solnic merged commit f6e3c14 into main Sep 12, 2023
1 check passed
@solnic solnic deleted the support-for-string-maps branch September 12, 2023 11:29
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