byte-it / openapi-spec-generator

Creates Open API spec for a Laravel JSON:API
3 stars 6 forks source link

out of the box error: null returned in ResourceContainer #10

Open Mina-R-Meshriky opened 3 years ago

Mina-R-Meshriky commented 3 years ago

I am trying the package out of the box, couldn't generate the documentation on a running project though

LaravelJsonApi\OpenApiSpec\ResourceContainer::resource(): Return value must be of type LaravelJsonApi\Core\Resources\JsonApiResource, null returned

  at vendor/byteit/openapi-spec-generator/src/ResourceContainer.php:34
     30▕         $fqn = $this->getFQN($model);
     31▕         if(!isset($this->resource[$fqn])){
     32▕             $this->loadResources($fqn);
     33▕         }
  ➜  34▕         return $this->resources[$fqn]->first();
     35▕     }
     36▕ 
     37▕     /**
     38▕      * @param  mixed  $model

      +11 vendor frames 
  12  [internal]:0
      LaravelJsonApi\OpenApiSpec\Builders\PathsBuilder::LaravelJsonApi\OpenApiSpec\Builders\{closure}(Object(LaravelJsonApi\OpenApiSpec\Route))

      +2 vendor frames 
  15  [internal]:0
      LaravelJsonApi\OpenApiSpec\Builders\PathsBuilder::LaravelJsonApi\OpenApiSpec\Builders\{closure}(Object(Illuminate\Support\Collection), "/settings")
captnCC commented 3 years ago

Is your DB empty? At this point it is a hard requirement, that for each model that has a Schema, sample data must be present.

Mina-R-Meshriky commented 3 years ago

but why dont we use the model factory for the sample ? instead of the database I mean or if the database has no data, don't insert a sample

captnCC commented 3 years ago

To the first question: The factory would be satisfying for simple schemas. But I think for more complex setups with many models and relations, the usage of a seeded DB is more suitable. This allows the developer to create a complete dataset via Seeder or an imported DB dump. But yes it is planned to make the sample generation completely optional!