Improve the profile query to have more sane responses

This is a mix of Synapse and Dendrite behaviour, mostly Dendrite. Synapse returns `null` for field values that aren't set, however Dendrite just doesn't return them and instead opts for an empty object.

Further, synapse is lacking in error codes in this area. Dendrite does some additional validation on this API which introduces more errors for bad requests, instead of defaulting to empty objects/200 OK responses.

Likewise, Dendrite returns a 404 when the user is not found while Synapse returns 200 OK/empty object.
pull/977/head
Travis Ralston 6 years ago
parent 0ddf578b61
commit d914c402e2

@ -131,7 +131,8 @@ paths:
x-example: "@someone:example.org" x-example: "@someone:example.org"
- in: query - in: query
name: field name: field
type: string type: enum
enum: ['displayname', 'avatar_url']
description: |- description: |-
The field to query. If specified, the server will only return the given field The field to query. If specified, the server will only return the given field
in the response. If not specified, the server will return the full profile for in the response. If not specified, the server will return the full profile for
@ -144,26 +145,22 @@ paths:
the response should include the fields of the user's profile that can be made the response should include the fields of the user's profile that can be made
public, such as the display name and avatar. public, such as the display name and avatar.
If the ``field`` is for a field that the server does not recognize, an empty object If the user does not have a particular field set on their profile, the server
should be returned. If the ``field`` is recognized, but the user does not have it should exclude it from the response body or give it the value ``null``.
set on their profile, ``null`` should be returned for the value of that field.
If the user does not exist, an empty object should be returned regardless of the
``field`` being queried.
schema: schema:
type: object type: object
properties: properties:
displayname: displayname:
type: string type: string
description: |- description: |-
The display name of the user. If the user does not have a display name set, The display name of the user. May be omitted if the user does not have a
this should be the value ``null``. display name set.
x-example: "John Doe" x-example: "John Doe"
avatar_url: avatar_url:
type: string type: string
description: |- description: |-
The avatar URL for the user's avatar. If the user does not have an avatar The avatar URL for the user's avatar. May be omitted if the user does not
set, this should be the value ``null``. have an avatar set.
x-example: "mxc://matrix.org/MyC00lAvatar" x-example: "mxc://matrix.org/MyC00lAvatar"
examples: examples:
application/json: { application/json: {
@ -171,11 +168,26 @@ paths:
"avatar_url": "mxc://matrix.org/MyC00lAvatar" "avatar_url": "mxc://matrix.org/MyC00lAvatar"
} }
400: 400:
description: The user does not belong to the server. description: |-
The request was missing parameters or had invalid values for the parameters. This
can happen for:
* The user not being hosted on the homeserver,
* Lack of a ``user_id`` in the request, or
* The ``field`` requested not being an allowed value.
schema: schema:
$ref: "../client-server/definitions/errors/error.yaml" $ref: "../client-server/definitions/errors/error.yaml"
examples: examples:
application/json: { application/json: {
"errcode": "M_UNKNOWN", "errcode": "M_INVALID_ARGUMENT_VALUE",
"error": "User is not hosted on this homeserver." "error": "User is not hosted on this homeserver."
} }
404:
description: The user does not exist or does not have a profile.
schema:
$ref: "../client-server/definitions/errors/error.yaml"
examples:
application/json: {
"errcode": "M_NOT_FOUND",
"error": "User does not exist."
}

Loading…
Cancel
Save