knuckleswtf / scribe

Generate API documentation for humans from your Laravel codebase.✍
https://scribe.knuckles.wtf/laravel/
MIT License
1.58k stars 280 forks source link

How use recursive schema ? #859

Closed Grazulex closed 1 week ago

Grazulex commented 1 week ago

Scribe version

4.37

Your question

Hello, I use a resouce for my response :

        return [
            'id' => $this->id,
            'name' => $this->name,
            'description' => $this->description,
            'stats_ongoing' => $this->stats_ongoing,
            'probe_type' => new ProbeTypesResource($this->probeType),
            'created_at' => new DateTimeResource($this->created_at),
            'updated_at' => new DateTimeResource($this->updated_at),
            'rules' => $this->when('api/probes' === $request->route()->getPrefix(), fn() => ProbeRulesResource::collection($this->rules)),
            'last_metrics' => ProbeMetricsResource::collection($metrics),
        ];

and in my controller i have this :

    #[ResponseFromApiResource(ProbesCollection::class, Probes::class)]
    public function index(Request $request): JsonResponse

but when i generate the doc, I have this like example :

            "id": 36,
            "team_id": 14,
            "probe_type_id": 34,
            "name": "Lela Schinner Jr.",
            "description": "Quos quia illum impedit vel similique.",
            "stats_ongoing": 0,
            "created_at": "2024-06-21T04:00:54.000000Z",
            "updated_at": "2024-06-21T04:00:54.000000Z"

Why/how can I generate docs with the recursive schema from my resource ?

Docs

Grazulex commented 1 week ago

if I use this in my controller :

[ResponseFromApiResource(ProbesResource::class, Probes::class, collection: true)]

it's working wel now....