From 8cdd986f3bb27bed117a6755edb44c4d1a4bcc53 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Fri, 23 Aug 2024 14:27:16 +0200 Subject: [PATCH] fix(OpenApiType): Clean whitespace in description fields Signed-off-by: provokateurin --- CHANGELOG.md | 2 + src/OpenApiType.php | 2 +- tests/appinfo/routes.php | 1 + tests/lib/Controller/SettingsController.php | 21 ++++ tests/openapi-administration.json | 103 ++++++++++++++++++++ tests/openapi-full.json | 103 ++++++++++++++++++++ 6 files changed, 231 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2174bb2..eb5b0c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Clean whitespace in description fields ## [1.0.0] - 2024-08-20 diff --git a/src/OpenApiType.php b/src/OpenApiType.php index 58ec0ad..0eea15b 100644 --- a/src/OpenApiType.php +++ b/src/OpenApiType.php @@ -104,7 +104,7 @@ enum: [0, 1], $values["enum"] = $this->enum; } if ($this->description !== null && $this->description !== "" && !$isParameter) { - $values["description"] = $this->description; + $values["description"] = Helpers::cleanDocComment($this->description); } if ($this->items !== null) { $values["items"] = $this->items->toArray(); diff --git a/tests/appinfo/routes.php b/tests/appinfo/routes.php index a6180be..04451c7 100644 --- a/tests/appinfo/routes.php +++ b/tests/appinfo/routes.php @@ -83,5 +83,6 @@ ['name' => 'Settings#parameterRequestBody', 'url' => '/api/{apiVersion}/parameterDELETE', 'verb' => 'DELETE', 'postfix' => 'DELETE', 'requirements' => ['apiVersion' => '(v2)']], ['name' => 'Settings#parameterRequestBody', 'url' => '/api/{apiVersion}/parameterPATCH', 'verb' => 'PATCH', 'postfix' => 'PATCH', 'requirements' => ['apiVersion' => '(v2)']], ['name' => 'Settings#objectDefaults', 'url' => '/api/{apiVersion}/objectDefaults', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']], + ['name' => 'Settings#whitespace', 'url' => '/api/{apiVersion}/whitespace', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']], ], ]; diff --git a/tests/lib/Controller/SettingsController.php b/tests/lib/Controller/SettingsController.php index 3b97152..2d1dcc4 100644 --- a/tests/lib/Controller/SettingsController.php +++ b/tests/lib/Controller/SettingsController.php @@ -567,4 +567,25 @@ public function parameterRequestBody(int $simple, array $complex): DataResponse public function objectDefaults(array $empty = [], array $values = ['key' => 'value']): DataResponse { return new DataResponse(); } + + /** + * some + * whitespace + * + * even + * more + * whitespace + * + * @param int $value and this one + * has + * even + * more whitespace + * @return DataResponse}, array{}> + * + * 200: OK + */ + #[PasswordConfirmationRequired] + public function whitespace(int $value): DataResponse { + return new DataResponse(); + } } diff --git a/tests/openapi-administration.json b/tests/openapi-administration.json index 49c6da6..b7dd124 100644 --- a/tests/openapi-administration.json +++ b/tests/openapi-administration.json @@ -4050,6 +4050,109 @@ } } }, + "/ocs/v2.php/apps/notifications/api/{apiVersion}/whitespace": { + "post": { + "operationId": "settings-whitespace", + "summary": "some whitespace", + "description": "even more whitespace\nThis endpoint requires admin access\nThis endpoint requires password confirmation", + "tags": [ + "settings" + ], + "security": [ + { + "bearer_auth": [] + }, + { + "basic_auth": [] + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "value" + ], + "properties": { + "value": { + "type": "integer", + "format": "int64", + "description": "and this one has even more whitespace" + } + } + } + } + } + }, + "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": "object", + "required": [ + "test" + ], + "properties": { + "test": { + "type": "array", + "maxItems": 0 + } + } + } + } + } + } + } + } + } + } + } + } + }, "/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 72e6f18..3e382f6 100644 --- a/tests/openapi-full.json +++ b/tests/openapi-full.json @@ -4192,6 +4192,109 @@ } } }, + "/ocs/v2.php/apps/notifications/api/{apiVersion}/whitespace": { + "post": { + "operationId": "settings-whitespace", + "summary": "some whitespace", + "description": "even more whitespace\nThis endpoint requires admin access\nThis endpoint requires password confirmation", + "tags": [ + "settings" + ], + "security": [ + { + "bearer_auth": [] + }, + { + "basic_auth": [] + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "value" + ], + "properties": { + "value": { + "type": "integer", + "format": "int64", + "description": "and this one has even more whitespace" + } + } + } + } + } + }, + "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": "object", + "required": [ + "test" + ], + "properties": { + "test": { + "type": "array", + "maxItems": 0 + } + } + } + } + } + } + } + } + } + } + } + } + }, "/ocs/v2.php/tests/attribute-ocs/{param}": { "get": { "operationId": "routing-attributeocs-route",