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

Example is not using factory #854

Open fernandopiovezan1 opened 1 month ago

fernandopiovezan1 commented 1 month ago

Scribe version

4.35.0

Your question

I'm using scribe with the same settings I used previously, but it's not using the factories when generating the examples.

Scribe version 4.35.0

PHP version 8.3.6

Framework Laravel

Framework version v11.4.0

title => "Documenta\u00e7\u00e3o da API"
base_url => "http://localhost"
type => "laravel"
strategies.urlParameters => added Knuckles\Scribe\Extracting\Strategies\UrlParameters\GetFromLumenAPI
strategies.queryParameters => added App\Docs\Strategies\AddParams
strategies.headers => added Knuckles\Scribe\Extracting\Strategies\Headers\GetFromRouteRules: removed [
    'override',
    [
        'Content-Type' => 'application/json',
        'Accept' => 'application/json',
    ],
]
strategies.responses => added Knuckles\Scribe\Extracting\Strategies\Responses\ResponseCalls: removed [
    'Knuckles\\Scribe\\Extracting\\Strategies\\Responses\\ResponseCalls',
    [
        'only' => [
            'GET *',
        ],
    ],
]
database_connections_to_transact.0 => null

Factory File

return [
            'name'                 => $this->faker->name,
            'description'          => $this->faker->text($this->faker->numberBetween(5, 300)),
            'phone_number'         => $this->faker->numerify('0##########'),
            'visible_contact_page' => $this->faker->boolean,
            'phone_category_id'    => $phoneCategoryId,
            'company_id'           => $company->id,
            'is_active'            => $this->faker->boolean,
        ];

Example generated

        [
            'name' => 'pbbxqpnycjv',
            'description' => 'Nostrum sunt sequi adipisci nulla et explicabo magni.',
            'phone_number' => 'jzlrzwotnkiyoboepadcb',
            'visible_contact_page' => true,
            'phone_category_id' => 'aut',
            'is_active' => false,
        ]

I tried to find in the code where the problem could be and the only strange thing I found was that InstantiatesExampleModels is not accessed on any endpoint and UseResponseAttributes.extractFromAttributes all parameters are blank.

Docs

shalvah commented 1 month ago

Are you sure this is right? Your factory is for a model, but the example generated looks like Scribe generated values for individual fields. If they are individual fields on the request, a factory probably won't be used.