dashbitco / nimble_options

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

Protocol.UndefinedError when documenting a wildcard key keyword list #60

Closed the-mikedavis closed 3 years ago

the-mikedavis commented 3 years ago

:wave: hello!

I have a minimal example repo here: https://github.com/the-mikedavis/nimble_example, with the schema definition here and tests that exhibit the behaviour here

Given a schema like so (similar to a snippet in the documentation):

[
  foo: [
    type: :keyword_list,
    keys: [*: [type: :atom]]
  ]
]

we can properly validate a set of input options:

iex(1)> NimbleOptions.validate([foo: [bar: :baz]], schema())
{:ok, [foo: [bar: :baz]]}

but trying to document this schema will fail:

iex(2)> NimbleOptions.docs(schema())                        
** (Protocol.UndefinedError) protocol Enumerable not implemented for nil of type Atom. This protocol is implemented for the following type(s): Map, Stream, Range, Date.Range, List, GenEvent.Stream, Function, File.Stream, HashDict, MapSet, IO.Stream, HashSet
    (elixir 1.11.0) lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir 1.11.0) lib/enum.ex:141: Enumerable.reduce/3
    (elixir 1.11.0) lib/enum.ex:3461: Enum.reduce/3
    (nimble_options 0.3.5) lib/nimble_options/docs.ex:61: NimbleOptions.Docs.option_doc/2
    (elixir 1.11.0) lib/enum.ex:2181: Enum."-reduce/3-lists^foldl/2-0-"/3
    (nimble_options 0.3.5) lib/nimble_options/docs.ex:6: NimbleOptions.Docs.generate/2

I'm using these versions

tool version
elixir 1.11.0
erlang 23.1
nimble_options 0.3.5
OS ubuntu 16.04

thanks!

msaraiva commented 3 years ago

@the-mikedavis thanks for reporting this issue!