diff --git a/.github/workflows/run-tests-with-coverage.yml b/.github/workflows/run-tests-with-coverage.yml index 4d4ab568..204e51c4 100644 --- a/.github/workflows/run-tests-with-coverage.yml +++ b/.github/workflows/run-tests-with-coverage.yml @@ -24,7 +24,7 @@ jobs: - name: Install Dependencies run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist - name: Execute unit tests via PHPUnit with coverage - run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml + run: php -d zend.exception_ignore_args=0 -d xdebug.collect_params=4 vendor/bin/phpunit --coverage-clover build/logs/clover.xml - name: Export coverage report if: ${{ matrix.php-version == '8.4' }} uses: actions/upload-artifact@v4 diff --git a/lang/en/validation.php b/lang/en/validation.php new file mode 100644 index 00000000..18eeb1f3 --- /dev/null +++ b/lang/en/validation.php @@ -0,0 +1,5 @@ + 'Documentation file is empty or have bad format', +]; diff --git a/resources/views/error.blade.php b/resources/views/error.blade.php index 0b9291cb..de4ceeb3 100644 --- a/resources/views/error.blade.php +++ b/resources/views/error.blade.php @@ -1 +1,14 @@ -{{ $message }} \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 {{ $type }} 🚨🚨 + +--- + +### **Details:** + +{{ $message }} + +### **Error place:** + +{{ $error_place }} +--- \ No newline at end of file diff --git a/src/AutoDocServiceProvider.php b/src/AutoDocServiceProvider.php index fafd6bcb..672c6fe3 100644 --- a/src/AutoDocServiceProvider.php +++ b/src/AutoDocServiceProvider.php @@ -11,6 +11,8 @@ public function boot() { $this->mergeConfigFrom(__DIR__ . '/../config/auto-doc.php', 'auto-doc'); + $this->loadTranslationsFrom(__DIR__ . '/../lang', 'auto-doc'); + $this->publishes([ __DIR__ . '/../config/auto-doc.php' => config_path('auto-doc.php'), ], 'config'); diff --git a/src/Services/SwaggerService.php b/src/Services/SwaggerService.php index 068997ab..50ca44bd 100644 --- a/src/Services/SwaggerService.php +++ b/src/Services/SwaggerService.php @@ -23,6 +23,7 @@ use RonasIT\AutoDoc\Traits\GetDependenciesTrait; use RonasIT\AutoDoc\Validators\SwaggerSpecValidator; use Symfony\Component\HttpFoundation\Response; +use Throwable; use Exception; /** @@ -73,6 +74,10 @@ public function __construct(Container $container) $this->setDriver(); if (config('app.env') === 'testing') { + // client must enter at least `contact.email` to generate a default `info` block + // otherwise an exception will be called + $this->checkEmail(); + $this->container = $container; $this->security = $this->config['security']; @@ -84,6 +89,23 @@ public function __construct(Container $container) $this->driver->saveProcessTmpData($this->data); } + } else { + try { + $this->checkEmail(); + } catch (EmptyContactEmailException $exception) { + $this->data = $this->generateEmptyData( + $this->config['defaults']['error'], + [ + 'message' => $exception->getMessage(), + 'type' => $exception::class, + 'error_place' => $this->getErrorPlace($exception), + ], + ); + + $this->driver->saveProcessTmpData($this->data); + + $this->driver->saveData(); + } } } @@ -134,12 +156,6 @@ protected function setDriver() protected function generateEmptyData(?string $view = null, array $viewData = [], array $license = []): array { - // client must enter at least `contact.email` to generate a default `info` block - // otherwise an exception will be called - if (!empty($this->config['info']) && !Arr::get($this->config, 'info.contact.email')) { - throw new EmptyContactEmailException(); - } - if (empty($view) && !empty($this->config['info'])) { $view = $this->config['info']['description']; } @@ -165,6 +181,13 @@ protected function generateEmptyData(?string $view = null, array $viewData = [], return $data; } + protected function checkEmail(): void + { + if (!empty($this->config['info']) && !Arr::get($this->config, 'info.contact.email')) { + throw new EmptyContactEmailException(); + } + } + protected function generateSecurityDefinition(): ?array { if (empty($this->security)) { @@ -796,18 +819,6 @@ protected function getActionName($uri): string return Str::camel($action); } - /** - * @deprecated method is not in use - * @codeCoverageIgnore - */ - protected function saveTempData() - { - $exportFile = Arr::get($this->config, 'files.temporary'); - $data = json_encode($this->data); - - file_put_contents($exportFile, $data); - } - public function saveProductionData() { if (ParallelTesting::token()) { @@ -831,8 +842,19 @@ public function getDocFileContent() $documentation = $this->driver->getDocumentation(); $this->openAPIValidator->validate($documentation); - } catch (Exception $exception) { - return $this->generateEmptyData($this->config['defaults']['error'], ['message' => $exception->getMessage()]); + } catch (Throwable $exception) { + $message = ($exception instanceof Exception) + ? $exception->getMessage() + : __('validation.unhandled_error_message'); + + return $this->generateEmptyData( + $this->config['defaults']['error'], + [ + 'message' => $message, + 'type' => $exception::class, + 'error_place' => $this->getErrorPlace($exception), + ] + ); } $additionalDocs = config('auto-doc.additional_paths', []); @@ -852,6 +874,18 @@ public function getDocFileContent() return $documentation; } + protected function getErrorPlace(Throwable $exception): string + { + $errorPlaceInTrace = Arr::first($exception->getTrace()); + + $errorPlaceInTrace = implode(', ', Arr::map( + $errorPlaceInTrace, + fn ($value, $key) => $key . '=' . (is_array($value) ? json_encode($value) : $value), + )); + + return $errorPlaceInTrace; + } + protected function camelCaseToUnderScore($input): string { preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches); @@ -973,7 +1007,7 @@ protected function prepareInfo(?string $view = null, array $viewData = [], array if (!empty($view)) { $info['description'] = view($view, $viewData)->render(); } - + return array_merge($this->config['info'], $info); } diff --git a/tests/AutoDocControllerTest.php b/tests/AutoDocControllerTest.php index cf9141d8..8a39cd95 100644 --- a/tests/AutoDocControllerTest.php +++ b/tests/AutoDocControllerTest.php @@ -4,10 +4,11 @@ use Illuminate\Http\Response; use phpmock\phpunit\PHPMock; +use RonasIT\AutoDoc\Tests\Support\Traits\TraceMockTrait; class AutoDocControllerTest extends TestCase { - use PHPMock; + use PHPMock, TraceMockTrait; protected static array $documentation; protected static string $localDriverFilePath; @@ -40,6 +41,24 @@ public function testGetJSONDocumentation() $response->assertJson(self::$documentation); } + public function testGetJSONWithoutEmailDocumentation() + { + config([ + 'auto-doc.info.contact.email' => null, + 'app.env' => 'development', + ]); + + $response = $this->json('get', '/auto-doc/documentation'); + + $response->assertStatus(Response::HTTP_OK); + + $content = $response->json(); + + $this->mockGetTrace($content['info']['description']); + + $this->assertEqualsJsonFixture('documentation_without_email', $content); + } + public function testGetJSONDocumentationWithAdditionalPaths() { config([ diff --git a/tests/SwaggerServiceTest.php b/tests/SwaggerServiceTest.php index 04440fa6..8859e294 100644 --- a/tests/SwaggerServiceTest.php +++ b/tests/SwaggerServiceTest.php @@ -17,10 +17,11 @@ use RonasIT\AutoDoc\Tests\Support\Traits\SwaggerServiceMockTrait; use RonasIT\AutoDoc\Tests\Support\Traits\SwaggerServiceTestingTrait; use stdClass; +use RonasIT\AutoDoc\Tests\Support\Traits\TraceMockTrait; class SwaggerServiceTest extends TestCase { - use SwaggerServiceMockTrait, SwaggerServiceTestingTrait; + use SwaggerServiceMockTrait, SwaggerServiceTestingTrait, TraceMockTrait; public function testConstructorInvalidConfigVersion() { @@ -186,14 +187,17 @@ public static function getConstructorInvalidTmpData(): array [ 'tmpDoc' => 'documentation/invalid_format__missing_local_ref', 'fixture' => 'invalid_format_missing_local_ref.html', + 'eight_dot_four_fixture' => 'php_8.4_invalid_format_missing_local_ref.html' ], [ 'tmpDoc' => 'documentation/invalid_format__missing_external_ref', 'fixture' => 'invalid_format_missing_external_ref.html', + 'eight_dot_four_fixture' => 'php_8.4_invalid_format_missing_external_ref.html' ], [ 'tmpDoc' => 'documentation/invalid_format__missing_ref_file', 'fixture' => 'invalid_format_missing_ref_file.html', + 'eight_dot_four_fixture' => 'php_8.4_invalid_format_missing_ref_file.html' ], [ 'tmpDoc' => 'documentation/invalid_format__invalid_schema_type', @@ -223,6 +227,10 @@ public static function getConstructorInvalidTmpData(): array 'tmpDoc' => 'documentation/invalid_format__response__invalid_items', 'fixture' => 'invalid_format_response_invalid_items.html', ], + [ + 'tmpDoc' => 'documentation/tmp_data_incorrect_documentation_structure_request', + 'fixture' => 'invalid_format_incorrect_documentation_structure_request.html', + ], ]; } @@ -230,12 +238,21 @@ public static function getConstructorInvalidTmpData(): array public function testGetDocFileContentInvalidTmpData( string $tmpDoc, string $fixture, + ?string $eight_dot_four_fixture = null, ) { $this->mockDriverGetDocumentation($this->getJsonFixture($tmpDoc)); $content = app(SwaggerService::class)->getDocFileContent(); - $this->assertEqualsFixture($fixture, $content['info']['description']); + $this->mockGetTrace($content['info']['description']); + + if (!empty($eight_dot_four_fixture) + && version_compare(PHP_VERSION, '8.4.0', '>=')) { + $this->assertEqualsFixture($eight_dot_four_fixture, $content['info']['description']); + } else { + $this->assertEqualsFixture($fixture, $content['info']['description']); + } + } public function testEmptyContactEmail() @@ -243,8 +260,9 @@ public function testEmptyContactEmail() config(['auto-doc.info.contact.email' => null]); $this->expectException(EmptyContactEmailException::class); + $this->expectExceptionMessage('Please fill the `info.contact.email` field in the app-doc.php config file.'); - app(SwaggerService::class); + app(SwaggerService::class)->getDocFileContent(); } public static function getAddEmptyData(): array diff --git a/tests/TestCase.php b/tests/TestCase.php index fde97e94..89d4cc0f 100755 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -87,7 +87,7 @@ public function assertEqualsJsonFixture(string $fixtureName, $data, bool $export public function assertEqualsFixture(string $fixtureName, $data, bool $exportMode = false): void { if ($exportMode || $this->globalExportMode) { - $this->exportContent($fixtureName, $data); + $this->exportContent($data, $fixtureName); } $this->assertEquals($this->getFixture($fixtureName), $data); diff --git a/tests/fixtures/AutoDocControllerTest/documentation__non_json.txt b/tests/fixtures/AutoDocControllerTest/documentation__non_json.txt deleted file mode 100644 index ba9562d7..00000000 --- a/tests/fixtures/AutoDocControllerTest/documentation__non_json.txt +++ /dev/null @@ -1,90 +0,0 @@ -openapi: "3.1.0", -info: - description: "This is a sample server Petstore server." - version: "1.0.0" - title: "Swagger Petstore 2.0" - termsOfService: "http://swagger.io/terms/" - contact: - email: "apiteam@swagger.io" - license: - name: "Apache 2.0" - url: "http://www.apache.org/licenses/LICENSE-2.0.html" -host: "petstore.swagger.io" -basePath: "/v2" -tags: -- name: "pet" - description: "Everything about your Pets" - externalDocs: - description: "Find out more" - url: "http://swagger.io" -- name: "store" - description: "Access to Petstore orders" -- name: "user" - description: "Operations about user" - externalDocs: - description: "Find out more about our store" - url: "http://swagger.io" -schemes: -- "https" -- "http" -paths: - /pet: - post: - tags: - - "pet" - summary: "Add a new pet to the store" - description: "" - operationId: "addPet" - - parameters: - - in: "body" - name: "body" - description: "Pet object that needs to be added to the store" - required: true - schema: - $ref: "#/definitions/Pet" - responses: - "405": - description: "Invalid input" - security: - - petstore_auth: - - "write:pets" - - "read:pets" -definitions: - Pet: - type: "object" - required: - - "name" - - "photoUrls" - properties: - id: - type: "integer" - format: "int64" - category: - $ref: "#/definitions/Category" - name: - type: "string" - example: "doggie" - photoUrls: - type: "array" - xml: - name: "photoUrl" - wrapped: true - items: - type: "string" - tags: - type: "array" - xml: - name: "tag" - wrapped: true - items: - $ref: "#/definitions/Tag" - status: - type: "string" - description: "pet status in the store" - enum: - - "available" - - "pending" - - "sold" - xml: - name: "Pet" diff --git a/tests/fixtures/AutoDocControllerTest/documentation_without_email.json b/tests/fixtures/AutoDocControllerTest/documentation_without_email.json new file mode 100644 index 00000000..382b20c2 --- /dev/null +++ b/tests/fixtures/AutoDocControllerTest/documentation_without_email.json @@ -0,0 +1,25 @@ +{ + "openapi": "3.1.0", + "servers": [ + { + "url": "http:\/\/localhost" + } + ], + "paths": [], + "components": { + "schemas": [] + }, + "info": { + "description": "# ❗️ **ERROR** ❗️\n\n## 🚨🚨 RonasIT\\AutoDoc\\Exceptions\\EmptyContactEmailException 🚨🚨\n\n---\n\n### **Details:**\n\nPlease fill the `info.contact.email` field in the app-doc.php config file.\n\n### **Error place:**\n\nfile=\/src\/Services\/SwaggerService.php, line=999, function=checkEmail, class=RonasIT\\AutoDoc\\Services\\SwaggerService, type=->, args=[]\n---", + "version": "0.0.0", + "title": "Name of Your Application", + "termsOfService": "", + "contact": { + "email": null + }, + "license": { + "name": "", + "url": "" + } + } +} \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/documentation/tmp_data_incorrect_documentation_structure_request.json b/tests/fixtures/SwaggerServiceTest/documentation/tmp_data_incorrect_documentation_structure_request.json new file mode 100644 index 00000000..df9611dd --- /dev/null +++ b/tests/fixtures/SwaggerServiceTest/documentation/tmp_data_incorrect_documentation_structure_request.json @@ -0,0 +1,400 @@ +{ + "openapi": "3.1.0", + "servers": [ + { + "url": "https:\/\/localhost" + } + ], + "paths": { + "\/v{version}\/media": { + "post": { + "tags": [ + "v{version}" + ], + "consumes": [ + "application\/json" + ], + "produces": [ + "application\/json" + ], + "parameters": [ + { + "in": "path", + "name": "version", + "description": "in: 0.1,0.2", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "201": { + "description": "Created", + "content": { + "application\/json": { + "schema": { + "type": "object", + "$ref": "#\/components\/schemas\/postV{version}media201ResponseObject" + }, + "example": { + "id": 20, + "link": "https:\/\/localhost\/v0.2\/media\/20\/content", + "created_at": "2018-11-11T11:11:11.000000Z", + "preview": { + "id": 19, + "link": "https:\/\/localhost\/v0.2\/media\/19\/content", + "created_at": "2018-11-11T11:11:11.000000Z", + "blur_hash": null + }, + "blur_hash": "L00000fQfQfQfQfQfQfQfQfQfQfQ" + } + } + } + }, + "401": { + "description": "Unauthorized", + "content": { + "application\/json": { + "schema": { + "type": "object", + "$ref": "#\/components\/schemas\/postV{version}media401ResponseObject" + }, + "example": { + "message": "Unauthenticated." + } + } + } + } + }, + "security": [], + "description": "", + "deprecated": false, + "requestBody": { + "content": { + "application\/json": { + "schema": { + "$ref": "#\/components\/schemas\/v{version}mediaObject" + } + } + }, + "description": "", + "required": true + }, + "summary": "create media" + } + }, + "\/v{version}\/media\/{id}\/content": { + "get": { + "tags": [ + "v{version}" + ], + "consumes": [ + "application\/json" + ], + "produces": [ + "image\/jpeg", + "application\/json" + ], + "parameters": [ + { + "in": "path", + "name": "version", + "description": "in: 0.1,0.2", + "required": true, + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "id", + "description": "regexp: [0-9]+", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "Operation successfully done", + "content": { + "image\/jpeg": { + "schema": { + "type": "object", + "$ref": "#\/components\/schemas\/getV{version}media{id}content200ResponseObject" + }, + "example": "[]" + } + } + }, + "429": { + "description": "Too Many Requests", + "content": { + "application\/json": { + "schema": { + "type": "object", + "$ref": "#\/components\/schemas\/getV{version}media{id}content429ResponseObject" + }, + "example": { + "message": "Too Many Attempts." + } + } + } + }, + "403": { + "description": "Forbidden", + "content": { + "application\/json": { + "schema": { + "type": "object", + "$ref": "#\/components\/schemas\/getV{version}media{id}content403ResponseObject" + }, + "example": { + "message": "This action is unauthorized." + } + } + } + }, + "404": { + "description": "This entity not found", + "content": { + "application\/json": { + "schema": { + "type": "object", + "$ref": "#\/components\/schemas\/getV{version}media{id}content404ResponseObject" + }, + "example": { + "message": "Media does not exist" + } + } + } + } + }, + "security": [], + "description": "", + "deprecated": false, + "summary": "get content" + } + }, + "\/media\/{id}": { + "delete": { + "tags": [ + "media" + ], + "consumes": [ + "application\/json" + ], + "produces": [ + "application\/json" + ], + "parameters": [ + { + "in": "path", + "name": "id", + "description": "", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "404": { + "description": "This entity not found", + "content": { + "application\/json": { + "schema": { + "type": "object", + "$ref": "#\/components\/schemas\/deleteMedia{id}404ResponseObject" + }, + "example": { + "message": "Not found." + } + } + } + } + }, + "security": [], + "description": "", + "deprecated": false, + "summary": "delete media" + } + }, + "\/media\/bulk": { + "post": { + "tags": [ + "media" + ], + "consumes": [ + "application\/json" + ], + "produces": [ + "application\/json" + ], + "parameters": [], + "responses": { + "404": { + "description": "This entity not found", + "content": { + "application\/json": { + "schema": { + "type": "object", + "$ref": "#\/components\/schemas\/postMediabulk404ResponseObject" + }, + "example": { + "message": "Not found." + } + } + } + } + }, + "security": [], + "description": "", + "deprecated": false, + "requestBody": { + "content": { + "application\/json": { + "schema": { + "$ref": "#\/components\/schemas\/mediabulkObject" + } + } + }, + "description": "", + "required": true + }, + "summary": "bulk create media" + } + }, + "\/media": { + "get": { + "tags": [ + "media" + ], + "consumes": [ + "application\/json" + ], + "produces": [ + "application\/json" + ], + "parameters": [ + { + "in": "query", + "name": "page", + "description": "integer", + "schema": { + "type": "integer" + } + }, + { + "in": "query", + "name": "per_page", + "description": "integer", + "schema": { + "type": "integer" + } + }, + { + "in": "query", + "name": "all", + "description": "integer", + "schema": { + "type": "integer" + } + }, + { + "in": "query", + "name": "query", + "description": "string", + "schema": { + "type": "string" + } + }, + { + "in": "query", + "name": "order_by", + "description": "string, in:link,name", + "schema": { + "type": "string" + } + }, + { + "in": "query", + "name": "desc", + "description": "boolean", + "schema": { + "type": "boolean" + } + }, + { + "in": "query", + "name": "name", + "description": "string", + "schema": { + "type": "string" + } + } + ], + "responses": { + "404": { + "description": "This entity not found", + "content": { + "application\/json": { + "schema": { + "type": "object", + "$ref": "#\/components\/schemas\/getMedia404ResponseObject" + }, + "example": { + "message": "Not found." + } + } + } + } + }, + "security": [], + "description": "", + "deprecated": false, + "summary": "search media" + }, + "post": { + "tags": [ + "media" + ], + "consumes": [ + "application\/json" + ], + "produces": [ + "application\/json" + ], + "parameters": [], + "content": { + "application\/json": { + "schema": { + "type": "object", + "$ref": "#\/components\/schemas\/postMedia404ResponseObject" + }, + "example": { + "message": "Not found." + } + } + } + } + }, + "security": [], + "description": "", + "deprecated": false, + "requestBody": { + "content": { + "application\/json": { + "schema": { + "$ref": "#\/components\/schemas\/mediaObject" + } + } + }, + "description": "", + "required": true + }, + "summary": "create media" + } +}}, "components": {"schemas": {"v{version}mediaObject": {"type": "object", "properties": {"file": {"type": "string", "description": "file, max:5120, mimes:jpg,jpeg,bmp,png,heic"}, "meta": {"type": "object", "description": ""}, "is_public": {"type": "boolean", "description":""}, "type": {"type": "string","description": "in:avatar,cover"}}, "required":["file"], "example": {"file": "[uploaded_file]"}},"postV{version}media201ResponseObject": {"type": "object", "properties": {"id": {"type": "integer"}, "link":{"type": "string"}, "created_at": {"type": "string"}, "preview": {"type": "array", "nullable": true}, "blur_hash": {"type": "string"}}}, "postV{version}media401ResponseObject": {"type": "object", "properties": {"message": {"type": "string"}}}, "getV{version}media{id}content200ResponseObject": {"type": "object", "properties":[]}, "getV{version}media{id}content429ResponseObject": {"type": "object", "properties": {"message": {"type": "string"}}}, "getV{version}media{id}content403ResponseObject": {"type": "object", "properties": {"message": {"type": "string"}}}, "getV{version}media{id}content404ResponseObject": {"type": "object", "properties": {"message": {"type": "string"}}}, "deleteMedia{id}404ResponseObject": {"type": "object", "properties": {"message": {"type": "string"}}}, "mediabulkObject": {"type": "object", "properties": {"media": {"type": "object", "description": ""}, "media.*": {"type": "object", "description": ""}, "media.*.file": {"type": "string", "description": "file, max:5120, mimes:jpg,jpeg,bmp,png,heic"}, "media.*.meta":{"type": "object", "description": ""},"media.*.is_public": {"type": "boolean", "description": ""}}, "required":["media", "media.*.file"], "example": {"media":[{"meta":["test1"], "file": "[uploaded_file]"}, {"meta":["test2"], "file": "[uploaded_file]"}]}}, "postMediabulk404ResponseObject": {"type": "object","properties": {"message": {"type": "string"}}}, "getMedia404ResponseObject": {"type": "object","properties": {"message": {"type": "string"}}}, "mediaObject": {"type": "object","properties": {"file": {"type": "string","description": "file, max:5120, mimes:jpg,jpeg,bmp,png,heic"}, "meta": {"type":"object", "description": ""}, "is_public": {"type": "boolean", "description": ""}, "type": {"type": "string", "description": "in:avatar,cover"}}, "required":["file"], "example": {"file": "[uploaded_file]"}},"postMedia404ResponseObject": {"type": "object", "properties": {"message": {"type": "string"}}}}}, "info": {"description": "This is automatically collected documentation", "version": "0.0.0", "title": "Laravel", "termsOfService": "", "contact": {"email": "azabolotnikov@ronasit.com"}}} \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_contact_email_format.html b/tests/fixtures/SwaggerServiceTest/invalid_contact_email_format.html new file mode 100644 index 00000000..8162a684 --- /dev/null +++ b/tests/fixtures/SwaggerServiceTest/invalid_contact_email_format.html @@ -0,0 +1,11 @@ +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\EmptyContactEmailException 🚨🚨 + +--- + +### **Details:** + +Please fill the `info.contact.email` field in the app-doc.php config file. + +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_array_parameter_no_items.html b/tests/fixtures/SwaggerServiceTest/invalid_format_array_parameter_no_items.html index 5ee5a195..497ab12d 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_array_parameter_no_items.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_array_parameter_no_items.html @@ -1 +1,14 @@ -Validation failed. paths./users.post.parameters.0 is an array, so it must include an 'items' field. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\InvalidSwaggerSpecException 🚨🚨 + +--- + +### **Details:** + +Validation failed. paths./users.post.parameters.0 is an array, so it must include an 'items' field. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateType, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[{"type":"array"},["array","boolean","integer","number","string","object","null","undefined"],"paths.\/users.post.parameters.0"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_array_response_body_no_items.html b/tests/fixtures/SwaggerServiceTest/invalid_format_array_response_body_no_items.html index daf4fee1..ca505eae 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_array_response_body_no_items.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_array_response_body_no_items.html @@ -1 +1,14 @@ -Validation failed. paths./users.get.responses.200.schema is an array, so it must include an 'items' field. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\InvalidSwaggerSpecException 🚨🚨 + +--- + +### **Details:** + +Validation failed. paths./users.get.responses.200.schema is an array, so it must include an 'items' field. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateType, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[{"type":"array"},["array","boolean","integer","number","string","object","null","undefined","file"],"paths.\/users.get.responses.200.schema"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_array_response_header_no_items.html b/tests/fixtures/SwaggerServiceTest/invalid_format_array_response_header_no_items.html index caf830c0..f7edcb4a 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_array_response_header_no_items.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_array_response_header_no_items.html @@ -1 +1,14 @@ -Validation failed. paths./users.get.responses.default.headers.Last-Modified is an array, so it must include an 'items' field. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\InvalidSwaggerSpecException 🚨🚨 + +--- + +### **Details:** + +Validation failed. paths./users.get.responses.default.headers.Last-Modified is an array, so it must include an 'items' field. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateType, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[{"type":"array"},["array","boolean","integer","number","string","object","date","double"],"paths.\/users.get.responses.default.headers.Last-Modified"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_body_and_form_params.html b/tests/fixtures/SwaggerServiceTest/invalid_format_body_and_form_params.html index 389e03a0..4260f82c 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_body_and_form_params.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_body_and_form_params.html @@ -1 +1,14 @@ -Validation failed. Operation 'paths./users/{username}.post' has body and formData parameters. Only one or the other is allowed. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\InvalidSwaggerSpecException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Operation 'paths./users/{username}.post' has body and formData parameters. Only one or the other is allowed. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateBodyParameters, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[[{"name":"username","in":"path","required":true,"schema":{"type":"string"}},{"name":"foo","in":"body","schema":{"type":"number"}},{"name":"bar","in":"formData","schema":{"type":"number"}}],"paths.\/users\/{username}.post"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_duplicate_header_params.html b/tests/fixtures/SwaggerServiceTest/invalid_format_duplicate_header_params.html index 0a770041..d97ab16a 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_duplicate_header_params.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_duplicate_header_params.html @@ -1 +1,14 @@ -Validation failed. Operation 'paths./users/{username}.get' has multiple in:header parameters with name:foo. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\DuplicateParamException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Operation 'paths./users/{username}.get' has multiple in:header parameters with name:foo. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateParamsUnique, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[[{"name":"username","in":"path","required":true,"schema":{"type":"string"}},{"name":"foo","in":"header","schema":{"type":"string"},"required":false},{"name":"username","in":"header","schema":{"type":"string"}},{"name":"username","in":"body","schema":{"type":"string"}},{"name":"foo","in":"header","schema":{"type":"number"},"required":true}],"paths.\/users\/{username}.get"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_duplicate_operation_id.html b/tests/fixtures/SwaggerServiceTest/invalid_format_duplicate_operation_id.html index 25dbb9bc..27cb7ff9 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_duplicate_operation_id.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_duplicate_operation_id.html @@ -1 +1,14 @@ -Validation failed. Found multiple fields 'paths.*.*.operationId' with values: addPet. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\DuplicateFieldException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Found multiple fields 'paths.*.*.operationId' with values: addPet. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateOperationIdsUnique, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_duplicate_path_params.html b/tests/fixtures/SwaggerServiceTest/invalid_format_duplicate_path_params.html index a03ed69e..b30a1771 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_duplicate_path_params.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_duplicate_path_params.html @@ -1 +1,14 @@ -Validation failed. Operation 'paths./users/{username}.get' has multiple in:path parameters with name:username. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\DuplicateParamException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Operation 'paths./users/{username}.get' has multiple in:path parameters with name:username. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateParamsUnique, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[[{"name":"username","in":"path","required":true,"schema":{"type":"string"}},{"name":"bar","in":"header","schema":{"type":"string"},"required":false},{"name":"username","in":"header","schema":{"type":"string"}},{"name":"username","in":"body","schema":{"type":"string"}},{"name":"username","in":"path","schema":{"type":"number"},"required":true}],"paths.\/users\/{username}.get"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_duplicate_path_placeholders.html b/tests/fixtures/SwaggerServiceTest/invalid_format_duplicate_path_placeholders.html index 5e443501..43432d5b 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_duplicate_path_placeholders.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_duplicate_path_placeholders.html @@ -1 +1,14 @@ -Validation failed. Path '/users/{username}/profile/{username}/image/{img_id}' has multiple path placeholders with name: username. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\DuplicatePathPlaceholderException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Path '/users/{username}/profile/{username}/image/{img_id}' has multiple path placeholders with name: username. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validatePathParameters, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[[{"name":"username","in":"path","required":true,"schema":{"type":"string"}},{"name":"img_id","in":"path","required":true,"schema":{"type":"number"}}],"\/users\/{username}\/profile\/{username}\/image\/{img_id}","paths.\/users\/{username}\/profile\/{username}\/image\/{img_id}.get"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_duplicate_tag.html b/tests/fixtures/SwaggerServiceTest/invalid_format_duplicate_tag.html index 99344580..cb8ba38a 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_duplicate_tag.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_duplicate_tag.html @@ -1 +1,14 @@ -Validation failed. Found multiple fields 'tags.*.name' with values: user. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\DuplicateFieldException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Found multiple fields 'tags.*.name' with values: user. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateTagsUnique, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_file_invalid_consumes.html b/tests/fixtures/SwaggerServiceTest/invalid_format_file_invalid_consumes.html index 22b966e5..0bf41111 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_file_invalid_consumes.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_file_invalid_consumes.html @@ -1 +1,14 @@ -Validation failed. Operation 'paths./users/{username}/profile/image.post' has body and formData parameters. Only one or the other is allowed. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\InvalidSwaggerSpecException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Operation 'paths./users/{username}/profile/image.post' has body and formData parameters. Only one or the other is allowed. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateFormDataConsumes, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[{"parameters":[{"name":"username","in":"path","schema":{"type":"string"},"required":true},{"name":"image","in":"formData","schema":{"type":"file"}}],"consumes":["application\/octet-stream","image\/png"],"responses":{"default":{"description":"hello world"}}},"paths.\/users\/{username}\/profile\/image.post"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_file_no_consumes.html b/tests/fixtures/SwaggerServiceTest/invalid_format_file_no_consumes.html index 22b966e5..4cae7ff3 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_file_no_consumes.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_file_no_consumes.html @@ -1 +1,14 @@ -Validation failed. Operation 'paths./users/{username}/profile/image.post' has body and formData parameters. Only one or the other is allowed. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\InvalidSwaggerSpecException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Operation 'paths./users/{username}/profile/image.post' has body and formData parameters. Only one or the other is allowed. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateFormDataConsumes, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[{"parameters":[{"name":"username","in":"path","schema":{"type":"string"},"required":true},{"name":"image","in":"formData","schema":{"type":"file"}}],"responses":{"default":{"description":"hello world"}}},"paths.\/users\/{username}\/profile\/image.post"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_incorrect_documentation_structure_request.html b/tests/fixtures/SwaggerServiceTest/invalid_format_incorrect_documentation_structure_request.html new file mode 100644 index 00000000..51d4f69d --- /dev/null +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_incorrect_documentation_structure_request.html @@ -0,0 +1,14 @@ +# ❗️ **ERROR** ❗️ + +## 🚨🚨 TypeError 🚨🚨 + +--- + +### **Details:** + +Documentation file is empty or have bad format + +### **Error place:** + +file=/src/Services/SwaggerService.php, line=999, function=getDocumentation, class=MockClass, type=->, args=[] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_invalid_schema_type.html b/tests/fixtures/SwaggerServiceTest/invalid_format_invalid_schema_type.html index a6c49ec3..855ad952 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_invalid_schema_type.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_invalid_schema_type.html @@ -1 +1,14 @@ -Validation failed. Field 'paths./users.get.responses.200.schema.type' has an invalid value: something. Allowed values: array, boolean, integer, number, string, object, null, undefined, file. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\InvalidFieldValueException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Field 'paths./users.get.responses.200.schema.type' has an invalid value: something. Allowed values: array, boolean, integer, number, string, object, null, undefined, file. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateType, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[{"type":"something","items":{"user":{"type":"string"}}},["array","boolean","integer","number","string","object","null","undefined","file"],"paths.\/users.get.responses.200.schema"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_invalid_value_parameter_in.html b/tests/fixtures/SwaggerServiceTest/invalid_format_invalid_value_parameter_in.html index 68a11aac..e3085d3f 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_invalid_value_parameter_in.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_invalid_value_parameter_in.html @@ -1 +1,14 @@ -Validation failed. Field 'paths./auth/login.post.parameters.0.in' has an invalid value: invalid_in. Allowed values: body, formData, query, path, header. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\InvalidFieldValueException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Field 'paths./auth/login.post.parameters.0.in' has an invalid value: invalid_in. Allowed values: body, formData, query, path, header. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateFieldValue, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=["paths.\/auth\/login.post.parameters.0.in",["body","formData","query","path","header"]] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_invalid_value_path.html b/tests/fixtures/SwaggerServiceTest/invalid_format_invalid_value_path.html index 96de275c..1c19c7f3 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_invalid_value_path.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_invalid_value_path.html @@ -1 +1,14 @@ -Validation failed. Incorrect 'paths.users'. Paths should only have path names that starts with `/`. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\InvalidPathException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Incorrect 'paths.users'. Paths should only have path names that starts with `/`. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validatePaths, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_invalid_value_status_code.html b/tests/fixtures/SwaggerServiceTest/invalid_format_invalid_value_status_code.html index 07d68cac..d332bd91 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_invalid_value_status_code.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_invalid_value_status_code.html @@ -1 +1,14 @@ -Validation failed. Operation at 'paths./users.get.responses.8888' should only have three-digit status codes, `default`, and vendor extensions (`x-*`) as properties. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\InvalidStatusCodeException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Operation at 'paths./users.get.responses.8888' should only have three-digit status codes, `default`, and vendor extensions (`x-*`) as properties. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateResponse, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[{"description":"hello world"},"8888","paths.\/users.get"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_external_ref.html b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_external_ref.html index 2eace1cf..602f5aed 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_external_ref.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_external_ref.html @@ -1 +1,14 @@ -Validation failed. Ref 'authloginObject' is used in $ref but not defined in 'tests/fixtures/SwaggerServiceTest/documentation/with_definitions.json' file. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\MissingExternalRefException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Ref 'authloginObject' is used in $ref but not defined in 'tests/fixtures/SwaggerServiceTest/documentation/with_definitions.json' file. + +### **Error place:** + +function=RonasIT\AutoDoc\Validators\{closure}, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=["tests\/fixtures\/SwaggerServiceTest\/documentation\/with_definitions.json#\/definitions\/authloginObject","$ref"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_definition_type.html b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_definition_type.html index e2bd233c..a71f2c82 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_definition_type.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_definition_type.html @@ -1 +1,14 @@ -Validation failed. 'components.schemas.authloginObject' should have required fields: type. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\MissingFieldException 🚨🚨 + +--- + +### **Details:** + +Validation failed. 'components.schemas.authloginObject' should have required fields: type. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateFieldsPresent, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[["type"],"components.schemas.authloginObject"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_header_type.html b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_header_type.html index 28a5c4ff..16511e5e 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_header_type.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_header_type.html @@ -1 +1,14 @@ -Validation failed. 'paths./user/login.get.responses.200.headers.X-Rate-Limit' should have required fields: type. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\MissingFieldException 🚨🚨 + +--- + +### **Details:** + +Validation failed. 'paths./user/login.get.responses.200.headers.X-Rate-Limit' should have required fields: type. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateFieldsPresent, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[["type"],"paths.\/user\/login.get.responses.200.headers.X-Rate-Limit"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_info_version.html b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_info_version.html index dc3dac19..f577df16 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_info_version.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_info_version.html @@ -1 +1,14 @@ -Validation failed. 'info' should have required fields: version. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\MissingFieldException 🚨🚨 + +--- + +### **Details:** + +Validation failed. 'info' should have required fields: version. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateFieldsPresent, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[["title","version"],"info"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_items_type.html b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_items_type.html index 0e470070..347e99c6 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_items_type.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_items_type.html @@ -1 +1,14 @@ -Validation failed. 'paths./pet/findByStatus.get.parameters.0.schema.items' should have required fields: type. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\MissingFieldException 🚨🚨 + +--- + +### **Details:** + +Validation failed. 'paths./pet/findByStatus.get.parameters.0.schema.items' should have required fields: type. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateFieldsPresent, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[["type"],"paths.\/pet\/findByStatus.get.parameters.0.schema.items"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_operation_responses.html b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_operation_responses.html index 5ebd060b..51f44d2a 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_operation_responses.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_operation_responses.html @@ -1 +1,14 @@ -Validation failed. 'paths./auth/login.post' should have required fields: responses. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\MissingFieldException 🚨🚨 + +--- + +### **Details:** + +Validation failed. 'paths./auth/login.post' should have required fields: responses. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateFieldsPresent, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[["responses"],"paths.\/auth\/login.post"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_parameter_in.html b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_parameter_in.html index 996315fa..228657f6 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_parameter_in.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_parameter_in.html @@ -1 +1,14 @@ -Validation failed. 'paths./auth/login.post.parameters.0' should have required fields: in. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\MissingFieldException 🚨🚨 + +--- + +### **Details:** + +Validation failed. 'paths./auth/login.post.parameters.0' should have required fields: in. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateFieldsPresent, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[["in","name"],"paths.\/auth\/login.post.parameters.0"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_paths.html b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_paths.html index c68f537e..8c3f08cc 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_paths.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_paths.html @@ -1 +1,14 @@ -Validation failed. '' should have required fields: paths. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\MissingFieldException 🚨🚨 + +--- + +### **Details:** + +Validation failed. '' should have required fields: paths. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateFieldsPresent, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[["openapi","info","paths"]] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_response_description.html b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_response_description.html index c272c3d5..5b10e3df 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_response_description.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_response_description.html @@ -1 +1,14 @@ -Validation failed. 'paths./auth/login.post.responses.200' should have required fields: description. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\MissingFieldException 🚨🚨 + +--- + +### **Details:** + +Validation failed. 'paths./auth/login.post.responses.200' should have required fields: description. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateFieldsPresent, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[["description"],"paths.\/auth\/login.post.responses.200"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_tag_name.html b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_tag_name.html index 54dece06..782ca34b 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_tag_name.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_field_tag_name.html @@ -1 +1,14 @@ -Validation failed. 'tags.0' should have required fields: name. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\MissingFieldException 🚨🚨 + +--- + +### **Details:** + +Validation failed. 'tags.0' should have required fields: name. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateFieldsPresent, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[["name"],"tags.0"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_local_ref.html b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_local_ref.html index 13d8fc9a..30a369f9 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_local_ref.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_local_ref.html @@ -1 +1,14 @@ -Validation failed. Ref 'loginObject' is used in $ref but not defined in 'definitions' field. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\MissingLocalRefException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Ref 'loginObject' is used in $ref but not defined in 'definitions' field. + +### **Error place:** + +function=RonasIT\AutoDoc\Validators\{closure}, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=["#\/definitions\/loginObject","$ref"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_path_parameter.html b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_path_parameter.html index 46a71416..be45334f 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_path_parameter.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_path_parameter.html @@ -1 +1,14 @@ -Validation failed. Path parameters cannot be optional. Set required=true for the 'username' parameters at operation 'paths./users.get'. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\InvalidSwaggerSpecException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Path parameters cannot be optional. Set required=true for the 'username' parameters at operation 'paths./users.get'. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validatePathParameters, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[[{"name":"username","in":"path","required":true,"schema":{"type":"string"}},{"name":"bar","in":"header","schema":{"type":"string"},"required":false},{"name":"username","in":"header","schema":{"type":"string"}},{"name":"username","in":"body","schema":{"type":"string"}}],"\/users","paths.\/users.get"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_ref_file.html b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_ref_file.html index a7794cf8..e9a773e7 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_missing_ref_file.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_missing_ref_file.html @@ -1 +1,14 @@ -Validation failed. Filename 'invalid-filename.json' is used in $ref but file doesn't exist. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\MissingRefFileException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Filename 'invalid-filename.json' is used in $ref but file doesn't exist. + +### **Error place:** + +function=RonasIT\AutoDoc\Validators\{closure}, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=["invalid-filename.json","$ref"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_multiple_body_params.html b/tests/fixtures/SwaggerServiceTest/invalid_format_multiple_body_params.html index 3eaab7d4..a40ab989 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_multiple_body_params.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_multiple_body_params.html @@ -1 +1,14 @@ -Validation failed. Operation 'paths./users/{username}.get' has 2 body parameters. Only one is allowed. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\InvalidSwaggerSpecException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Operation 'paths./users/{username}.get' has 2 body parameters. Only one is allowed. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateBodyParameters, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[[{"name":"username","in":"path","required":true,"schema":{"type":"string"}},{"name":"bar","in":"header","schema":{"type":"number"},"required":true},{"name":"foo","in":"body","required":true,"schema":{"type":"number"}},{"name":"foo2","in":"body","schema":{"type":"number"}}],"paths.\/users\/{username}.get"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_no_path_params.html b/tests/fixtures/SwaggerServiceTest/invalid_format_no_path_params.html index 543b42ff..d1450f4c 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_no_path_params.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_no_path_params.html @@ -1 +1,14 @@ -Validation failed. Operation 'paths./users/{username}/{foo}.get' has no params for placeholders: username, foo. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\MissingPathParamException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Operation 'paths./users/{username}/{foo}.get' has no params for placeholders: username, foo. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validatePathParameters, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[[{"name":"username","in":"header","required":true,"schema":{"type":"number"}},{"name":"foo","in":"body","schema":{"type":"number"}}],"\/users\/{username}\/{foo}","paths.\/users\/{username}\/{foo}.get"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_path_param_no_placeholder.html b/tests/fixtures/SwaggerServiceTest/invalid_format_path_param_no_placeholder.html index 1e350309..bbe5b4bd 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_path_param_no_placeholder.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_path_param_no_placeholder.html @@ -1 +1,14 @@ -Validation failed. Operation 'paths./users/{username}.post' has no placeholders for params: foo. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\MissingPathPlaceholderException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Operation 'paths./users/{username}.post' has no placeholders for params: foo. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validatePathParameters, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[[{"name":"username","in":"path","required":true,"schema":{"type":"string"}},{"name":"foo","in":"path","schema":{"type":"number"}}],"\/users\/{username}","paths.\/users\/{username}.post"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_request_body_invalid_content.html b/tests/fixtures/SwaggerServiceTest/invalid_format_request_body_invalid_content.html index 0884fddc..ebfd7c9a 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_request_body_invalid_content.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_request_body_invalid_content.html @@ -1 +1,14 @@ -Validation failed. Operation 'paths./users/{id}.post' has invalid content types: image/png. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\InvalidSwaggerSpecException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Operation 'paths./users/{id}.post' has invalid content types: image/png. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateRequestBodyContent, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[{"image\/png":{"items":[]}},"paths.\/users\/{id}.post"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_response_invalid_items.html b/tests/fixtures/SwaggerServiceTest/invalid_format_response_invalid_items.html index 8e42aa1f..5c0f44cd 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_response_invalid_items.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_response_invalid_items.html @@ -1 +1,14 @@ -Validation failed. 'paths./users/{id}.post.responses.200.schema.items' should have required fields: type. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\MissingFieldException 🚨🚨 + +--- + +### **Details:** + +Validation failed. 'paths./users/{id}.post.responses.200.schema.items' should have required fields: type. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateFieldsPresent, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[["type"],"paths.\/users\/{id}.post.responses.200.schema.items"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_security_definition_flow.html b/tests/fixtures/SwaggerServiceTest/invalid_format_security_definition_flow.html index 3e0fc9b6..771a4b12 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_security_definition_flow.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_security_definition_flow.html @@ -1 +1,14 @@ -Validation failed. Field 'securityDefinitions.0.flow' has an invalid value: invalid. Allowed values: implicit, password, application, accessCode. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\InvalidFieldValueException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Field 'securityDefinitions.0.flow' has an invalid value: invalid. Allowed values: implicit, password, application, accessCode. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateFieldValue, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=["securityDefinitions.0.flow",["implicit","password","application","accessCode"]] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_security_definition_in.html b/tests/fixtures/SwaggerServiceTest/invalid_format_security_definition_in.html index 241f6946..338b923f 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_security_definition_in.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_security_definition_in.html @@ -1 +1,14 @@ -Validation failed. Field 'securityDefinitions.0.in' has an invalid value: invalid. Allowed values: query, header. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\InvalidFieldValueException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Field 'securityDefinitions.0.in' has an invalid value: invalid. Allowed values: query, header. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateFieldValue, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=["securityDefinitions.0.in",["query","header"]] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_format_security_definition_type.html b/tests/fixtures/SwaggerServiceTest/invalid_format_security_definition_type.html index 33a2c0a9..2ecc341b 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_format_security_definition_type.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_format_security_definition_type.html @@ -1 +1,14 @@ -Validation failed. Field 'securityDefinitions.0.type' has an invalid value: invalid. Allowed values: basic, apiKey, oauth2. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\InvalidFieldValueException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Field 'securityDefinitions.0.type' has an invalid value: invalid. Allowed values: basic, apiKey, oauth2. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateFieldValue, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=["securityDefinitions.0.type",["basic","apiKey","oauth2"]] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/invalid_version.html b/tests/fixtures/SwaggerServiceTest/invalid_version.html index 581fef92..06889e32 100644 --- a/tests/fixtures/SwaggerServiceTest/invalid_version.html +++ b/tests/fixtures/SwaggerServiceTest/invalid_version.html @@ -1 +1,14 @@ -Validation failed. Unrecognized Swagger version '1.0'. Expected 3.1.0. \ No newline at end of file +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\InvalidSwaggerVersionException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Unrecognized Swagger version '1.0'. Expected 3.1.0. + +### **Error place:** + +file=/src/Validators/SwaggerSpecValidator.php, line=999, function=validateVersion, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=[] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/php_8.4_invalid_format_missing_external_ref.html b/tests/fixtures/SwaggerServiceTest/php_8.4_invalid_format_missing_external_ref.html new file mode 100644 index 00000000..1b2206de --- /dev/null +++ b/tests/fixtures/SwaggerServiceTest/php_8.4_invalid_format_missing_external_ref.html @@ -0,0 +1,14 @@ +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\MissingExternalRefException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Ref 'authloginObject' is used in $ref but not defined in 'tests/fixtures/SwaggerServiceTest/documentation/with_definitions.json' file. + +### **Error place:** + +function={closure:RonasIT\AutoDoc\Validators\SwaggerSpecValidator::validateRefs():1}, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=["tests\/fixtures\/SwaggerServiceTest\/documentation\/with_definitions.json#\/definitions\/authloginObject","$ref"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/php_8.4_invalid_format_missing_local_ref.html b/tests/fixtures/SwaggerServiceTest/php_8.4_invalid_format_missing_local_ref.html new file mode 100644 index 00000000..227d8633 --- /dev/null +++ b/tests/fixtures/SwaggerServiceTest/php_8.4_invalid_format_missing_local_ref.html @@ -0,0 +1,14 @@ +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\MissingLocalRefException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Ref 'loginObject' is used in $ref but not defined in 'definitions' field. + +### **Error place:** + +function={closure:RonasIT\AutoDoc\Validators\SwaggerSpecValidator::validateRefs():1}, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=["#\/definitions\/loginObject","$ref"] +--- \ No newline at end of file diff --git a/tests/fixtures/SwaggerServiceTest/php_8.4_invalid_format_missing_ref_file.html b/tests/fixtures/SwaggerServiceTest/php_8.4_invalid_format_missing_ref_file.html new file mode 100644 index 00000000..5ce8effe --- /dev/null +++ b/tests/fixtures/SwaggerServiceTest/php_8.4_invalid_format_missing_ref_file.html @@ -0,0 +1,14 @@ +# ❗️ **ERROR** ❗️ + +## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\MissingRefFileException 🚨🚨 + +--- + +### **Details:** + +Validation failed. Filename 'invalid-filename.json' is used in $ref but file doesn't exist. + +### **Error place:** + +function={closure:RonasIT\AutoDoc\Validators\SwaggerSpecValidator::validateRefs():1}, class=RonasIT\AutoDoc\Validators\SwaggerSpecValidator, type=->, args=["invalid-filename.json","$ref"] +--- \ No newline at end of file diff --git a/tests/support/Traits/TraceMockTrait.php b/tests/support/Traits/TraceMockTrait.php new file mode 100644 index 00000000..13d39633 --- /dev/null +++ b/tests/support/Traits/TraceMockTrait.php @@ -0,0 +1,72 @@ + Str::contains($value, 'function=') + ); + + $traceInfoInArray = $this->getTraceInfoInArray($traceInfo); + + $mockedContent = Arr::set( + array: $contentInArray, + key: array_search($traceInfo, $contentInArray), + value: implode(', ', $traceInfoInArray) + ); + + $content = implode(PHP_EOL, $mockedContent); + } + + protected function getTraceInfoInArray(string $traceInfo): array + { + $errorPlaceInArray = explode(', ', $traceInfo); + $errorPlaceInArray = array_combine( + keys: Arr::map($errorPlaceInArray, fn ($value, $key) => Str::before($value, '=')), + values: $errorPlaceInArray + ); + + foreach ($errorPlaceInArray as $key => $value) { + $errorPlaceInArray[$key] = match ($key) { + 'line' => 'line=999', + 'class' => Str::contains($value, 'MockObject') ? 'class=MockClass' : $value, + 'file' => 'file=/src' . Str::after($value, '/src'), + 'function' => $this->normalizeClosureFormat($value), + default => $value, + }; + } + + return $errorPlaceInArray; + } + + protected function normalizeFilePath(string $filePath): string + { + if (!str_starts_with($filePath, '/app')) { + return Str::after($filePath, base_path() . DIRECTORY_SEPARATOR); + } + + return $filePath; + } + + protected function normalizeClosureFormat(string $function): string + { + if (Str::contains($function, 'closure:')) { + $functionInArray = explode(':', $function); + + Arr::set($functionInArray, array_key_last($functionInArray), '1}'); + + return implode(':', $functionInArray); + } + + return $function; + } +} \ No newline at end of file