PHP code example of jobins / api-generator

1. Go to this page and download the library: Download jobins/api-generator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jobins / api-generator example snippets




namespace Tests\Feature;

use App\Http\Requests\RegistrationRequest;
use JoBins\APIGenerator\Security\Bearer;
use JoBins\APIGenerator\Traits\HasDocsGenerator;

class RegistrationTest extends TestCase
{
    use HasDocsGenerator;
    
    /** @test */
    public function it_register_a_new_user()
    {
        $responseSchema = [
            "description" => "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);    
    }
}


/**
 * Class ExampleFormRequest
 * @package JoBins\APIGenerator\Tests\Stubs
 */
class ExampleFormRequest extends FormRequest
{
    public function rules()
    {
        return [
            "email"     => "        "nickname"  => "Nick name of a new user."
        ];
    }
}
shell
php artisan vendor:publish --provider="Jobins\APIGenerator\APIGeneratorServiceProvider"