diff --git a/lib/nimble_options/docs.ex b/lib/nimble_options/docs.ex index e3be50a..7febe50 100644 --- a/lib/nimble_options/docs.ex +++ b/lib/nimble_options/docs.ex @@ -45,6 +45,7 @@ defmodule NimbleOptions.Docs do description = get_required_str(schema) + |> get_deprecated_str(schema) |> get_doc_str(schema) |> get_default_str(schema) |> case do @@ -76,6 +77,13 @@ defmodule NimbleOptions.Docs do if schema[:required], do: "Required." end + defp get_deprecated_str(prev_str, schema) do + space_concat( + prev_str, + schema[:deprecated] && "*This option is deprecated. #{String.trim(schema[:deprecated])}*" + ) + end + defp get_doc_str(prev_str, schema) do space_concat(prev_str, schema[:doc] && String.trim(schema[:doc])) end diff --git a/test/nimble_options/docs_test.exs b/test/nimble_options/docs_test.exs index 013869a..6747aae 100644 --- a/test/nimble_options/docs_test.exs +++ b/test/nimble_options/docs_test.exs @@ -236,6 +236,22 @@ defmodule NimbleOptions.DocsTest do assert NimbleOptions.docs(schema) == docs end + test "generates deprecated information" do + schema = [ + old: [type: :atom, doc: "Old option.", deprecated: "Use `:new` instead."], + new: [type: :string, doc: "New option."] + ] + + docs = """ + * `:old` (`t:atom/0`) - *This option is deprecated. Use `:new` instead.* Old option. + + * `:new` (`t:String.t/0`) - New option. + + """ + + assert NimbleOptions.docs(schema) == docs + end + test "the option doesn't appear in the documentation when the :doc option is false" do schema = [ name: [type: :atom, doc: "An atom."],