Skip to content

Commit 1f492d9

Browse files
authored
Merge pull request #20 from ensi-platform/task-81781
#81781
2 parents 9e52685 + 871fc62 commit 1f492d9

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Generators/RequestsGenerator.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Ensi\LaravelOpenApiServerGenerator\Enums\OpenApi3ContentTypeEnum;
88
use InvalidArgumentException;
99
use RuntimeException;
10+
use Throwable;
1011

1112
class RequestsGenerator extends BaseGenerator implements GeneratorInterface
1213
{
@@ -60,7 +61,11 @@ protected function extractRequests(SpecObjectInterface $specObject, array $names
6061
if (std_object_has($route, 'requestBody')) {
6162
$contentType = OpenApi3ContentTypeEnum::tryFrom(array_keys(get_object_vars($route->requestBody->content))[0]);
6263
if ($contentType) {
63-
[$validationRules, $usesEnums] = $this->getPropertyRules($contentType, $route->requestBody);
64+
try {
65+
[$validationRules, $usesEnums] = $this->getPropertyRules($contentType, $route->requestBody);
66+
} catch (Throwable $e) {
67+
console_warning("$className didn't generate", $e);
68+
}
6469
}
6570
}
6671

src/helpers.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use Symfony\Component\Console\Output\ConsoleOutput;
4+
35
if (!function_exists('std_object_has')) {
46
function std_object_has(stdClass $object, string $propertyName): bool
57
{
@@ -18,3 +20,16 @@ function do_with_all_of(stdClass $object, callable $fn): void
1820
}
1921
}
2022
}
23+
24+
if (!function_exists('console_warning')) {
25+
function console_warning(string $text, Throwable $e = null): void
26+
{
27+
$output = resolve(ConsoleOutput::class);
28+
29+
if ($e) {
30+
$text .= "\r\n{$e->getCode()}: {$e->getMessage()}";
31+
}
32+
33+
$output->writeln("<comment>$text</comment>");
34+
}
35+
}

0 commit comments

Comments
 (0)