 
   defp key_match?(regex, string), do: Regex.match?(regex, string)
 
-  @spec additionals(Xema.Schema.t(), map) :: result
-  defp additionals(%{additional_properties: false}, map) do
+  @spec additionals(Xema.Schema.t(), map, keyword) :: result
+  defp additionals(%{additional_properties: false}, map, opts) do
     case Map.equal?(map, %{}) do
       true ->
         :ok

    end
  end

  @spec items(Xema.Schema.t(), list) :: result
  defp items(%{items: nil}, _list), do: :ok

  defp items(%{items: items, additional_items: additional_items}, list)
       when is_list(items),
       do: items_tuple(items, update_nil(additional_items, true), list, 0, [])

  defp items(%{items: items}, list), do: items_list(items, list, 0, [])

  @spec items_list(Xema.Schema.t(), list, integer, list) :: result
  defp items_list(_schema, [], _at, []), do: :ok
  defp items_list(_schema, [], _at, errors), do: {:error, Enum.reverse(errors)}

  defp items_list(schema, [item | list], at, errors) do
    case validate(schema, item) do
      :ok ->
        items_list(schema, list, at + 1, errors)

      {:error, reason} ->
        items_list(schema, list, at + 1, [{at, reason} | errors])
    end
  end

  @spec items_tuple(list, nil | boolean | Xema.Schema.t(), list, integer, list) ::
          result
  defp items_tuple(_schemas, _additonal_items, [], _at, []), do: :ok

  defp items_tuple(_schemas, _additonal_items, [], _at, errors),
    do: {:error, Enum.reverse(errors)}

  defp items_tuple([], false, [_ | list], at, errors),
    do:
      items_tuple([], false, list, at + 1, [
        {at, %{additional_items: false}} | errors
      ])

  defp items_tuple([], true, _list, _at, []), do: :ok

  defp items_tuple([], true, _list, _at, errors),
    do: {:error, Enum.reverse(errors)}

  defp items_tuple([], schema, [item | list], at, errors) do
    case validate(schema, item) do
      :ok ->
        items_tuple([], schema, list, at + 1, errors)

      {:error, reason} ->
        items_tuple([], schema, list, at + 1, [{at, reason} | errors])
    end
  end


         additional_items,
         [item | list],
         at,
         errors,
         opts
       ) do
    case validate(schema, item, opts) do
      :ok ->
        items_tuple(schemas, additional_items, list, at + 1, errors, opts)

      {:error, reason} ->
        items_tuple(schemas, additional_items, list, at + 1, [
          {at, reason} | errors
        ], opts)
    end
  end

