From 8ab3de1114b970a5b129c926d1399422575c7a86 Mon Sep 17 00:00:00 2001 From: Dave Menninger Date: Tue, 19 Oct 2021 21:10:34 -0400 Subject: [PATCH 1/3] add typespec for list of options --- lib/poison.ex | 2 +- lib/poison/decoder.ex | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/poison.ex b/lib/poison.ex index c2ac4bcf..51043c56 100644 --- a/lib/poison.ex +++ b/lib/poison.ex @@ -75,7 +75,7 @@ defmodule Poison do Parser.parse!(value, %{}) end - @spec decode!(iodata, Decoder.options()) :: Decoder.t() | no_return + @spec decode!(iodata, Decoder.options() | [Decoder.option()]) :: Decoder.t() | no_return def decode!(value, options) when is_list(options) do decode!(value, Map.new(options)) end diff --git a/lib/poison/decoder.ex b/lib/poison/decoder.ex index caab69df..8efcd863 100644 --- a/lib/poison/decoder.ex +++ b/lib/poison/decoder.ex @@ -108,6 +108,7 @@ defprotocol Poison.Decoder do @typep as :: map | struct | [as] + @type option :: {:keys, :atoms | :atoms!} | {:decimal, boolean} | {:as, as} @type options :: %{ optional(:keys) => :atoms | :atoms!, optional(:decimal) => boolean, From 42b10891ff5642598f7a3c336ae7ec73969258e5 Mon Sep 17 00:00:00 2001 From: Dave Menninger Date: Tue, 19 Oct 2021 21:18:23 -0400 Subject: [PATCH 2/3] move the list option into the Protocol --- lib/poison.ex | 2 +- lib/poison/decoder.ex | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/poison.ex b/lib/poison.ex index 51043c56..c2ac4bcf 100644 --- a/lib/poison.ex +++ b/lib/poison.ex @@ -75,7 +75,7 @@ defmodule Poison do Parser.parse!(value, %{}) end - @spec decode!(iodata, Decoder.options() | [Decoder.option()]) :: Decoder.t() | no_return + @spec decode!(iodata, Decoder.options()) :: Decoder.t() | no_return def decode!(value, options) when is_list(options) do decode!(value, Map.new(options)) end diff --git a/lib/poison/decoder.ex b/lib/poison/decoder.ex index 8efcd863..4831dac7 100644 --- a/lib/poison/decoder.ex +++ b/lib/poison/decoder.ex @@ -109,11 +109,13 @@ defprotocol Poison.Decoder do @typep as :: map | struct | [as] @type option :: {:keys, :atoms | :atoms!} | {:decimal, boolean} | {:as, as} - @type options :: %{ - optional(:keys) => :atoms | :atoms!, - optional(:decimal) => boolean, - optional(:as) => as - } + @type options :: + %{ + optional(:keys) => :atoms | :atoms!, + optional(:decimal) => boolean, + optional(:as) => as + } + | [option] @spec decode(t, options) :: any def decode(value, options) From a9e23880fb33bd5321968b2006de9b104f253efa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dave=20Menninger=20=E2=9A=A1?= Date: Tue, 19 Oct 2021 21:39:20 -0400 Subject: [PATCH 3/3] change option type to typep Co-authored-by: RudolfMan --- lib/poison/decoder.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/poison/decoder.ex b/lib/poison/decoder.ex index 4831dac7..8926fba2 100644 --- a/lib/poison/decoder.ex +++ b/lib/poison/decoder.ex @@ -108,7 +108,7 @@ defprotocol Poison.Decoder do @typep as :: map | struct | [as] - @type option :: {:keys, :atoms | :atoms!} | {:decimal, boolean} | {:as, as} + @typep option :: {:keys, :atoms | :atoms!} | {:decimal, boolean} | {:as, as} @type options :: %{ optional(:keys) => :atoms | :atoms!,