mpociot / laravel-apidoc-generator

Laravel API Documentation Generator
https://beyondco.de/docs/laravel-apidoc-generator/
MIT License
3.43k stars 614 forks source link

[Feature] @bodyParamsFile, to generate Body Parameters documentation from json file #767

Open ajcastro opened 4 years ago

ajcastro commented 4 years ago

Allow to generate Body Parameters documentation from a json file. Example:

/**
 * Store user
 *
 * @bodyParamsFile requests/users.store.json
 * 
 * @responseFile responses/users.store.json
 */

I would like to share my workflow.

  1. I have helpers createJsonRequestFile() and createJsonResponseFile() that will write my json files in storage/requests and storage/responses folders. Example:

    public function test_users_store()
    {
    $response = $this->postJson(route('users.store'), $data = []);
    
    $response
    ->createJsonRequestFile()
    ->createJsonResponseFile()
    ->assertCreated();
    }
  2. Then I run phpunit and apidoc:generate to generate my api docs:
    phpunit && php artisan apidoc:generate

As you can see I create my json data from unit tests and currently we have @responseFile for responses that's why I would also like to suggest feature like @bodyParamsFile for body params.

Also, maybe we can also do this for @queryParamsFile and @urlParamsFile.

Chris-Pratt-Clystnet commented 4 years ago

I have just run into this myself as I have a request that has a large number of body params.