Question 1
I have created APIs using Laravel-Json-API and now I want to implement Swagger for documentation. However, I couldn’t find any blog or article that explains how to do this. From my research, it appears that some people suggest this package doesn’t support any Swagger or other library?
If answer is No then which library should I used for
If answer is Yes then need to confirm where I should add the Swagger code because we have 3 files for 1 resource
- Adapter (project_name/src/App/JsonApi/Buildings/Adapter.php)
- Schema (project_name/src/App/JsonApi/Buildings/Schema.php)
- Validators (project_name/src/App/JsonApi/Buildings/Validators.php)
Code
routes/api.php
JsonApi::register('v1')
->withNamespace('Api')
->middleware('jwt')
->defaultController('AbstractJsonApiController')
->routes(
function (Api $api) {
$api->resource('buildings')->relationships(function ($relations) {
$relations->hasOne('property');
});
});
AbstractJsonApiController
<?php
namespace AppHttpControllersApi;
use CloudCreativityLaravelJsonApiContractsStoreStoreInterface;
use CloudCreativityLaravelJsonApiHttpControllersJsonApiController;
use CloudCreativityLaravelJsonApiHttpRequestsFetchResources;
class AbstractJsonApiController extends JsonApiController
{
public function index(StoreInterface $store, FetchResources $request)
{
$result = $this->doSearch($store, $request);
if ($this->isResponse($result)) {
return $result;
}
return $this->reply()->content(
$result,
[],
[
'aggregates' => $this->doAggregateSearch($store, $request),
'reports' => $this->doReportSearch($store, $request),
]
);
}
}
Current error when I ran this command php artisan l5-swagger:generate got the error below because I don’t know where I put the swagger code
Error
Required @OAPathItem() not found