dedoc / scramble

Modern Laravel OpenAPI (Swagger) documentation generator. No PHPDoc annotations required.
https://scramble.dedoc.co/
MIT License
1.24k stars 119 forks source link

FooCollection::toArray() is ignored #519

Closed benascbr closed 2 months ago

benascbr commented 2 months ago

Example

class MediaController {
    public function index(): MediaCollection
}
class MediaCollection {
   public function toArray()
   {
       return [
          'items'  => $this->resource->items(),
          'foo' => 'bar',
      ];
   }
}

It fails to read MediaCollection::toArray()

Expected generated response example:

[
   'items' => [
     MediaResource::toArray(),
     ...
   ],
   'foo' => 'bar',
]

Actual:

[MediaResource::toArray(), ...]

Related links: https://laravel.com/docs/11.x/eloquent-resources#resource-collections

I have v0.11.12 packge version

benascbr commented 2 months ago

P.S. Huge kudos for this package. It works almost out of the box for my current project

romalytvynenko commented 2 months ago

@benascbr please show your real code - I won't be able to help otherwise

benascbr commented 2 months ago

For sure. Creating example in https://github.com/dedoc/demo-scramble

benascbr commented 2 months ago

Resolved by changing

public function toArray($request): array|Arrayable|JsonSerializable

to public function toArray($request): array

romalytvynenko commented 2 months ago

Still would be good to see the example, but if you call it a day - I agree!