Skip to content

Commit

Permalink
bugfix: explicitly set nullability of a parameter is now considered a…
Browse files Browse the repository at this point in the history
…s well (no actual behavioral changes, all the changed endpoint parameters were optional so nullable by default, now they are explicitly nullable as well)
  • Loading branch information
eceltov committed Feb 27, 2025
1 parent 9af19f3 commit 424a49b
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 11 deletions.
2 changes: 2 additions & 0 deletions app/V1Module/presenters/AsyncJobsPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,14 @@ public function checkList()
new VInt(),
"Maximal time since completion (in seconds), null = only pending operations",
required: false,
nullable: true,
)]
#[Query(
"includeScheduled",
new VBool(),
"If true, pending scheduled events will be listed as well",
required: false,
nullable: true,
)]
public function actionList(?int $ageThreshold, ?bool $includeScheduled)
{
Expand Down
14 changes: 11 additions & 3 deletions app/V1Module/presenters/ExercisesPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,21 @@ public function checkDefault()
* @GET
*/
#[Query("offset", new VInt(), "Index of the first result.", required: false)]
#[Query("limit", new VInt(), "Maximal number of results returned.", required: false)]
#[Query("limit", new VInt(), "Maximal number of results returned.", required: false, nullable: true)]
#[Query(
"orderBy",
new VString(),
"Name of the column (column concept). The '!' prefix indicate descending order.",
required: false,
nullable: true,
)]
#[Query("filters", new VArray(), "Named filters that prune the result.", required: false)]
#[Query("filters", new VArray(), "Named filters that prune the result.", required: false, nullable: true)]
#[Query(
"locale",
new VString(),
"Currently set locale (used to augment order by clause if necessary),",
required: false,
nullable: true,
)]
public function actionDefault(
int $offset = 0,
Expand Down Expand Up @@ -263,7 +265,13 @@ public function checkAuthors()
* @GET
*/
#[Query("instanceId", new VString(), "Id of an instance from which the authors are listed.", required: false)]
#[Query("groupId", new VString(), "A group where the relevant exercises can be seen (assigned).", required: false)]
#[Query(
"groupId",
new VString(),
"A group where the relevant exercises can be seen (assigned).",
required: false,
nullable: true,
)]
public function actionAuthors(string $instanceId = null, string $groupId = null)
{
$authors = $this->exercises->getAuthors($instanceId, $groupId, $this->groups);
Expand Down
3 changes: 2 additions & 1 deletion app/V1Module/presenters/GroupsPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class GroupsPresenter extends BasePresenter
* Get a list of all non-archived groups a user can see. The return set is filtered by parameters.
* @GET
*/
#[Query("instanceId", new VString(), "Only groups of this instance are returned.", required: false)]
#[Query("instanceId", new VString(), "Only groups of this instance are returned.", required: false, nullable: true)]
#[Query(
"ancestors",
new VBool(),
Expand All @@ -196,6 +196,7 @@ class GroupsPresenter extends BasePresenter
new VString(),
"Search string. Only groups containing this string as a substring of their names are returned.",
required: false,
nullable: true,
)]
#[Query("archived", new VBool(), "Include also archived groups in the result.", required: false)]
#[Query(
Expand Down
6 changes: 4 additions & 2 deletions app/V1Module/presenters/PipelinesPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,21 @@ public function checkDefault(string $search = null)
* @GET
*/
#[Query("offset", new VInt(), "Index of the first result.", required: false)]
#[Query("limit", new VInt(), "Maximal number of results returned.", required: false)]
#[Query("limit", new VInt(), "Maximal number of results returned.", required: false, nullable: true)]
#[Query(
"orderBy",
new VString(),
"Name of the column (column concept). The '!' prefix indicate descending order.",
required: false,
nullable: true,
)]
#[Query("filters", new VArray(), "Named filters that prune the result.", required: false)]
#[Query("filters", new VArray(), "Named filters that prune the result.", required: false, nullable: true)]
#[Query(
"locale",
new VString(),
"Currently set locale (used to augment order by clause if necessary),",
required: false,
nullable: true,
)]
public function actionDefault(
int $offset = 0,
Expand Down
4 changes: 2 additions & 2 deletions app/V1Module/presenters/SubmitPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public function checkCanSubmit(string $id, string $userId = null)
* @throws NotFoundException
*/
#[Path("id", new VString(), "Identifier of the assignment", required: true)]
#[Query("userId", new VString(), "Identification of the user", required: false)]
#[Query("userId", new VString(), "Identification of the user", required: false, nullable: true)]
public function actionCanSubmit(string $id, string $userId = null)
{
$assignment = $this->assignments->findOrThrow($id);
Expand Down Expand Up @@ -452,7 +452,7 @@ public function checkPreSubmit(string $id, string $userId = null)
*/
#[Post("files", new VArray())]
#[Path("id", new VString(), "identifier of assignment", required: true)]
#[Query("userId", new VString(), "Identifier of the submission author", required: false)]
#[Query("userId", new VString(), "Identifier of the submission author", required: false, nullable: true)]
public function actionPreSubmit(string $id, string $userId = null)
{
$assignment = $this->assignments->findOrThrow($id);
Expand Down
6 changes: 4 additions & 2 deletions app/V1Module/presenters/UsersPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,21 @@ public function checkDefault()
* @GET
*/
#[Query("offset", new VInt(), "Index of the first result.", required: false)]
#[Query("limit", new VInt(), "Maximal number of results returned.", required: false)]
#[Query("limit", new VInt(), "Maximal number of results returned.", required: false, nullable: true)]
#[Query(
"orderBy",
new VString(),
"Name of the column (column concept). The '!' prefix indicate descending order.",
required: false,
nullable: true,
)]
#[Query("filters", new VArray(), "Named filters that prune the result.", required: false)]
#[Query("filters", new VArray(), "Named filters that prune the result.", required: false, nullable: true)]
#[Query(
"locale",
new VString(),
"Currently set locale (used to augment order by clause if necessary),",
required: false,
nullable: true,
)]
public function actionDefault(
int $offset = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,18 @@ public static function convertRegexCapturesToParenthesesBuilder(array $annotatio
}
$validation = $annotationParameters["validation"];

// check nullability
// check nullability, it is either in the validation string, or set explicitly
// validation strings contain the 'null' qualifier always at the end of the string.
$nullabilitySuffix = "|null";
if (str_ends_with($validation, $nullabilitySuffix)) {
// remove the '|null'
$validation = substr($validation, 0, -strlen($nullabilitySuffix));
$nullable = true;
// check for explicit nullability
} elseif (array_key_exists("nullable", $annotationParameters)) {
// if it is explicitly not nullable but at the same time has to be nullable due to another factor,
// make it nullable (the other factor can be missing validation)
$nullable |= $annotationParameters["nullable"] === "true";
}

// this will always produce a single validator (the annotations do not contain multiple validation fields)
Expand Down

0 comments on commit 424a49b

Please sign in to comment.