Skip to content

Commit 600a243

Browse files
stolenDanil Zagoskin
authored andcommitted
reduce test dependencies
1 parent e95b2bf commit 600a243

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

rebar.config_

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
{profiles, [
66
{dev, [
77
{deps, [
8-
jsx,
9-
yamerl,
108
{cowboy, "2.12.0"},
11-
{lhttpc, {git, "https://github.com/erlyvideo/lhttpc.git", {branch, "master"}}},
129
redbug
1310
]},
1411
{ct_opts, [{ct_hooks, [cth_surefire]}]}

src/openapi_client.erl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,15 @@ call(#{schema := Schema, uri := URI} = State, OperationId, Args0, Opts) when is_
6262
_ -> RequestBody
6363
end]),
6464
Timeout = proplists:get_value(timeout, Opts, 50000),
65-
Result = case lhttpc:request(RequestURL, Method, RequestHeaders, RequestBody, Timeout) of
66-
{ok, {{Code0,_},ResponseHeaders0,Bin0}} ->
65+
Request = case Method of
66+
get ->
67+
{RequestURL, RequestHeaders};
68+
_ ->
69+
ContentType = proplists:get_value("Content-Type", RequestHeaders, "text/plain"),
70+
{RequestURL, RequestHeaders, ContentType, RequestBody}
71+
end,
72+
Result = case httpc:request(Method, Request, [{timeout, Timeout}], [{body_format, binary}]) of
73+
{ok, {{_, Code0, _}, ResponseHeaders0, Bin0}} ->
6774
{ok, Code0, [{string:to_lower(K),V} || {K,V} <- ResponseHeaders0], Bin0};
6875
{error, E0} ->
6976
{error, E0}

test/openapi_handler_SUITE.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ start_http(Routes, ApiName) ->
4242

4343

4444
init_per_suite(Config) ->
45+
inets:start(),
4546
{ok, _} = application:ensure_all_started(cowboy),
46-
{ok, _} = application:ensure_all_started(lhttpc),
4747

4848
PetstorePath = filename:join(code:lib_dir(openapi_handler),"test/redocly-petstore.json"),
4949
TestSchemaPath = filename:join(code:lib_dir(openapi_handler),"test/test_schema.json"),
@@ -183,9 +183,9 @@ json_body_parameters(_) ->
183183
broken_json(_) ->
184184
Port = integer_to_list(ranch:get_port(petstore_api_server)),
185185
JSON = "{\"key\":\"value\"]}",
186-
{ok, {{400,_},Headers,Body}} = lhttpc:request("http://127.0.0.1:"++Port++"/test/yml/store/order", post,
187-
[{"Content-Type", "application/json"}], JSON, 5000),
188-
"application/json" = proplists:get_value("Content-Type", Headers),
186+
Request = {"http://127.0.0.1:"++Port++"/test/yml/store/order", [], "application/json", JSON},
187+
{ok, {{_, 400, _}, Headers, Body}} = httpc:request(post, Request, [{timeout, 5000}], [{body_format, binary}]),
188+
"application/json" = proplists:get_value("content-type", Headers),
189189
#{<<"error">> := <<"broken_json">>} = openapi_json:decode(Body),
190190
ok.
191191

0 commit comments

Comments
 (0)