scottming

scottming

A new validation library, looking for suggestions

Hello everyone, I have written a library about validation joi, which I think is suitable for use in CQRS projects where there are many data structures defined. I’m about to release version 0.2.0, currently in the develop branch. Do you have any suggestions for the API, or for the code, or for testing

Most Liked

stefanchrobot

stefanchrobot

When I looked at the example on GitHub:

iex> schema = %{a: [:integer]}
%{a: [:integer]}
iex> data1 = %{a: 1}
%{a: 1}
iex> Joi.validate(data1, schema)
{:ok, %{a: 1}}
iex> data2 = %{a: <<123>>}
iex> Joi.validate(data2, schema)
{:error,
[
  %Joi.Error{
    context: %{key: :a, value: "{"},
    message: "a must be a integer",
    path: [:a],
    type: "integer.base"
  }
]}

the same - or at least similar - thing can be achieved using schemaless changesets with Ecto:

iex> types = %{a: :integer}
iex> data = %{a: "hello"}
iex> changeset = {%{}, types} |> Ecto.Changeset.cast(data, Map.keys(types))
#Ecto.Changeset<
  action: nil,
  changes: %{},
  errors: [a: {"is invalid", [type: :integer, validation: :cast]}],
  data: %{},
  valid?: false
>

So the question is whether the functionality you’re building can be written as an extension to Ecto, which is I think is very commonly used. In one of the previous projects, I had a microservice that didn’t have it’s own storage, but I still used Ecto to validate the schema of the incoming requests.

stefanchrobot

stefanchrobot

Hi, would it be possible to build this library on top of Ecto’s schemaless changesets?

Where Next?

Popular in Discussions Top

AstonJ
Are there any Elixir or Erlang libraries that help with this? I’ve been thinking how streaming services like twitch have exploded recentl...
New
mbenatti
Following https://github.com/tbrand/which_is_the_fastest |&gt; https://raw.githubusercontent.com/tbrand/which_is_the_fastest/master/imgs...
New
AstonJ
If a newbie asked you about Phoenix Contexts, how would you explain the basics to them? Feel free to be as concise or in-depth as you li...
New
Crowdhailer
I’ve been hearing much about the new formatter and it’s something I have been keen to try. I find examples buy far the most illuminating...
248 19814 150
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40165 209
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54260 488
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New

We're in Beta

About us Mission Statement