Skip to content

Commit

Permalink
api/v1/projects/:id: Allow endpoint to return selected fields
Browse files Browse the repository at this point in the history
Clients can already access a subset of fields when listing projects
with `api/v1/projects` so it makes sense to have it for individual
projects too. And in particular clients may want to avoid the
`comments` field because it can be very large.
  • Loading branch information
bpfoley authored and cpeel committed Mar 27, 2024
1 parent d95a798 commit 1a29ef9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions api/dp-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,13 @@ paths:
required: true
schema:
type: string
- name: field
description: Field to return, if not set all fields are returned.
To request multiple fields, append with [] and pass one per desired
field (e.g. field[]=projectid&field[]=author).
in: query
schema:
type: string
responses:
200:
description: project response
Expand Down
4 changes: 3 additions & 1 deletion api/v1_projects.inc
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ function create_or_update_project($project)
function api_v1_project($method, $data, $query_params)
{
if ($method == "GET") {
return render_project_json($data[":projectid"]);
// restrict to list of desired fields, if set
$return_fields = array_get_as_array($query_params, "field", null);
return render_project_json($data[":projectid"], $return_fields);
} elseif ($method == "PUT") {
$project = $data[":projectid"];
return render_project_json(create_or_update_project($project));
Expand Down

0 comments on commit 1a29ef9

Please sign in to comment.