Accessing typespecs during compile time

Hi!

I’m trying to build a small library to transform JSON data (e.g raw, string-based maps) into structs and such based on a module’s typespec (draft implementation can be found here: https://gist.github.com/frekw/85e0a12b60bd77bc43a1f6fc4e08a9d1).

However, since I need to do a bit of parsing of the typespecs in order to accomplish this, I though I’d move it to compile time. But it seems I can’t access the typespec AST until the bytecode has been generated, which becomes a bit of a catch 22.

Is there anyway around this?

It looks like you are doing your generation from another module? If so then just require that other module and mix will compile it before yours is compiled. :slight_smile:

I managed to get it sort of working by using @after_compile, but went with another solution in the end due to some other limitations.

The result can be found here: https://github.com/soundtrackyourbrand/forma