From 6ba2fbda74fa1d803836f9cf7b2efeb0e5e1ae10 Mon Sep 17 00:00:00 2001 From: xinz Date: Tue, 14 Feb 2023 11:20:51 +0800 Subject: [PATCH] Add test for issue #19 --- lib/oasis/parser.ex | 2 -- test/integration_test.exs | 6 ++++++ test/support/gen/plug/pre_test_post_json.ex | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/oasis/parser.ex b/lib/oasis/parser.ex index 2ecd7a1..58abfe7 100644 --- a/lib/oasis/parser.ex +++ b/lib/oasis/parser.ex @@ -8,12 +8,10 @@ defmodule Oasis.Parser do def parse(%{"type" => "null"}, nil), do: nil def parse(%{"type" => "array"} = type, value) when is_list(value) do - # post request body as :urlencoded or :multipart do_parse_array(type, value) end def parse(%{"type" => "object"} = type, value) when is_map(value) do - # post request body as :urlencoded or :multipart do_parse_object(type, value) end diff --git a/test/integration_test.exs b/test/integration_test.exs index 97bcf25..1da96a8 100644 --- a/test/integration_test.exs +++ b/test/integration_test.exs @@ -498,6 +498,12 @@ defmodule Oasis.IntegrationTest do start_supervised!({Finch, name: TestFinch}) headers = [{"content-type", "application/json"}] + body = "[{\"id2\":1,\"name2\":\"hello\"}]" + + assert {:ok, response} = Finch.build(:post, "#{url}/test_post_json", headers, body) |> Finch.request(TestFinch) + assert response.status == 400 and + response.body == "Find body parameter `body_request` with error: Required properties id, name were not present." + body = "[{\"id\":1,\"name\":\"hello\"}]" assert {:ok, response} = Finch.build(:post, "#{url}/test_post_json", headers, body) |> Finch.request(TestFinch) diff --git a/test/support/gen/plug/pre_test_post_json.ex b/test/support/gen/plug/pre_test_post_json.ex index 312af25..08470c9 100644 --- a/test/support/gen/plug/pre_test_post_json.ex +++ b/test/support/gen/plug/pre_test_post_json.ex @@ -22,7 +22,8 @@ defmodule Oasis.Gen.Plug.PreTestPostJSON do "properties" => %{ "id" => %{"type" => "integer"}, "name" => %{"type" => "string"} - } + }, + "required" => ["id", "name"], }, "type" => "array" }