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

Update docs with recent changes to membership APIs #9210

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
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
145 changes: 115 additions & 30 deletions docs/_extra/api-reference/hypothesis-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ info:
| 500 | Server Error | An error occurred with our API |

servers:
- url: https://api.hypothes.is/api
- url: https://hypothes.is/api
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thought I'd fix this while I was here: all the example URLs in our docs have been wrong, presumably since we first moved to redoc.


# -----------------------------------------------------------------------------
# Reusable tags for grouping operations
Expand All @@ -111,6 +111,7 @@ tags:
- name: general
- name: annotations
- name: groups
- name: memberships
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The membership APIs used to be listed under groups in the docs. I'm moving them out into their own separate section since they do form a separate set of endpoints (list-memberships, add-membership, get-membership, edit-membership and delete-membership). Like annotation, user and group, "membership" is now a first-class noun in the h model and API.

- name: profile
- name: users

Expand All @@ -122,6 +123,25 @@ components:
# Reusable parameters
# -------------------------
parameters:
PageNumber:
name: "page[number]"
in: query
required: false
description: Which page of results to get
schema:
type: int
default: 1
minimum: 1
PageSize:
name: "page[size]"
in: query
required: false
description: How many items to get per page
schema:
type: int
default: 20
minimum: 1
maximum: 100
Comment on lines +126 to +144
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Putting the pagination query params in a reusable place. They're currently only used by one endpoint but if we ever add another endpoint with page-based pagination we'll want to re-use the same query params. That said I don't know if/how you can customize the default and maximum values when reusing a parameter in OpenAPI. 🤷‍♂️ A problem for another day

Copy link
Contributor

Choose a reason for hiding this comment

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

That said I don't know if/how you can customize the default and maximum values when reusing a parameter in OpenAPI. 🤷‍♂️ A problem for another day

You can use allOf where one of the "sides" is a $ref to the common parts of the schema, and the rest are the parts that are different.

AnnotationID:
name: id
in: path
Expand Down Expand Up @@ -265,6 +285,12 @@ components:
$ref: './schemas/user-new.yaml#/User'
UserUpdate:
$ref: './schemas/user-update.yaml#/User'
Membership:
$ref: './schemas/membership.yaml#/Membership'
MembershipCreate:
$ref: './schemas/membership-create.yaml#/Membership'
PaginationMeta:
$ref: './schemas/pagination-meta.yaml#/PaginationMeta'
Comment on lines +288 to +293
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reusable schemas for various parts of membership API request and response bodies.


# -----------------------------------------------------------------------------
# API OPERATIONS
Expand Down Expand Up @@ -851,76 +877,135 @@ paths:
# ---------------------------------------------------------------------------

# ---------------------------------------------------------------------------
# GET groups/{id}/members - Get group members
# GET groups/{id}/members - Get group memberships
# ---------------------------------------------------------------------------
/groups/{id}/members:
get:
tags:
- groups
summary: Get group members
- memberships
summary: Get group memberships
description: |
Fetch a list of all members (users) in a group. Returned user resource only
contains public-facing user data. Authenticated user must have read access
to the group. Does not require authentication for reading members of
public groups. Returned members are unsorted.
Get a paginated list of all user memberships in a group.
To get the memberships of a private group the authenticated user must be a member of the group.
Getting the memberships of an open or restricted group does not require authentication.
The returned memberships are sorted by joining date, oldest first.

If the `page[number]` query param is included in the request then the response will be paginated.
If there's no `page[number]` query param in the request then a legacy,
un-paginated response format will be used. In the future this legacy
un-paginated response format will be removed and the paginated response
format will be used even when the `page[number]` query param is not
present.
Comment on lines +893 to +898
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a PR ready to remove the un-paginated API when we're ready to do that, and I've included removing this stuff from the docs: #9183

parameters:
- $ref: '#/components/parameters/PageNumber'
- $ref: '#/components/parameters/PageSize'
security:
- AuthClient: []
- ApiKey: []
- {} # Unauthenticated OK for public groups
- {}
responses:
'200':
description: Success
content:
application/*json:
schema:
type: array
items:
$ref: '#/components/schemas/User'
oneOf:
- title: "Paginated"
type: object
properties:
meta:
description: "Metadata about this response."
type: object
properties:
page:
$ref: '#/components/schemas/PaginationMeta'
data:
description: "The list of memberships for the requested page."
type: array
items:
$ref: '#/components/schemas/Membership'
- title: "Unpaginated (deprecated)"
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is deprecated, I reckon you can also add deprecated: true, but I would need to check the docs to confirm this in fact possible in this context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually did try this but it didn't seem to do anything

type: array
items:
$ref: '#/components/schemas/Membership'

/groups/{id}/members/{user}:
# ----------------------------------------------------------
# POST groups/{id}/members/{user} - Add user to group
# ----------------------------------------------------------
post:
tags:
- groups
- memberships
summary: Add member to group
description: |
Add a user as a member to a group. This endpoint is only accessible to
requests authenticated with `AuthClient` credentials and is restricted
to users and groups within the associated authority.
Add a user as a member to a group.
security:
- AuthClient: []
parameters:
- $ref: '#/components/parameters/GroupID'
- $ref: '#/components/parameters/UserID'
requestBody:
required: false
content:
application/*json:
schema:
$ref: '#/components/schemas/MembershipCreate'
responses:
'204':
$ref: '#/components/responses/NoContent'
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/Membership'

# ------------------------------------------------------------------------
# PATCH groups/{id}/members/{user} - Change a user's membership in a group
# ------------------------------------------------------------------------
patch:
tags:
- memberships
summary: Update membership
description: |
Update a user's membership in a group.

To update *your own* membership you can use the alias `me` in place of `{user}`.
This is equivalent to using your own user ID.
security:
- ApiKey: []
parameters:
- $ref: '#/components/parameters/GroupID'
- $ref: '#/components/parameters/UserID'
requestBody:
required: true
content:
application/*json:
schema:
$ref: '#/components/schemas/MembershipCreate'
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/Membership'

# ----------------------------------------------------------
# DELETE groups/{id}/members/{user} - Remove user from group
# ----------------------------------------------------------
delete:
tags:
- groups
- memberships
summary: Remove member from group
description: |
Remove a user from a group. At present, this endpoint only allows
the removal as one's self (authenticated with API Key) from the
indicated group.
Remove a user from a group.

To remove *yourself* from a group you can use the alias `me` in place of `{user}`.
This is equivalent to using your own user ID.
security:
- ApiKey: []
parameters:
- $ref: '#/components/parameters/GroupID'
- name: user
in: path
description: Currently, only the literal value `me` is accepted
required: true
schema:
type: string
enum:
- me
- $ref: '#/components/parameters/UserID'
responses:
'204':
$ref: '#/components/responses/NoContent'
Expand Down
Loading
Loading