Skip to content

feat(profiles): server-required profiles #1354

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions _format/1.1/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2226,6 +2226,28 @@ because the value for the `updated` key is not recognized under the profile's
requirement that the `updated` key hold a string of the form produced by
`JSON.stringify`.

### <a href="#profiles-required" id="profiles-required" class="headerlink"></a> Server-Required Profiles

Generally, servers should not require that clients apply specific profiles to
their requests, as such requirements reduce interoperability.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a very important sentence for understanding how profiles are meant to be implemented for maximum interoperability! I'm glad we're adding it after all :)


However, in many common cases, a server does require that clients provide
certain data (e.g., authentication credentials), and it **MAY** require that
this data be provided by applying a specific profile (or any one profile from
Copy link
Contributor

Choose a reason for hiding this comment

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

I find this example not very convincing. I cannot imagine authentication is often embedded into JSON:API documents. Authentication is an orthogonal concern.

Which leaves me wondering: what is a good example of this? Why is this "common"?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's strange that this statement broadly contradicts the one before it by saying "Generally servers should not require profiles" and then "in many common cases, servers can require profiles".

I think it's hard to think of an example where extra data must be provided (a revision key is the best I could come up with), but I can think of requirements about how that data is provided (i.e. different profiles for different date/time formats).

Copy link
Member Author

Choose a reason for hiding this comment

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

I find this example not very convincing. I cannot imagine authentication is often embedded into JSON:API documents. Authentication is an orthogonal concern.

Authentication isn't a great example; I was imagining a case where maybe a request signature could show up in the body (e.g., in top-level meta), but Gabe's examples are better tbh. I can update the PR and the wording.

I think it's strange that this statement broadly contradicts the one before it by saying "Generally servers should not require profiles" and then "in many common cases, servers can require profiles".

How would you suggest wording it?

Copy link
Contributor

@gabesullice gabesullice Jan 4, 2019

Choose a reason for hiding this comment

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

A server MAY require that a client applies a specific profile to its request.

However, it is NOT RECOMMENDED for servers to require profiles which require additional query parameters or additional request document members, as such requirements reduce interoperability between clients and servers.

Note: Profiles with optional document members, specific value formats (e.g. ISO 8601 date and time format), or specific query parameters within a query parameter family already reserved by this specification should be treated with care, but do not have the same level of interoperability concerns.

Copy link
Contributor

@gabesullice gabesullice Jan 4, 2019

Choose a reason for hiding this comment

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

My theory here is that:

  1. anything optional obviously doesn't have interop concerns.
  2. query parameters within query parameter families are usually implementation specific (filter, sort, etc) so clients will likely not have them hardcoded.
  3. like Consider relaxing some MUSTs #2, value formats are usually "passed through" a client library and aren't hardcoded; they typically come from a frontend developer working against a specific backend.

a set of supported profiles) to the request.

In the event that the server requires the client to apply a profile to its
request, and the client fails to do so, the server **MUST** send a
`415 Unsupported Media Type` error.

In the error's response body, there **MUST** be an [error object] for each
required profile that is missing, and this error object **MUST**:

1. have a `type` who's URI is `http://jsonapi.org/errors/missing-required-profile`
2. include the URI of the missing profile in the `extension` member of the
Copy link
Contributor

Choose a reason for hiding this comment

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

s/extension/profile/

`missing` object, with the `alternatives` key provided if the client could've
used other profiles instead to satisfy the server's requirements.

### <a href="#profiles-authoring" id="profiles-authoring" class="headerlink"></a> Authoring Profiles

A profile **MAY** assign meaning to elements of the document structure whose use
Expand Down Expand Up @@ -2371,6 +2393,23 @@ An error object **MAY** have the following members:
exists; if it doesn't, the client **SHOULD** simply ignore the pointer.
* `parameter`: a string indicating which URI query parameter caused
the error.
* <a id="error-objects-source-missing"></a>`missing`: an object indicating
that the error was caused by a missing profile, JSON object key (or array
index), or URI query parameter. If present, this object **MUST** contain
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't think of a use case for the missing array index. What am I missing?

Copy link
Member Author

Choose a reason for hiding this comment

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

E.g., a profile that takes data in an [x,y,z] coordinate pair is given an array with fewer entries. More importantly, though, it just seems good to general here

Copy link
Contributor

Choose a reason for hiding this comment

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

The coordinate example helps, thanks!

But I thought profiles only could add elements to the document structure (per
https://jsonapi.org/format/1.1/#profile-keywords-and-aliases), which means they must have a name, and hence a JSON object key? Wouldn't the coordinate example be a value of an object key, and therefore z being absent from [x,y,z] would not result in a missing error since the key would be present, the value itself would just be invalid. In other words: invalid, not missing?

I'm probably still missing something, sorry.

Copy link
Member Author

@ethanresnick ethanresnick Jan 24, 2019

Choose a reason for hiding this comment

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

Wouldn't the coordinate example be a value of an object key, and therefore z being absent from [x,y,z] would not result in a missing error since the key would be present, the value itself would just be invalid.

It's both. I.e., the value is invalid because a key (index 2) is missing.

In other words, if a client client sends:

{ "meta": { "homeBase": [x,y] }

then the server's error object would ideally contain "pointer": "/meta/homeBase", whether it contains "missing" or not. But that just tells you that the value at /meta/homeBase had an error. Being able to supplement the pointer with "missing": { "key": "2" } just makes it a bit more specific about what the error was.

In theory, you never need "missing": { "key": "... " }, because you can always reinterpret your error as being not that some key is missing, but that the value that's supposed to contain the key (pointed to by "pointer") is invalid. But missing is a way to be more specific about "invalid how".

exactly one of the following keys:
* `extension`: the URI of a missing profile. This key **SHOULD** be
Copy link
Contributor

Choose a reason for hiding this comment

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

s/extension/profile/

used with the `pointer` member to indicate which value in the request
document is missing the profile.
* `key`: the name of a missing key in a JSON object, or a missing index in
a JSON array, expressed as a string. This key **SHOULD** be used with
the `pointer` member to indicate which object/array in the request
document is missing the key.
Comment on lines +2403 to +2406
Copy link
Contributor

Choose a reason for hiding this comment

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

Even if server-required profiles doesn't make it into 1.1, I think this is a worthwhile addition, paired with the language added in e75cec1 to clarify that the pointer must reference an element in the original request. In the case of a missing key, this should be paired with some other data point (e.g., this element) to tell the client exactly which data was missing.

* `parameter`: the name of a missing URI query parameter.

This object **MAY** also contain an `alternatives` key, whose value is an
array listing alternate profile URIs, key names, or query parameter names
(depending on which type of value is missing) that can be added to resolve
this error.
* `meta`: a [meta object][meta] containing non-standard meta-information about the
error.

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy