···168168 end
169169170170 def post(client, %{__struct__: module} = procedure, opts) do
171171+ has_raw_input? =
172172+ if raw_input = procedure.raw_input do
173173+ opts = Keyword.put(opts, :body, raw_input)
174174+175175+ if Code.ensure_loaded?(module) and function_exported?(module, :content_type, 0) do
176176+ headers = Keyword.get(opts, :headers, [])
177177+ has_content_type? = Enum.any?(headers, fn {k, _} -> String.downcase(k) == "content-type" end)
178178+179179+ unless has_content_type? do
180180+ raise """
181181+ content-type header is required when sending raw_input for #{module.id()}.
182182+ Expected: #{module.content_type()}
183183+ """
184184+ end
185185+ end
186186+187187+ true
188188+ else
189189+ false
190190+ end
191191+171192 opts =
172172- opts
173173- |> put_params(procedure)
174174- |> put_body(procedure)
193193+ if has_raw_input? do
194194+ put_params(opts, procedure)
195195+ else
196196+ opts
197197+ |> put_params(procedure)
198198+ |> put_body(procedure)
199199+ end
175200176201 output_struct = Module.concat(module, Output)
177202 output_exists = Code.ensure_loaded?(output_struct)
+4-1
test/atex/lexicon_test.exs
···196196 end
197197198198 test "error structs have from_json/1" do
199199+ Code.ensure_loaded!(Lexicon.Test.DoThing.Errors.SomethingBroke)
200200+ Code.ensure_loaded!(Lexicon.Test.DoThing.Errors.DoesNotCompute)
199201 assert function_exported?(Lexicon.Test.DoThing.Errors.SomethingBroke, :from_json, 1)
200202 assert function_exported?(Lexicon.Test.DoThing.Errors.DoesNotCompute, :from_json, 1)
201203 end
···232234 end
233235234236 test "root module exports coerce_error/1" do
237237+ Code.ensure_loaded!(Lexicon.Test.DoThing)
235238 assert function_exported?(Lexicon.Test.DoThing, :coerce_error, 1)
236239 end
237240···269272 end
270273271274 test "error structs have from_json/1" do
272272- Code.ensure_loaded!(Lexicon.Test.DoOtherThing)
275275+ Code.ensure_loaded!(Lexicon.Test.DoOtherThing.Errors.ValidationFailed)
273276 assert function_exported?(Lexicon.Test.DoOtherThing.Errors.ValidationFailed, :from_json, 1)
274277 end
275278