Spectral - Type-driven JSON encoding/decoding, validation, and OpenAPI generation

Hi, good library, I’ve read the code and it has a lot of very strange approaches and things

  • It uses a spectra erlang library, which uses caching in persistent_term for type-specs. But why do you need to introduce lazy-loading of the type-information (which would certainly introduce random spikes in runtime performance), when you can just create an encoder/decoder for a specific type during compilation? Just introduce a macro.

  • Library says

    Spectral provides type-safe data serialization and deserialization for Elixir types. Currently the focus is on JSON.

    but it also provides features of OpenAPI spec generations, including endpoint documentation, etc. So its not JSON codec generation, it is a code-first OpenAPI integration.

  • If you’re doing OpenAPI, there is a problem that OpenAPI JSON schema is not “compatible” with the elixir type specs. I mean that JSON Schema can define types which can’t be expressed in elixir type specs. And I don’t see any way to integrate JSON Schema definitions into elixir type specs.

  • It uses spectra, which encodes record tuples as maps and there is no option to specify codecs for generic tuples as far as I can see. I tried naive approach with custom codec for :erlang.tuple/0 type and it didn’t work.

  • It fails to work in iex, because it uses abstract_code chunk received with :code.get_object_code, which returns only for modules which are present in a code path. There must be an option to accept module binary

  • Code cache is not invalidated on recompilation, which would make development with this library a hell

I found some more issues, so feel free to contact me so I can perform a more detailed review (for a reasonable price of course)