Skip to content

Commit d60f991

Browse files
Merge pull request #61 from nextcloud/bugfix/noid/limit-boolean-when-specified
fix(type): Only allow specified boolean when given
2 parents 620bc06 + b86ce4d commit d60f991

File tree

4 files changed

+131
-10
lines changed

4 files changed

+131
-10
lines changed

src/OpenApiType.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,9 @@ private static function resolveIdentifier(string $context, array $definitions, s
307307
"positive-int" => new OpenApiType(type: "integer", format: "int64", minimum: 1),
308308
"negative-int" => new OpenApiType(type: "integer", format: "int64", maximum: -1),
309309
"non-positive-int" => new OpenApiType(type: "integer", format: "int64", maximum: 0),
310-
"bool", "boolean", "true", "false" => new OpenApiType(type: "boolean"),
310+
"bool", "boolean" => new OpenApiType(type: "boolean"),
311+
"true" => new OpenApiType(type: "boolean", enum: [true]),
312+
"false" => new OpenApiType(type: "boolean", enum: [false]),
311313
"numeric" => new OpenApiType(type: "number"),
312314
"double" => new OpenApiType(type: "number", format: "double"),
313315
"float" => new OpenApiType(type: "number", format: "float"),

tests/appinfo/routes.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
['name' => 'Settings#intParameterWithMinAndMax', 'url' => '/api/{apiVersion}/min-max', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
4343
['name' => 'Settings#intParameterWithMin', 'url' => '/api/{apiVersion}/min', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
4444
['name' => 'Settings#intParameterWithMax', 'url' => '/api/{apiVersion}/max', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
45-
['name' => 'Settings#listOfIntStringAndBool', 'url' => '/api/{apiVersion}/mixed-list', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
45+
['name' => 'Settings#listOfIntStringAndOneBool', 'url' => '/api/{apiVersion}/mixed-list-one', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
46+
['name' => 'Settings#listOfIntStringAndAllBools', 'url' => '/api/{apiVersion}/mixed-list-all', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
4647
['name' => 'Settings#booleanParameterRequired', 'url' => '/api/{apiVersion}/boolean', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
4748
['name' => 'Settings#booleanParameterDefaultFalse', 'url' => '/api/{apiVersion}/boolean-false', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
4849
['name' => 'Settings#booleanParameterDefaultTrue', 'url' => '/api/{apiVersion}/boolean-true', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],

tests/lib/Controller/SettingsController.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,19 @@ public function intParameterWithMax(int $limit): DataResponse {
218218
*
219219
* 200: Admin settings updated
220220
*/
221-
public function listOfIntStringAndBool($weird): DataResponse {
221+
public function listOfIntStringAndOneBool($weird): DataResponse {
222+
return new DataResponse();
223+
}
224+
225+
/**
226+
* A route with a list of 2 integers, 2 strings and 1 boolean
227+
*
228+
* @param 0|1|'yes'|'no'|true|false $weird Weird list
229+
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
230+
*
231+
* 200: Admin settings updated
232+
*/
233+
public function listOfIntStringAndAllBools($weird): DataResponse {
222234
return new DataResponse();
223235
}
224236

@@ -237,7 +249,7 @@ public function booleanParameterRequired(bool $yesOrNo): DataResponse {
237249
/**
238250
* A route with boolean defaulting to false
239251
*
240-
* @param bool $yesOrNo Booleandefaulting to false
252+
* @param bool $yesOrNo Boolean defaulting to false
241253
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
242254
*
243255
* 200: Admin settings updated
@@ -249,7 +261,7 @@ public function booleanParameterDefaultFalse(bool $yesOrNo = false): DataRespons
249261
/**
250262
* A route with boolean defaulting to true
251263
*
252-
* @param bool $yesOrNo Booleandefaulting to true
264+
* @param bool $yesOrNo Boolean defaulting to true
253265
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
254266
*
255267
* 200: Admin settings updated

tests/openapi.json

Lines changed: 111 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,9 +1273,9 @@
12731273
}
12741274
}
12751275
},
1276-
"/ocs/v2.php/apps/notifications/api/{apiVersion}/mixed-list": {
1276+
"/ocs/v2.php/apps/notifications/api/{apiVersion}/mixed-list-one": {
12771277
"post": {
1278-
"operationId": "settings-list-of-int-string-and-bool",
1278+
"operationId": "settings-list-of-int-string-and-one-bool",
12791279
"summary": "A route with a list of 2 integers, 2 strings and 1 boolean",
12801280
"description": "This endpoint requires admin access",
12811281
"tags": [
@@ -1298,8 +1298,107 @@
12981298
"schema": {
12991299
"oneOf": [
13001300
{
1301-
"type": "boolean"
1301+
"type": "integer",
1302+
"enum": [
1303+
0,
1304+
1
1305+
]
13021306
},
1307+
{
1308+
"type": "string",
1309+
"enum": [
1310+
"yes",
1311+
"no"
1312+
]
1313+
},
1314+
{
1315+
"type": "boolean",
1316+
"enum": [
1317+
true
1318+
]
1319+
}
1320+
]
1321+
}
1322+
},
1323+
{
1324+
"name": "apiVersion",
1325+
"in": "path",
1326+
"required": true,
1327+
"schema": {
1328+
"type": "string",
1329+
"enum": [
1330+
"v2"
1331+
],
1332+
"default": "v2"
1333+
}
1334+
},
1335+
{
1336+
"name": "OCS-APIRequest",
1337+
"in": "header",
1338+
"description": "Required to be true for the API request to pass",
1339+
"required": true,
1340+
"schema": {
1341+
"type": "boolean",
1342+
"default": true
1343+
}
1344+
}
1345+
],
1346+
"responses": {
1347+
"200": {
1348+
"description": "Admin settings updated",
1349+
"content": {
1350+
"application/json": {
1351+
"schema": {
1352+
"type": "object",
1353+
"required": [
1354+
"ocs"
1355+
],
1356+
"properties": {
1357+
"ocs": {
1358+
"type": "object",
1359+
"required": [
1360+
"meta",
1361+
"data"
1362+
],
1363+
"properties": {
1364+
"meta": {
1365+
"$ref": "#/components/schemas/OCSMeta"
1366+
},
1367+
"data": {}
1368+
}
1369+
}
1370+
}
1371+
}
1372+
}
1373+
}
1374+
}
1375+
}
1376+
}
1377+
},
1378+
"/ocs/v2.php/apps/notifications/api/{apiVersion}/mixed-list-all": {
1379+
"post": {
1380+
"operationId": "settings-list-of-int-string-and-all-bools",
1381+
"summary": "A route with a list of 2 integers, 2 strings and 1 boolean",
1382+
"description": "This endpoint requires admin access",
1383+
"tags": [
1384+
"settings"
1385+
],
1386+
"security": [
1387+
{
1388+
"bearer_auth": []
1389+
},
1390+
{
1391+
"basic_auth": []
1392+
}
1393+
],
1394+
"parameters": [
1395+
{
1396+
"name": "weird",
1397+
"in": "query",
1398+
"description": "Weird list",
1399+
"required": true,
1400+
"schema": {
1401+
"oneOf": [
13031402
{
13041403
"type": "integer",
13051404
"enum": [
@@ -1313,6 +1412,13 @@
13131412
"yes",
13141413
"no"
13151414
]
1415+
},
1416+
{
1417+
"type": "boolean",
1418+
"enum": [
1419+
true,
1420+
false
1421+
]
13161422
}
13171423
]
13181424
}
@@ -1477,7 +1583,7 @@
14771583
{
14781584
"name": "yesOrNo",
14791585
"in": "query",
1480-
"description": "Booleandefaulting to false",
1586+
"description": "Boolean defaulting to false",
14811587
"schema": {
14821588
"type": "integer",
14831589
"default": 0,
@@ -1562,7 +1668,7 @@
15621668
{
15631669
"name": "yesOrNo",
15641670
"in": "query",
1565-
"description": "Booleandefaulting to true",
1671+
"description": "Boolean defaulting to true",
15661672
"schema": {
15671673
"type": "integer",
15681674
"default": 1,

0 commit comments

Comments
 (0)