Skip to content

Conversation

jelhan
Copy link
Contributor

@jelhan jelhan commented Jan 3, 2021

The meaning of an empty value for the include query parameter was not clear yet. As @freddrake pointed out in #1530 a reader could interpret either as an empty list of relationship paths or as a single (invalid) relationship path.

The meaning of an empty value for fields query parameter is explicitly specified:

The value of the fields parameter MUST be a comma-separated (U+002C COMMA, “,”) list that refers to the name(s) of the fields to be returned. An empty value indicates that no fields should be returned.

I think the same applies to the include query parameter even though it's not mentioned explicitly yet. Otherwise a client would not be able to tell a server to not include any related resources - even if that server includes some resources by default.

I think this is not a breaking change. Let's have a look at several scenarios:

  1. An existing implementation may consider an empty value as a single relationship path. An empty string is not a valid relationship path. The server would be unable to identify the relationship path and response with 400 Bad Request.

    If a server is unable to identify a relationship path or does not support inclusion of resources from a path, it MUST respond with 400 Bad Request.

  2. An existing implementation may silently ignore an include parameter if it's value is empty.

    1. If it does not include any related resources by default, the existing implementation would be valid.
    2. If it includes related resources by default even if an include parameter with an empty value is given, the implementation is not compliant with the specification even today. A server must not ignore a given include query parameter. It must response with a 400 if it does not support it.

      If an endpoint does not support the include parameter, it MUST respond with 400 Bad Request to any requests that include it.

      If an endpoint supports the include parameter and a client supplies it, the server MUST NOT include unrequested resource objects in the included section of the compound document.
      [...]
      If a server is unable to identify a relationship path or does not support inclusion of resources from a path, it MUST respond with 400 Bad Request.

  3. An existing implementation may already interpret an empty ignore parameter as an empty list of relationship paths and not include any related resources.

The meaning of an empty value for a Sparse Fieldset was also not explicitly specified since a few months ago. It was added in #1500. This was also not considered a breaking change.

Closes #1530

@freddrake
Copy link
Contributor

FWIW, I'm proceeding with the assumption that something like this is going to land at some point.

Comment on lines 1240 to 1241
(U+002E FULL-STOP, ".") list of [relationship][relationships] names. An empty
value indicates that no related resource should be returned.
Copy link

Choose a reason for hiding this comment

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

If we wish to add this clarification.

Suggested change
(U+002E FULL-STOP, ".") list of [relationship][relationships] names. An empty
value indicates that no related resource should be returned.
(U+002E FULL-STOP, ".") list of [relationship][relationships] names. An empty
value (no characters) indicates that no related resource should be returned.

Copy link
Member

Choose a reason for hiding this comment

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

@prathe I'm not sure the clarification (no characters) is needed, but I'm not opposed either. If we were to add this, it should also be added to the similar language around sparse field sets. Since it affects multiple areas, maybe a small separate PR would be best.

Copy link
Member

@dgeb dgeb left a comment

Choose a reason for hiding this comment

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

Thanks for adding this clarification. This seems good and is consistent with the language around sparse fieldsets. Just one minor nit to fix and then we can merge this.

Co-authored-by: Dan Gebhardt <dan@cerebris.com>
@dgeb dgeb merged commit f757757 into json-api:gh-pages Jan 14, 2021
@dgeb
Copy link
Member

dgeb commented Jan 14, 2021

Thanks again @jelhan for the clarifying PR and also to @freddrake for raising the issue in #1530.

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.

is empty include allowed?
6 participants