Skip to content

Commit

Permalink
Merge pull request #457 from seancribbs/hide-or-document-option-type
Browse files Browse the repository at this point in the history
Add documentation for `options/0` type and exclude when `docs: false`
  • Loading branch information
teamon authored Mar 24, 2021
2 parents 9c1c1ff + c8fec19 commit a66651f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/tesla/builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ defmodule Tesla.Builder do
Module.register_attribute(__MODULE__, :__middleware__, accumulate: true)
Module.register_attribute(__MODULE__, :__adapter__, [])

if unquote(docs) do
@typedoc "Options that may be passed to a request function. See `request/2` for detailed descriptions."
else
@typedoc false
end

@type option ::
{:method, Tesla.Env.method()}
| {:url, Tesla.Env.url()}
Expand Down
10 changes: 9 additions & 1 deletion test/tesla/builder_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,13 @@ defmodule Tesla.BuilderTest do
Enum.find(docs, &match?({{:function, :get, 3}, _, _, _, _}, &1))

assert doc != :hidden

assert {_, _, _, doc, _} = Enum.find(docs, &match?({{:type, :option, 0}, _, _, _, _}, &1))

assert doc != :hidden
end

test "do not generate docs for HTTP methods when docs: false" do
test "do not generate docs for HTTP methods or types when docs: false" do
{:docs_v1, _, :elixir, _, _, _, docs} = Code.fetch_docs(TeslaDocsTest.NoDocs)

assert {_, _, _, doc, _} =
Expand All @@ -170,6 +174,10 @@ defmodule Tesla.BuilderTest do
Enum.find(docs, &match?({{:function, :custom, 1}, _, _, _, _}, &1))

assert doc["en"] =~ ~r/something/

assert {_, _, _, doc, _} = Enum.find(docs, &match?({{:type, :option, 0}, _, _, _, _}, &1))

assert doc == :hidden
end
else
# Use Code.get_docs/2 for elixir <1.7
Expand Down

0 comments on commit a66651f

Please sign in to comment.