Skip to content

Commit

Permalink
Generate API documentation with scramble
Browse files Browse the repository at this point in the history
  • Loading branch information
alexPopaCode4 committed Feb 29, 2024
1 parent d4628a5 commit cac9ac3
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 53 deletions.
6 changes: 4 additions & 2 deletions app/Http/Resources/IdAndNameResource.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Resources;

use Illuminate\Http\Request;
Expand All @@ -15,8 +17,8 @@ class IdAndNameResource extends JsonResource
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name
'id' => (int) $this->id,
'name' => $this->name,
];
}
}
4 changes: 2 additions & 2 deletions app/Http/Resources/OrganisationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class OrganisationResource extends JsonResource
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'id' => (int) $this->id,
'name' => $this->name,
'type' => $this->type,
'status' => $this->status,
Expand All @@ -29,7 +29,7 @@ public function toArray(Request $request): array
'activity_counties' => IdAndNameResource::collection($this->activityCounties),
'created_at' => $this->created_at->format('Y-m-d H:i:s'),
'updated_at' => $this->updated_at->format('Y-m-d H:i:s'),
'volunteers_count' => $this->volunteers_count,
'volunteers_count' => (int) $this->volunteers_count,
];
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"require": {
"php": "^8.1",
"alcea/cnp": "^3.0",
"dedoc/scramble": "^0.8.5",
"filament/filament": "^2.17",
"filament/spatie-laravel-media-library-plugin": "^2.17",
"guzzlehttp/guzzle": "^7.8",
Expand Down
173 changes: 124 additions & 49 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions config/scramble.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

declare(strict_types=1);

use Dedoc\Scramble\Http\Middleware\RestrictedDocsAccess;

return [
/*
* Your API path. By default, all routes starting with this path will be added to the docs.
* If you need to change this behavior, you can add your custom routes resolver using `Scramble::routes()`.
*/
'api_path' => 'api',

/*
* Your API domain. By default, app domain is used. This is also a part of the default API routes
* matcher, so when implementing your own, make sure you use this config if needed.
*/
'api_domain' => null,

'info' => [
/*
* API version.
*/
'version' => env('API_VERSION', '1'),

/*
* Description rendered on the home page of the API documentation (`/docs/api`).
*/
'description' => '',
],

/*
* Customize Stoplight Elements UI
*/
'ui' => [
/*
* Hide the `Try It` feature. Enabled by default.
*/
'hide_try_it' => false,

/*
* URL to an image that displays as a small square logo next to the title, above the table of contents.
*/
'logo' => '',

/*
* Use to fetch the credential policy for the Try It feature. Options are: omit, include (default), and same-origin
*/
'try_it_credentials_policy' => 'include',
],

/*
* The list of servers of the API. By default, when `null`, server URL will be created from
* `scramble.api_path` and `scramble.api_domain` config variables. When providing an array, you
* will need to specify the local server URL manually (if needed).
*
* Example of non-default config (final URLs are generated using Laravel `url` helper):
*
* ```php
* 'servers' => [
* 'Live' => 'api',
* 'Prod' => 'https://scramble.dedoc.co/api',
* ],
* ```
*/
'servers' => null,

'middleware' => [
'web',
RestrictedDocsAccess::class,
],

'extensions' => [],
];
2 changes: 2 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Gate::define('viewApiDocs', fn () => true);

Route::middleware('auth:sanctum')
->prefix('/v1')
->group(function () {
Expand Down

0 comments on commit cac9ac3

Please sign in to comment.