Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit non-Object meta #124

Merged
merged 4 commits into from
Aug 28, 2018
Merged

Omit non-Object meta #124

merged 4 commits into from
Aug 28, 2018

Conversation

kbaird
Copy link
Contributor

@kbaird kbaird commented Aug 3, 2018

The serializer was including meta even in cases where its value would not be an Object, which is not in compliance with the JSONAPI spec (http://jsonapi.org/format/#document-meta). This PR makes the serializer omit the meta when is_map(meta) is false.

I also DRYed up the tests, since my added ones re-used some of the existing default data.

…refore not an object, as the specification requires.

Cf. http://jsonapi.org/format/#document-meta

Where specified, a meta member can be used to include non-standard meta-information. The value of each meta member MUST be an object (a “meta object”).
@kbaird kbaird changed the title Omit nil meta Omit non-Object meta Aug 3, 2018
@mjc
Copy link

mjc commented Aug 3, 2018

I think this is a bugfix rather than an enhancement as "meta": null was the previous output and that is not allowed by the spec.

@doomspork doomspork added bug and removed enhancement labels Aug 3, 2018
@doomspork
Copy link
Member

Thank you and welcome @kbaird 😁

I've corrected the label

Copy link
Contributor

@snewcomer snewcomer left a comment

Choose a reason for hiding this comment

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

Very nice! Seen this a lot but never knew it was a bug!

@@ -117,8 +117,7 @@ defmodule JSONAPI.QueryParser do
requested_fields =
value
|> String.split(",")
|> Enum.map(&String.to_atom/1)
|> Enum.into(MapSet.new())
|> Enum.into(MapSet.new(), &String.to_atom/1)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@jeregrine jeregrine merged commit 70e04b5 into beam-community:master Aug 28, 2018
@kbaird kbaird deleted the OmitNilMeta branch August 30, 2018 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants