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

Document /headers/original/missing.png in the header field #1184

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nikclayton
Copy link
Contributor

No description provided.

@vercel
Copy link

vercel bot commented Mar 7, 2023

@nikclayton is attempting to deploy a commit to the Mastodon Team on Vercel.

A member of the Team first needs to authorize it.

@trwnh
Copy link
Member

trwnh commented Mar 8, 2023

i don't think this is necessary to clarify?

@nikclayton
Copy link
Contributor Author

i don't think this is necessary to clarify?

I think it is. I wasted a bunch of time yesterday investigating why a null check in some code wasn't working, only to discover that the value coming back from the API for a missing value was, completely inexplicably, and in contrast to the rest of the api, not null.

@trwnh
Copy link
Member

trwnh commented Mar 10, 2023

it's already non-nullable in the docs though. idk why you would expect it to be null. if something can be null, it will explicitly be marked "nullable".

@nikclayton
Copy link
Contributor Author

nikclayton commented Mar 10, 2023

it's already non-nullable in the docs though. idk why you would expect it to be null. if something can be null, it will explicitly be marked "nullable".

  1. It would be clearer if non-nullable was also explicitly mentioned (although that is orthogonal to this PR)
  2. Either way, the fact that "This profile does not have a header image" is not indicated with null, or the empty string, or the field not being present in the response, but is instead represented by an undocumented magic string is extremely surprising, and as the developer of a Mastodon client leaves me asking questions like:
  • Is this magic string part of the API surface, or is it free to change at any time?
  • Is this magic string /headers/original/missing.png, or /original/missing.png, or /missing.png?
  • Are other Mastodon-compatible servers free to return a different magic string, or the empty string, instead?
  • What other parts of the API rely on undocumented magic strings?

API documentation should be complete and unambiguous. This PR incrementally improves the Mastodon API documentation towards this goal.

@trwnh
Copy link
Member

trwnh commented Mar 11, 2023

it's not a "magic string", it's an actual image that can be resolved and used as a placeholder. yes, the server may return any path it wants; the current guarantee is that it is a valid image url.

"nullable" is the exception, and non-nullable is the general rule. the type listed for each property is the type that will be returned. if the type lists null as a possible return value, then this is highlighted so that developers may take care to avoid null pointer exceptions. otherwise it should be safe to proceed and use the value as-is.

@nikclayton
Copy link
Contributor Author

it's not a "magic string", it's an actual image that can be resolved and used as a placeholder. yes, the server may return any path it wants; the current guarantee is that it is a valid image url.

It is a magic string, because it's the only indicator that the user has not uploaded their own header or avatar image. In order, the absence of the field, a null value, or the empty string would all be better implementations than this, and more

Consider a frontend that wants to allow the user to modify their header image by providing two options:

  1. Delete image
  2. Upload new image

The "Upload new image" option is always valid.

The "Delete image" option should only be shown to the user if they have an image to delete, and to test that you have to check against the magic /headers/original/missing.png string. Which is undocumented.

And if different servers are free to return their own string it's even worse.

Finally, I note that other parts of the documentation do take care to document the magic string, like https://github.com/mastodon/documentation/blob/master/content/en/methods/media.md

Copy link

This pull request has merge conflicts that must be resolved before it can be merged.

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.

None yet

2 participants