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

[PRO] Docs to improve #562

Closed manuel-watchenterprise closed 1 month ago

manuel-watchenterprise commented 1 month ago

The generation is crashing easily when using array or collection.

image

The only way I found it works:

#[DataCollectionOf(PollOptionDto::class)]
public ?DataCollection $choices;

But if it is Collection or array, it fails both with the attribute and PhpDocs.

These are all crashing:

// This is from docs example!
#[DataCollectionOf(PollOptionDto::class)]
public ?Collection $choices;

/**
 * Avoid using @var is also mentioned in docs
 * @var Collection<int, PollOptionDto>
 */
public ?Collection $choices;

/**
 * @property Collection<int, PollOptionDto>
 */
public ?Collection $choices;

/**
 * @property Collection<int, PollOptionDto>
 */
class MyDto extends Data {
  public ?Collection $choices;
}

// and the same with arrays

/**
 * @property PollOptionDto[]
 */
public ?Collection $choices;

So, even if all these will fail, I recommend to update the docs to include the working example.

romalytvynenko commented 1 month ago

@manuel-watchenterprise Fixed! Please bump dedoc/scramble-pro to ^0.6.8