Skip to content

Commit a7f6f17

Browse files
committed
feat: scramble api docs helper
1 parent 4b0d13e commit a7f6f17

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
],
1717
"require": {
1818
"php": "^8.1",
19-
"laravel/framework": "^9.0|^10.0|^11.0|^12.0"
19+
"laravel/framework": "^10.0|^11.0|^12.0"
2020
},
2121
"require-dev": {
2222
"doctrine/dbal": ">=2.3",
23+
"dedoc/scramble": "^0.12.6",
2324
"mockery/mockery": "^1.0",
24-
"nunomaduro/larastan": "^2.0|^3.0",
25-
"orchestra/testbench": "^7.0|^8.0|^9.0|^10.0",
25+
"larastan/larastan": "^2.0|^3.0",
26+
"orchestra/testbench": "^8.0|^9.0|^10.0",
2627
"phpunit/phpunit": "^9.5|^10.0"
2728
},
2829
"autoload": {

phpstan.neon.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
includes:
2-
- ./vendor/nunomaduro/larastan/extension.neon
2+
- ./vendor/larastan/larastan/extension.neon
33
- ./phpstan-baseline.neon
44

55

src/Scramble/ApiResourceOpenApi.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public function toSchema(Type $type)
5151

5252
$file_url = $this->getModelPropertyType($type, 'file_url', $scope);
5353

54-
if (blank($fields)) {
55-
$fields = $modelType->getMethodReturnType('toArray', [], $scope)->items;
54+
if (blank($fields) && $modelType instanceof ObjectType) {
55+
$fields = $modelType->getMethodReturnType('toArray', [], $scope)->items; //@phpstan-ignore property.notFound
5656
}
5757

5858
//@todo -- check the mapResources property and add those fields to the array
@@ -62,18 +62,9 @@ public function toSchema(Type $type)
6262
return $this->openApiTransformer->transform($array);
6363
}
6464

65-
private function getPropertyDefinitionsFromResource(Type $type): array
66-
{
67-
$c = new ReflectionClass($type->name);
68-
69-
return collect(PhpDoc::parse($c->getDocComment())->getPropertyTagValues())->mapWithKeys(function ($value) {
70-
return [str($value->propertyName)->replace('$', '')->toString() => new ArrayItemType_(str($value->propertyName)->replace('$', '')->toString(),)];
71-
})->toArray();
72-
}
73-
7465
private function getPropertyArray(Type $type, string $propertyName, Type $modelType, Scope $scope, bool $isOptional): array
7566
{
76-
$prop = new ReflectionProperty($type->name, $propertyName);
67+
$prop = new ReflectionProperty($type->name, $propertyName); //@phpstan-ignore property.notFound
7768
$val = $prop->getValue();
7869
if (! is_array($val)) {
7970
return [];

0 commit comments

Comments
 (0)