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.

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/bench/reports/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

Where Next?

Popular in Announcing Top

danschultzer
In short Plug n’ play OAuth 2.0 provider library. Just set up a resource owner schema with Ecto (your user schema), install the dependen...
New
martinthenth
Hello everybody :wave: Recently, some of my colleagues talked about database ids and uuids and their problems, and I remembered the pain...
New
ostinelli
Let’s write a database! Well not really, but I think it’s a little sad that there doesn’t seem to be a simple in-memory distributed KV da...
New
tfwright
After working on it for a couple of months and using it in production for most of that time, today I’ve released LiveAdmin, a LiveView ba...
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
kelvinst
Hey everyone! Well, we made this lib a while ago and now we decided to finally go out and public with it! It’s a tool for creating and m...
New
wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
Azolo
Hey everyone, I just released WebSockex which is a Elixir WebSocket client. WebSockex strives to work as a OTP special process, be RFC6...
New
Flo0807
Hello everyone! I am excited to share our heart project Backpex with you. After building several Phoenix applications, we realized that...
New
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

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29377 241
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New

We're in Beta

About us Mission Statement