Skip to content

Commit 1c7dfcf

Browse files
committed
refactor: set empty array for not exception errors
1 parent 115f599 commit 1c7dfcf

File tree

42 files changed

+438
-43
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+438
-43
lines changed

resources/views/error.blade.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
### **{{ $message }}**
1+
# ❗️ **ERROR** ❗️
2+
3+
## 🚨🚨 {{$type}} 🚨🚨
4+
5+
---
6+
7+
### **Details:**
8+
9+
{{$message}}
10+
11+
---

src/Services/SwaggerService.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use RonasIT\AutoDoc\Validators\SwaggerSpecValidator;
2525
use Symfony\Component\HttpFoundation\Response;
2626
use Throwable;
27-
27+
use Exception;
2828
/**
2929
* @property SwaggerDriverContract $driver
3030
*/
@@ -832,7 +832,12 @@ public function getDocFileContent()
832832

833833
$this->openAPIValidator->validate($documentation);
834834
} catch (Throwable $exception) {
835-
return $this->generateEmptyData($this->config['defaults']['error'], ['message' => $exception->getMessage()]);
835+
$message = $exception instanceof Exception ? $exception->getMessage() : '[]';
836+
837+
return $this->generateEmptyData($this->config['defaults']['error'], [
838+
'message' => $message,
839+
'type' => $exception::class,
840+
]);
836841
}
837842

838843
$additionalDocs = config('auto-doc.additional_paths', []);

tests/SwaggerServiceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public function testGetDocFileContentInvalidTmpData(
238238

239239
$content = app(SwaggerService::class)->getDocFileContent();
240240

241-
$this->assertStringContainsString($this->getFixture($fixture), $content['info']['description']);
241+
$this->assertEqualsFixture($fixture, $content['info']['description']);
242242
}
243243

244244
public function testEmptyContactEmail()

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function assertEqualsJsonFixture(string $fixtureName, $data, bool $export
8787
public function assertEqualsFixture(string $fixtureName, $data, bool $exportMode = false): void
8888
{
8989
if ($exportMode || $this->globalExportMode) {
90-
$this->exportContent($fixtureName, $data);
90+
$this->exportContent($data, $fixtureName);
9191
}
9292

9393
$this->assertEquals($this->getFixture($fixtureName), $data);
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
Validation failed. paths./users.post.parameters.0 is an array, so it must include an 'items' field.
1+
# ❗️ **ERROR** ❗️
2+
3+
## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\InvalidSwaggerSpecException 🚨🚨
4+
5+
---
6+
7+
### **Details:**
8+
9+
Validation failed. paths./users.post.parameters.0 is an array, so it must include an 'items' field.
10+
11+
---
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
Validation failed. paths./users.get.responses.200.schema is an array, so it must include an 'items' field.
1+
# ❗️ **ERROR** ❗️
2+
3+
## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\InvalidSwaggerSpecException 🚨🚨
4+
5+
---
6+
7+
### **Details:**
8+
9+
Validation failed. paths./users.get.responses.200.schema is an array, so it must include an 'items' field.
10+
11+
---
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
Validation failed. paths./users.get.responses.default.headers.Last-Modified is an array, so it must include an 'items' field.
1+
# ❗️ **ERROR** ❗️
2+
3+
## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\InvalidSwaggerSpecException 🚨🚨
4+
5+
---
6+
7+
### **Details:**
8+
9+
Validation failed. paths./users.get.responses.default.headers.Last-Modified is an array, so it must include an 'items' field.
10+
11+
---
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
Validation failed. Operation 'paths./users/{username}.post' has body and formData parameters. Only one or the other is allowed.
1+
# ❗️ **ERROR** ❗️
2+
3+
## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\InvalidSwaggerSpecException 🚨🚨
4+
5+
---
6+
7+
### **Details:**
8+
9+
Validation failed. Operation 'paths./users/{username}.post' has body and formData parameters. Only one or the other is allowed.
10+
11+
---
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
Validation failed. Operation 'paths./users/{username}.get' has multiple in:header parameters with name:foo.
1+
# ❗️ **ERROR** ❗️
2+
3+
## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\DuplicateParamException 🚨🚨
4+
5+
---
6+
7+
### **Details:**
8+
9+
Validation failed. Operation 'paths./users/{username}.get' has multiple in:header parameters with name:foo.
10+
11+
---
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
Validation failed. Found multiple fields 'paths.*.*.operationId' with values: addPet.
1+
# ❗️ **ERROR** ❗️
2+
3+
## 🚨🚨 RonasIT\AutoDoc\Exceptions\SpecValidation\DuplicateFieldException 🚨🚨
4+
5+
---
6+
7+
### **Details:**
8+
9+
Validation failed. Found multiple fields 'paths.*.*.operationId' with values: addPet.
10+
11+
---

0 commit comments

Comments
 (0)