Skip to content

Remove top level links if configured#88

Merged
doomspork merged 3 commits intobeam-community:masterfrom
snewcomer:remove_links
Dec 19, 2017
Merged

Remove top level links if configured#88
doomspork merged 3 commits intobeam-community:masterfrom
snewcomer:remove_links

Conversation

@snewcomer
Copy link
Contributor

Looks like links can be both top level and resource. This removes the top level as well if configured.

Copy link
Member

@doomspork doomspork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @snewcomer!

data: encoded_data,
included: flatten_included(to_include)
}
|> merge_links(data, view, conn, Application.get_env(:jsonapi, :remove_links, false))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we refactor this to avoid piping into a single function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

data: encoded_data,
included: flatten_included(to_include)
}
merge_links(encoded_data, data, view, conn, Application.get_env(:jsonapi, :remove_links, false))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're using Application.get_env(:jsonapi, :remove_links, false) in a number of places, would you be open to refactoring this for us?

I think we can create a function:

defp remove_links?, do: Application.get_env(:jsonapi, :remove_links, false)


refute relationships[:links]
refute encoded[:data][:links]
refute encoded[:links]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add tests to ensure it's not removed elsewhere?

@doomspork
Copy link
Member

Thank you @snewcomer 😁

@jeregrine any thoughts?

@snewcomer
Copy link
Contributor Author

Just pinging this again. Thanks for the reviews!

Copy link
Member

@doomspork doomspork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@snewcomer apologizes for the delays on getting additional feedback. I found two small things, if you could fix those I think we're safe to merge.

data: encode_rel_data(rel_view, rel_data)
}
|> merge_related_links(info, Application.get_env(:jsonapi, :remove_links, false))
|> merge_related_links(info, remove_links?)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we un-pipe this?

}

doc = merge_links(encoded_data, data, view, conn, Application.get_env(:jsonapi, :remove_links, false))
doc = merge_links(encoded_data, data, view, conn, remove_links?)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please update calls to remove_links? to remove_links?()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

@doomspork
Copy link
Member

Thank you @snewcomer 👍 Until @jeregrine can cut a new release you'll need to use master:

{:jsonapi, github: "jeregrine/jsonapi"}

@doomspork doomspork merged commit ba4db2e into beam-community:master Dec 19, 2017
@jeregrine
Copy link

jeregrine commented Dec 20, 2017 via email

@doomspork
Copy link
Member

You got it @jeregrine!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants