From 94bbc4ec7a92ad5f973bfa8c8cebde424a4bc9c8 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Mon, 15 Apr 2024 06:36:52 +0200 Subject: [PATCH] fix(OpenApiType): All floats are doubles Signed-off-by: provokateurin --- src/OpenApiType.php | 4 +- tests/appinfo/routes.php | 1 + tests/lib/Controller/SettingsController.php | 15 ++- tests/openapi-administration.json | 111 +++++++++++++++++++- tests/openapi-full.json | 111 +++++++++++++++++++- 5 files changed, 233 insertions(+), 9 deletions(-) diff --git a/src/OpenApiType.php b/src/OpenApiType.php index 7d03544..ba5f82f 100644 --- a/src/OpenApiType.php +++ b/src/OpenApiType.php @@ -384,8 +384,8 @@ private static function resolveIdentifier(string $context, array $definitions, s "true" => new OpenApiType(type: "boolean", enum: [true]), "false" => new OpenApiType(type: "boolean", enum: [false]), "numeric" => new OpenApiType(type: "number"), - "double" => new OpenApiType(type: "number", format: "double"), - "float" => new OpenApiType(type: "number", format: "float"), + // https://www.php.net/manual/en/language.types.float.php: Both float and double are always stored with double precision + "float", "double" => new OpenApiType(type: "number", format: "double"), "mixed", "empty", "array" => new OpenApiType(type: "object"), "object", "stdClass" => new OpenApiType(type: "object", additionalProperties: true), "null" => new OpenApiType(nullable: true), diff --git a/tests/appinfo/routes.php b/tests/appinfo/routes.php index 6fa6daf..24945ef 100644 --- a/tests/appinfo/routes.php +++ b/tests/appinfo/routes.php @@ -71,5 +71,6 @@ ['name' => 'Settings#passwordConfirmationAttribute', 'url' => '/api/{apiVersion}/passwordConfirmationAttribute', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']], ['name' => 'Settings#oneOf', 'url' => '/api/{apiVersion}/oneOf', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']], ['name' => 'Settings#anyOf', 'url' => '/api/{apiVersion}/anyOf', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']], + ['name' => 'Settings#floatDouble', 'url' => '/api/{apiVersion}/floatDouble', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']], ], ]; diff --git a/tests/lib/Controller/SettingsController.php b/tests/lib/Controller/SettingsController.php index be6f3b4..de9c165 100644 --- a/tests/lib/Controller/SettingsController.php +++ b/tests/lib/Controller/SettingsController.php @@ -502,7 +502,7 @@ public function oneOf(): DataResponse { /** * Route with anyOf * - * @return DataResponse|DataResponse|DataResponse|DataResponse + * @return DataResponse|DataResponse|DataResponse|DataResponse * * 200: OK * 201: CREATED @@ -513,4 +513,17 @@ public function oneOf(): DataResponse { public function anyOf(): DataResponse { return new DataResponse(); } + + /** + * Route with float and double + * + * @return DataResponse|DataResponse + * + * 200: OK + * 201: CREATED + */ + #[PasswordConfirmationRequired] + public function floatDouble(): DataResponse { + return new DataResponse(); + } } diff --git a/tests/openapi-administration.json b/tests/openapi-administration.json index c7ce804..e34f6fa 100644 --- a/tests/openapi-administration.json +++ b/tests/openapi-administration.json @@ -2859,11 +2859,10 @@ "anyOf": [ { "type": "number", - "format": "float" + "format": "double" }, { - "type": "number", - "format": "double" + "type": "number" } ] } @@ -2916,6 +2915,112 @@ } } }, + "/ocs/v2.php/apps/notifications/api/{apiVersion}/floatDouble": { + "post": { + "operationId": "settings-float-double", + "summary": "Route with float and double", + "description": "This endpoint requires admin access\nThis endpoint requires password confirmation", + "tags": [ + "settings" + ], + "security": [ + { + "bearer_auth": [] + }, + { + "basic_auth": [] + } + ], + "parameters": [ + { + "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": "OK", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": { + "type": "number", + "format": "double" + } + } + } + } + } + } + } + }, + "201": { + "description": "CREATED", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": { + "type": "number", + "format": "double" + } + } + } + } + } + } + } + } + } + } + }, "/ocs/v2.php/tests/attribute-ocs/{param}": { "get": { "operationId": "routing-attributeocs-route", diff --git a/tests/openapi-full.json b/tests/openapi-full.json index ec06771..ca7c8a3 100644 --- a/tests/openapi-full.json +++ b/tests/openapi-full.json @@ -2986,11 +2986,10 @@ "anyOf": [ { "type": "number", - "format": "float" + "format": "double" }, { - "type": "number", - "format": "double" + "type": "number" } ] } @@ -3043,6 +3042,112 @@ } } }, + "/ocs/v2.php/apps/notifications/api/{apiVersion}/floatDouble": { + "post": { + "operationId": "settings-float-double", + "summary": "Route with float and double", + "description": "This endpoint requires admin access\nThis endpoint requires password confirmation", + "tags": [ + "settings" + ], + "security": [ + { + "bearer_auth": [] + }, + { + "basic_auth": [] + } + ], + "parameters": [ + { + "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": "OK", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": { + "type": "number", + "format": "double" + } + } + } + } + } + } + } + }, + "201": { + "description": "CREATED", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": { + "type": "number", + "format": "double" + } + } + } + } + } + } + } + } + } + } + }, "/ocs/v2.php/tests/attribute-ocs/{param}": { "get": { "operationId": "routing-attributeocs-route",