diff --git a/src/OpenApiType.php b/src/OpenApiType.php index e0f3217..dd34b01 100644 --- a/src/OpenApiType.php +++ b/src/OpenApiType.php @@ -307,7 +307,9 @@ private static function resolveIdentifier(string $context, array $definitions, s "positive-int" => new OpenApiType(type: "integer", format: "int64", minimum: 1), "negative-int" => new OpenApiType(type: "integer", format: "int64", maximum: -1), "non-positive-int" => new OpenApiType(type: "integer", format: "int64", maximum: 0), - "bool", "boolean", "true", "false" => new OpenApiType(type: "boolean"), + "bool", "boolean" => new OpenApiType(type: "boolean"), + "true" => new OpenApiType(type: "boolean", enum: [true]), + "false" => new OpenApiType(type: "boolean", enum: [false]), "double" => new OpenApiType(type: "number", format: "double"), "float" => new OpenApiType(type: "number", format: "float"), "mixed", "empty", "array" => new OpenApiType(type: "object"), diff --git a/tests/appinfo/routes.php b/tests/appinfo/routes.php index 66638f0..731547d 100644 --- a/tests/appinfo/routes.php +++ b/tests/appinfo/routes.php @@ -42,7 +42,8 @@ ['name' => 'Settings#intParameterWithMinAndMax', 'url' => '/api/{apiVersion}/min-max', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']], ['name' => 'Settings#intParameterWithMin', 'url' => '/api/{apiVersion}/min', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']], ['name' => 'Settings#intParameterWithMax', 'url' => '/api/{apiVersion}/max', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']], - ['name' => 'Settings#listOfIntStringAndBool', 'url' => '/api/{apiVersion}/mixed-list', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']], + ['name' => 'Settings#listOfIntStringAndOneBool', 'url' => '/api/{apiVersion}/mixed-list-one', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']], + ['name' => 'Settings#listOfIntStringAndAllBools', 'url' => '/api/{apiVersion}/mixed-list-all', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']], ['name' => 'Settings#booleanParameterRequired', 'url' => '/api/{apiVersion}/boolean', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']], ['name' => 'Settings#booleanParameterDefaultFalse', 'url' => '/api/{apiVersion}/boolean-false', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']], ['name' => 'Settings#booleanParameterDefaultTrue', 'url' => '/api/{apiVersion}/boolean-true', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']], diff --git a/tests/lib/Controller/SettingsController.php b/tests/lib/Controller/SettingsController.php index acd82aa..c70a299 100644 --- a/tests/lib/Controller/SettingsController.php +++ b/tests/lib/Controller/SettingsController.php @@ -218,7 +218,19 @@ public function intParameterWithMax(int $limit): DataResponse { * * 200: Admin settings updated */ - public function listOfIntStringAndBool($weird): DataResponse { + public function listOfIntStringAndOneBool($weird): DataResponse { + return new DataResponse(); + } + + /** + * A route with a list of 2 integers, 2 strings and 1 boolean + * + * @param 0|1|'yes'|'no'|true|false $weird Weird list + * @return DataResponse, array{}> + * + * 200: Admin settings updated + */ + public function listOfIntStringAndAllBools($weird): DataResponse { return new DataResponse(); } @@ -237,7 +249,7 @@ public function booleanParameterRequired(bool $yesOrNo): DataResponse { /** * A route with boolean defaulting to false * - * @param bool $yesOrNo Booleandefaulting to false + * @param bool $yesOrNo Boolean defaulting to false * @return DataResponse, array{}> * * 200: Admin settings updated @@ -249,7 +261,7 @@ public function booleanParameterDefaultFalse(bool $yesOrNo = false): DataRespons /** * A route with boolean defaulting to true * - * @param bool $yesOrNo Booleandefaulting to true + * @param bool $yesOrNo Boolean defaulting to true * @return DataResponse, array{}> * * 200: Admin settings updated diff --git a/tests/openapi.json b/tests/openapi.json index f0acb00..f8a06f6 100644 --- a/tests/openapi.json +++ b/tests/openapi.json @@ -1273,9 +1273,9 @@ } } }, - "/ocs/v2.php/apps/notifications/api/{apiVersion}/mixed-list": { + "/ocs/v2.php/apps/notifications/api/{apiVersion}/mixed-list-one": { "post": { - "operationId": "settings-list-of-int-string-and-bool", + "operationId": "settings-list-of-int-string-and-one-bool", "summary": "A route with a list of 2 integers, 2 strings and 1 boolean", "description": "This endpoint requires admin access", "tags": [ @@ -1298,8 +1298,107 @@ "schema": { "oneOf": [ { - "type": "boolean" + "type": "integer", + "enum": [ + 0, + 1 + ] }, + { + "type": "string", + "enum": [ + "yes", + "no" + ] + }, + { + "type": "boolean", + "enum": [ + true + ] + } + ] + } + }, + { + "name": "apiVersion", + "in": "path", + "required": true, + "schema": { + "type": "string", + "enum": [ + "v2" + ], + "default": "v2" + } + }, + { + "name": "OCS-APIRequest", + "in": "header", + "description": "Required to be true for the API request to pass", + "required": true, + "schema": { + "type": "boolean", + "default": true + } + } + ], + "responses": { + "200": { + "description": "Admin settings updated", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": {} + } + } + } + } + } + } + } + } + } + }, + "/ocs/v2.php/apps/notifications/api/{apiVersion}/mixed-list-all": { + "post": { + "operationId": "settings-list-of-int-string-and-all-bools", + "summary": "A route with a list of 2 integers, 2 strings and 1 boolean", + "description": "This endpoint requires admin access", + "tags": [ + "settings" + ], + "security": [ + { + "bearer_auth": [] + }, + { + "basic_auth": [] + } + ], + "parameters": [ + { + "name": "weird", + "in": "query", + "description": "Weird list", + "required": true, + "schema": { + "oneOf": [ { "type": "integer", "enum": [ @@ -1313,6 +1412,13 @@ "yes", "no" ] + }, + { + "type": "boolean", + "enum": [ + true, + false + ] } ] } @@ -1477,7 +1583,7 @@ { "name": "yesOrNo", "in": "query", - "description": "Booleandefaulting to false", + "description": "Boolean defaulting to false", "schema": { "type": "integer", "default": 0, @@ -1562,7 +1668,7 @@ { "name": "yesOrNo", "in": "query", - "description": "Booleandefaulting to true", + "description": "Boolean defaulting to true", "schema": { "type": "integer", "default": 1,