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 empty pagination links #2224

Conversation

mschneider85
Copy link

Purpose

I wanted to validate my API against the schema provided by json-api. There were validation errors caused by pagination links having "Null" values instead of strings. To make it schema compliant, I made this small modification.

Changes

An empty pagination link is serialized as nil, those are getting omitted now. This change affects the JsonApi adapter.

Caveats

Maybe omitting or returning empty pagination links should rather be optional?

Related GitHub issues

PR #1668 addresses a similar issue for links.

Additional helpful information

There's an open issue on the json-api repo pointing out the contradiction for pagination links within the specs. json-api/json-api#887

@bf4
Copy link
Member

bf4 commented Nov 26, 2017

I wanted to validate my API against the schema provided by json-api.

The schema isn't authoritative. You shouldn't rely on it too strongly. Are null values allowed by the specs? I believe we recently added this behavior for the opposite reason.

@mschneider85
Copy link
Author

mschneider85 commented Dec 1, 2017

The spec says

Each member of a links object is a “link”. A link MUST be represented as either:
a string containing the link’s URL.
an object (“link object”) [...]

For the pagination links (subset of links) it is:

Keys MUST either be omitted or have a null value

So I'm not quite sure how it is meant to be. In doubt I tended to follow the provided schema.

@@ -26,7 +26,7 @@ def as_json
prev: prev_page_url,
next: next_page_url,
last: last_page_url
}
}.compact
Copy link
Member

Choose a reason for hiding this comment

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

did not know about this on hash. thanks!

@bf4
Copy link
Member

bf4 commented Dec 1, 2017

I assume you're vendoring the schema, in which case I suggest you modify it and consider submitting a PR to json schema to allow a nil value.

@bf4 bf4 closed this Dec 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants