ityonemo

ityonemo

Exonerate - JSONschema validator for elixir

This one has been sitting in a dark corner of my github for several years, I started it before I knew how to publish to hex.pm but I found a need for it at my current job, so I rewrote chunks of it over the past couple of weeks and brought it up to date with the most current version of JSONSchema. I’ve used the validator (in its old form, as a github pull) in both of my previous elixir jobs, but now that I can say I’m “proud of it” it have put it on hex.pm for everyone to use.

This library injects JSONSchema validation code into your module. It’s inspired by EEx and NimbleParsec. The library is validated against the official JSONSchema test set.

https://hexdocs.pm/exonerate/Exonerate.html

Most Liked

ityonemo

ityonemo

updated to version 0.2.0, which now supports (and is tested against) most of draft 4, 6, 7, 2019, and 2020, also produces better error messages for anyOf, and oneOf filters, as well as “ref traces” for if your schema validation jumps around several references.

ityonemo

ityonemo

updated exonerate to version 0.3.0, almost complete support for JSONSchema draft 2020-09.

A few highlights of changes:

  • completely changed macro architecture
  • respects ids as URIs, has correct id resolution
  • able to obtain remoteRfs
  • optional RFC/standards-correct parsing of all "standardized format"s as set forth in the JSONSchema standard.

Benchmarks (generally ~3-5x faster than ExJsonSchema/JsonXema) are shown here: Exonerate/lib-bench.md at master · E-xyza/Exonerate · GitHub

ityonemo

ityonemo

I should probably give a concrete example. Supposing the schemas stored in the database are yours and not users’ you could do this:

defmodule MyApp.Validators do
  def make_from_db do
    Db.Schemas.get_all()
    |> Enum.map(&to_module/1)
    |> Enum.each(&Code.compile_quoted/1)
    :ok
  end
  defp to_module(schema) do
    module_name = :"validator_#{schema.name}"
    module_schema = Jason.encode!(schema.json) # assuming it's JSONB column
    common_options = [...]
    quote do
      defmodule unquote(module_name) do
        require Exonerate
        Exonerate.function_from_string(:def, :validate, unquote(module_schema), unquote(common_options))
      end
    end
  end
end
ityonemo

ityonemo

updated to version 0.2.1, a minor upgrade which provides the required: "/jsonpointer/to/required/parameter" optional error content if a required filter in your JSONSchema fails.

ityonemo

ityonemo

updated exonerate to version 0.3.2.

A few highlights of changes:

  • faster array items handling
  • allows registering resources for repeated use in functions
  • fixed nested not in unevaluatedItems
  • dump: true now generates code that you can copy-paste into a .ex or .exs file for correct compilation

Where Next?

Popular in Libraries Top

marcuslankenau
I feel kind of stuck with the absence of a proper xml library for Elixir. Currently I use SweetXML which was ok for me more or less to pa...
New
treble37
Just looking for a little feedback on a tiny helper library I built - Sometimes I find the need to convert maps with atom keys to maps...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
mbuhot
Leverage Open Api 3.0 (Swagger) to document, test, validate and explore your Plug and Phoenix APIs. Generate and serve a JSON Open API ...
New
mcrumm
If you would like to migrate away from node/npm/webpack while still using sass, the dart_sass package provides a installer and runner for...
New
michalmuskala
Hello everybody. I have just released Jason - a new JSON library. You might be wondering, why do we need a new library? The primary foc...
New
wfgilman
I’ve cleaned up and open sourced three financial libraries I was using for my company. They are bindings for the APIs of these three comp...
New
tmbb
PhoenixWS - Websockets over Phoenix Channels Source code on Github here: https://github.com/tmbb/phoenix_ws Phoenix channels are a great...
New
gabrielpoca
Hello everyone! I want to share with you something that I’m really proud of: https://stillstatic.io/ Still is a static site builder for...
New
mtrudel
Bandit is an HTTP server for Plug and WebSock apps. Bandit is written entirely in Elixir and is built atop Thousand Island. It can serve...
New

Other popular topics Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
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
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New

Sub Categories:

We're in Beta

About us Mission Statement