https://github.com/jobinsjp/api-generator
Generate api docs while writing test case (Laravel).
https://github.com/jobinsjp/api-generator
documentation laravel openapi phpunit swagger swagger-ui testing
Last synced: 29 days ago
JSON representation
Generate api docs while writing test case (Laravel).
- Host: GitHub
- URL: https://github.com/jobinsjp/api-generator
- Owner: JoBinsJP
- Created: 2021-03-26T08:23:58.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-05-07T15:22:03.000Z (almost 2 years ago)
- Last Synced: 2025-03-17T11:50:29.207Z (about 2 months ago)
- Topics: documentation, laravel, openapi, phpunit, swagger, swagger-ui, testing
- Language: PHP
- Homepage:
- Size: 59.6 KB
- Stars: 7
- Watchers: 4
- Forks: 3
- Open Issues: 7
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# API Generator
Generate api docs while writing test case (Laravel).
### Idea
It generates api docs with [OpenAPI Specification](https://swagger.io/specification) while wiring test case in
laravel application. The generated docs can preview on swagger ui either integrate laravel-swagger-ui on application
or [Swagger Editor online](https://editor.swagger.io/).##### Features
* All basic setup features as available in swagger api.
* Request body will define using Laravel FormRequest class.
* The Request body example will grab from test data that used on testing.
* Route parameters will define from Laravel route.
* Response example grabs from the test responses.### Installation
```shell
composer require jobins/api-generator --dev
```### Publish assets
```shell
php artisan vendor:publish --provider="Jobins\APIGenerator\APIGeneratorServiceProvider"
```### Basic Uses
```php
"A User Object",
"define" => [
"data.*" => ["refSchema" => "UserSchema"],
"message" => "Message for user",
],
];
$this->setSummary("Register a new user.")
->setId("Register")
->setSecurity([Bearer::class])
->setTags(["Posts"])
->setRulesFromFormRequest(RegistrationRequest::class)
->defineResponseSchema($responseSchema)
->jsond("post", route("registration.store"), $data)
->assertStatus(422)
->assertJsonFragment([])
->assertJsonStructure(["message"])
->generate($this, true);
}
}
```### Define parameters in descriptions method of FormRequest class.
```php
/**
* Class ExampleFormRequest
* @package JoBins\APIGenerator\Tests\Stubs
*/
class ExampleFormRequest extends FormRequest
{
public function rules()
{
return [
"email" => "required", // Required, String,
"nickname" => "sometimes|required", // Optional Field, String
];
}public function descriptions()
{
return [
"email" => "Email of a new user.",
"nickname" => "Nick name of a new user."
];
}
}
```