0

I am using "darkaonline/l5-swagger": "^5.5", for integrate swagger into my project. and complete whole step to configure it.

Here is my function

/**
 * @SWG\Get(
 *   path="/clients",
 *   summary="List clients",
 *   operationId="listClients",
 *   tags={"client"},
 *   @SWG\Response(
 *     response=200,
 *     description="A list of clients",
 *      @SWG\Schema(type="array", @SWG\Items(ref="#/definitions/Client"))
 *   ),
 *   @SWG\Response(
 *     response="default",
 *     description="an ""unexpected"" error"
 *   )
 * )
 */
public function index()
{
    $clients = Client::scope()
        ->orderBy('created_at', 'desc')
        ->withTrashed();

    if ($email = Input::get('email')) {
        $clients = $clients->whereHas('contacts', function ($query) use ($email) {
            $query->where('email', $email);
        });
    } elseif ($idNumber = Input::get('id_number')) {
        $clients = $clients->whereIdNumber($idNumber);
    }

    return $this->listResponse($clients);
}

I got this error $ref "#/definitions/Client" not found for @SWG\Items() in \App\Http\Controllers\Api\ClientApiController->index()

Jan Schultke
  • 17,446
  • 6
  • 47
  • 96
Ravi Gaudani
  • 186
  • 2
  • 14

1 Answers1

-1

You need to define the reference which looks its your model.

/*
 |--------------------------------------------------
 |  MODEL DEFINITIONS - (Example) - New%model%
 |--------------------------------------------------
 |  /**
 |   * @SWG\Definition(required={"name"}, definition="New%model%")
 |   *
 |  class Genre extends Eloquent
 |  {
 |      /**
 |       * @SWG\Property(example="Electronic")
 |       *
 |      public $name;
 */

This is a way to declare in your model, you can also define them by hand.

here you have more examples:

https://github.com/zircote/swagger-php/tree/master/Examples/petstore.swagger.io/models

Hope it helps.

Kiko Seijo
  • 701
  • 8
  • 11
  • Implementing public field on Eloquent models changes expected behavior, so this solution is not recommended. Eloquent has protected attribute `$attributes` for `__set()`. – mpyw May 11 '18 at 11:23