Skip to content

Commit 424a49b

Browse files
committed
bugfix: explicitly set nullability of a parameter is now considered as well (no actual behavioral changes, all the changed endpoint parameters were optional so nullable by default, now they are explicitly nullable as well)
1 parent 9af19f3 commit 424a49b

File tree

7 files changed

+31
-11
lines changed

7 files changed

+31
-11
lines changed

app/V1Module/presenters/AsyncJobsPresenter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,14 @@ public function checkList()
104104
new VInt(),
105105
"Maximal time since completion (in seconds), null = only pending operations",
106106
required: false,
107+
nullable: true,
107108
)]
108109
#[Query(
109110
"includeScheduled",
110111
new VBool(),
111112
"If true, pending scheduled events will be listed as well",
112113
required: false,
114+
nullable: true,
113115
)]
114116
public function actionList(?int $ageThreshold, ?bool $includeScheduled)
115117
{

app/V1Module/presenters/ExercisesPresenter.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,19 +199,21 @@ public function checkDefault()
199199
* @GET
200200
*/
201201
#[Query("offset", new VInt(), "Index of the first result.", required: false)]
202-
#[Query("limit", new VInt(), "Maximal number of results returned.", required: false)]
202+
#[Query("limit", new VInt(), "Maximal number of results returned.", required: false, nullable: true)]
203203
#[Query(
204204
"orderBy",
205205
new VString(),
206206
"Name of the column (column concept). The '!' prefix indicate descending order.",
207207
required: false,
208+
nullable: true,
208209
)]
209-
#[Query("filters", new VArray(), "Named filters that prune the result.", required: false)]
210+
#[Query("filters", new VArray(), "Named filters that prune the result.", required: false, nullable: true)]
210211
#[Query(
211212
"locale",
212213
new VString(),
213214
"Currently set locale (used to augment order by clause if necessary),",
214215
required: false,
216+
nullable: true,
215217
)]
216218
public function actionDefault(
217219
int $offset = 0,
@@ -263,7 +265,13 @@ public function checkAuthors()
263265
* @GET
264266
*/
265267
#[Query("instanceId", new VString(), "Id of an instance from which the authors are listed.", required: false)]
266-
#[Query("groupId", new VString(), "A group where the relevant exercises can be seen (assigned).", required: false)]
268+
#[Query(
269+
"groupId",
270+
new VString(),
271+
"A group where the relevant exercises can be seen (assigned).",
272+
required: false,
273+
nullable: true,
274+
)]
267275
public function actionAuthors(string $instanceId = null, string $groupId = null)
268276
{
269277
$authors = $this->exercises->getAuthors($instanceId, $groupId, $this->groups);

app/V1Module/presenters/GroupsPresenter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class GroupsPresenter extends BasePresenter
184184
* Get a list of all non-archived groups a user can see. The return set is filtered by parameters.
185185
* @GET
186186
*/
187-
#[Query("instanceId", new VString(), "Only groups of this instance are returned.", required: false)]
187+
#[Query("instanceId", new VString(), "Only groups of this instance are returned.", required: false, nullable: true)]
188188
#[Query(
189189
"ancestors",
190190
new VBool(),
@@ -196,6 +196,7 @@ class GroupsPresenter extends BasePresenter
196196
new VString(),
197197
"Search string. Only groups containing this string as a substring of their names are returned.",
198198
required: false,
199+
nullable: true,
199200
)]
200201
#[Query("archived", new VBool(), "Include also archived groups in the result.", required: false)]
201202
#[Query(

app/V1Module/presenters/PipelinesPresenter.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,21 @@ public function checkDefault(string $search = null)
156156
* @GET
157157
*/
158158
#[Query("offset", new VInt(), "Index of the first result.", required: false)]
159-
#[Query("limit", new VInt(), "Maximal number of results returned.", required: false)]
159+
#[Query("limit", new VInt(), "Maximal number of results returned.", required: false, nullable: true)]
160160
#[Query(
161161
"orderBy",
162162
new VString(),
163163
"Name of the column (column concept). The '!' prefix indicate descending order.",
164164
required: false,
165+
nullable: true,
165166
)]
166-
#[Query("filters", new VArray(), "Named filters that prune the result.", required: false)]
167+
#[Query("filters", new VArray(), "Named filters that prune the result.", required: false, nullable: true)]
167168
#[Query(
168169
"locale",
169170
new VString(),
170171
"Currently set locale (used to augment order by clause if necessary),",
171172
required: false,
173+
nullable: true,
172174
)]
173175
public function actionDefault(
174176
int $offset = 0,

app/V1Module/presenters/SubmitPresenter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public function checkCanSubmit(string $id, string $userId = null)
224224
* @throws NotFoundException
225225
*/
226226
#[Path("id", new VString(), "Identifier of the assignment", required: true)]
227-
#[Query("userId", new VString(), "Identification of the user", required: false)]
227+
#[Query("userId", new VString(), "Identification of the user", required: false, nullable: true)]
228228
public function actionCanSubmit(string $id, string $userId = null)
229229
{
230230
$assignment = $this->assignments->findOrThrow($id);
@@ -452,7 +452,7 @@ public function checkPreSubmit(string $id, string $userId = null)
452452
*/
453453
#[Post("files", new VArray())]
454454
#[Path("id", new VString(), "identifier of assignment", required: true)]
455-
#[Query("userId", new VString(), "Identifier of the submission author", required: false)]
455+
#[Query("userId", new VString(), "Identifier of the submission author", required: false, nullable: true)]
456456
public function actionPreSubmit(string $id, string $userId = null)
457457
{
458458
$assignment = $this->assignments->findOrThrow($id);

app/V1Module/presenters/UsersPresenter.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,21 @@ public function checkDefault()
125125
* @GET
126126
*/
127127
#[Query("offset", new VInt(), "Index of the first result.", required: false)]
128-
#[Query("limit", new VInt(), "Maximal number of results returned.", required: false)]
128+
#[Query("limit", new VInt(), "Maximal number of results returned.", required: false, nullable: true)]
129129
#[Query(
130130
"orderBy",
131131
new VString(),
132132
"Name of the column (column concept). The '!' prefix indicate descending order.",
133133
required: false,
134+
nullable: true,
134135
)]
135-
#[Query("filters", new VArray(), "Named filters that prune the result.", required: false)]
136+
#[Query("filters", new VArray(), "Named filters that prune the result.", required: false, nullable: true)]
136137
#[Query(
137138
"locale",
138139
new VString(),
139140
"Currently set locale (used to augment order by clause if necessary),",
140141
required: false,
142+
nullable: true,
141143
)]
142144
public function actionDefault(
143145
int $offset = 0,

app/helpers/MetaFormats/AnnotationConversion/NetteAnnotationConverter.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,18 @@ public static function convertRegexCapturesToParenthesesBuilder(array $annotatio
231231
}
232232
$validation = $annotationParameters["validation"];
233233

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

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

0 commit comments

Comments
 (0)