Exonerate
Exonerate copied to clipboard
allow reading gzip compressed schemas
thanks again for Exonerate! I mentioned the issue of working with compressed (gzipped) schemas at CodeBEAM America, and Isaac suggested I open an issue.
I have a bunch of schemas that are wordy but compress nicely (5-6x smaller). I currently end up generating the validators like this (code and names have been changed and simplified to protect the innocent).
defmodule CompressedReaderHelper do
defmacro __using__(_env) do
res = File.stream!(Path.join(__DIR__, "schema.json.gz"), [:read, :compressed]) |> Enum.into("")
quote do
require Exonerate
Exonerate.function_from_string( :def, :function_name, unquote(res))
end
end
end
(I actually wrote it this way so I could use CompressedReaderHelper
and pass some extra parameters to change the schema file path for different modules, but that's not pertinent to the compression).
I think it would be pretty straightforward to conditionally pass the :compressed
option and replace File.read!
with File.stream!
in function_from_file
https://github.com/E-xyza/Exonerate/blob/1a639563a64ee1bf2b3ad4417871c3d3034c7077/lib/exonerate.ex#L427
but I am not experienced enough in Elixir to know if it's stylistically a poor choice to push this into the opts
parameter that's already there but used for an entirely different set of options.