dashbitco / nimble_options

A tiny library for validating and documenting high-level options. 💽
Apache License 2.0
507 stars 38 forks source link

Type spec generation #32

Closed michallepicki closed 4 years ago

michallepicki commented 4 years ago

I took a look at whether it would be possible and I think it is. Macros don't get expanded inside @type for some reason so I didn't get this working:

require NimbleOptions.Type
@type opts :: NimbleOptions.Type.generate(schema)

But I think this could work:

require NimbleOptions.Type
NimbleOptions.Type.generate(opts, schema)

Is there a plan to add ability to generate a @type spec from the schema? Would that be a welcome addition in this project? I could publish a separate package instead

josevalim commented 4 years ago

Currently no plans. Thanks for checking though!

michallepicki commented 4 years ago

Can I use nimble_options in the package name? Something like nimble_options_type

josevalim commented 4 years ago

Sure!

michallepicki commented 4 years ago

For anyone interested, I have a WIP project, tests show what it generates. Overall seems fine, I am getting the usual fast-enough feedback cycle from dialyzer for catching option keys typos etc. Because NimbleOptions works on keyword lists (and not maps), Dialyzer cannot enforce requiredness per field.

I may add some escape hatch option to pass custom type definitions, it could also allow to support recursive options I think.

edit: fixed link to point to tests