ityonemo

ityonemo

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.

Showing Posts 1 to 10

ityonemo

ityonemo OP

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 OP

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 OP

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

egze

egze

Looks very cool. Do I get it correctly that the schema needs to exist at compile time? Any way to make it work with schemas coming from a database, for example?

ityonemo

ityonemo OP

It must exist at compile time. If you need dynamic schemas you’ll probably need JSONschema or ex_json_schema… Unless you have full control (not user input) in which case you can go nuts and make as many modules as you want at runtime

ityonemo

ityonemo OP

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
egze

egze

Thanks. That could work for my case.

ityonemo

ityonemo OP

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
tt67wq

tt67wq

Does this project have any differences and advantages compared to GitHub - jonasschmidt/ex_json_schema: An Elixir JSON Schema validator · GitHub?

ityonemo

ityonemo OP

It supports all of the JSONschema drafts up to 2020. ExJsonSchema only goes up to draft 7. Also it’s about 3x faster. May or may not be important, but it’s a runtime: false library so your release payload will be much smaller.

Where Next? Top

Trending in Announcing Top

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
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub. Docs are at OpenaiEx User Gu...
152 11030 135
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
fuelen
Hi all! I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas. You...
New
woylie
Phoenix components for pagination, sortable tables and filter forms with Flop and (optionally) Ecto. pagination cursor pagination sorta...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mudasobwa
I am seeing a lot of aplications of Argumentum ad Vericundiam in software discussions. They do link some piece of writing and point us to...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
sorenone
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews