Skip to content

Commit

Permalink
QueryParser Does Not Underscore Params
Browse files Browse the repository at this point in the history
If you want this functionality, include the `UnderscoreParameters` Plug.
Hooray for less duplication!
  • Loading branch information
jherdman committed Dec 28, 2018
1 parent d5404c9 commit 4b09c4a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 29 deletions.
12 changes: 1 addition & 11 deletions lib/jsonapi/plugs/query_parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ defmodule JSONAPI.QueryParser do
alias JSONAPI.{Config, Deprecation, Page}
alias JSONAPI.Exceptions.InvalidQuery
alias Plug.Conn
alias JSONAPI.Utils.Underscore
import JSONAPI.Utils.IncludeTree

@moduledoc """
Expand Down Expand Up @@ -187,7 +186,7 @@ defmodule JSONAPI.QueryParser do
if inc =~ ~r/\w+\.\w+/ do
acc ++ handle_nested_include(inc, valid_includes, config)
else
inc = inc |> dash() |> String.to_existing_atom()
inc = String.to_existing_atom(inc)

if Enum.any?(valid_includes, fn {key, _val} -> key == inc end) do
acc ++ [inc]
Expand All @@ -202,7 +201,6 @@ defmodule JSONAPI.QueryParser do
keys =
key
|> String.split(".")
|> Enum.map(&dash/1)
|> Enum.map(&String.to_existing_atom/1)

last = List.last(keys)
Expand All @@ -215,14 +213,6 @@ defmodule JSONAPI.QueryParser do
end
end

def dash(data) do
if Underscore.underscore?() do
Underscore.dash(data)
else
data
end
end

def get_valid_fields_for_type(%{view: view}, type) do
if type == view.type do
view.fields
Expand Down
18 changes: 0 additions & 18 deletions test/jsonapi_query_parser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,6 @@ defmodule JSONAPI.QueryParserTest do
end
end

describe "when underscore_to_dash == true" do
setup do
Application.put_env(:jsonapi, :underscore_to_dash, true)

on_exit(fn ->
Application.delete_env(:jsonapi, :underscore_to_dash)
end)

{:ok, []}
end

test "parse_include/2 turns an include string into a keyword list" do
config = struct(Config, view: MyView)
assert parse_include(config, "author.top-posts").includes == [author: :top_posts]
assert parse_include(config, "best-friends").includes == [:best_friends]
end
end

test "parse_include/2 returns a map with duplicate values for include and includes for compatibility" do
include_list =
Config
Expand Down

0 comments on commit 4b09c4a

Please sign in to comment.