Open eelco2k opened 8 months ago
yeah its a good idea, but i think this must be optional. The documentation will generated if developer parse argument, like --swagger
maybe. so the artisan command look like php artisan make:filament-api-service BlogResource --swagger
.
and i don't like this part define('TENANT_AWARENESS_BRANDS', true);
. The BRANDS
is make confused. if you want to do this,
we can use resource property on every handler. maybe adding this method to Handlers class :
public static function isTenantAwarenessEnabled() : bool
{
return static::getResource()::isScopedToTenant();
}
so you can call it while registering the routes.
I was thinking of putting it in a /Virtual/ folder with some empty classes, that way it is separted from actual code. This also means that you can regenerate API docs of one or more resources based on those api docs stubs again and again.
You are absolutely correct that the BRANDS
is not okay. it was just an example and can be dynamically fetched from classname of resource.
And yes, an extra static function on the handler class isTenantAwerenessEnabled() is a good idea.
I just posted a rough WiP.. but i will add your considerations :)
first work on swagger generation. I created it as a separate command instead of --swagger option in the filament-api-service for now.
rough work is in this feature branch as pull request https://github.com/rupadana/filament-api-service/pull/51
thank you for the tools. eelco2k fix it critical errors
$baseResourceSourcePath = (string) str($resourceClass)->prepend('/')->prepend(base_path($resourcePath))
->replace('\\', '/')->replace('//', '/')
->replace('App', 'app'); // default
and
<?php
namespace {{ namespace }}\{{ resourceClass }}\Transformers;
use OpenApi\Attributes as OAT;
#[OAT\Schema(
schema: "{{ transformerName }}",
title: "{{ transformerName }}",
description: "{{ modelClass }} API Transformer",
xml: new OAT\Xml(name: "{{ transformerName }}"),
)]
->replace('App', 'app')
Xml
It would be nice to add an example of use
php artisan make:filament-resource User
php artisan make:filament-api-service UserResource
php artisan make:filament-api-transformer UserResource
add in UserResource
/**
* @return string|null
*/
public static function getApiTransformer(): ?string
{
return UserTransformer::class;
}
php artisan make:filament-api-docs UserResource
php artisan l5-swagger:generate
I used the package until the patch was accepted
composer require cweagans/composer-patches
and composer,json
"extra": {
"laravel": {
"dont-discover": []
},
"patches": {
"rupadana/filament-api-service": {
"add command filament-api-docs (for generate swagger)": "patches/rupadana/filament-api-service/filament-api-docs.txt"
}
},
"enable-patching": true
},
"config": {
"optimize-autoloader": true,
"preferred-install": "source",
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"php-http/discovery": true,
"cweagans/composer-patches": true
}
},
Thanks for the work. Good luck in your development!
@POMXARK I've added your patches. hopefully everything works now.
What happened?
Use PHP Swagger API docs generator with https://github.com/DarkaOnLine/L5-Swagger and https://github.com/zircote/swagger-php to add these codeblocks to the stubs.
Most of the parameters can be set as custom CONSTANTS when the plugin is configured via config variables in l5-swagger.php
define('TENANT_AWARENESS', config('api-service.tenancy.awareness'); or so...
check if tenancy for resource is enabled set constant per resource in for example the BrandApiService.php
as an example for the different resource API Handlers.php (CreateHandler.php, UpdateHandler.php etc...) :
and
and BrandTransformer.php
and the transformer schema
How to reproduce the bug
Implement OpenApi\Attributes;
Package Version
3.2
PHP Version
8.3
Laravel Version
10.0
Which operating systems does with happen with?
No response
Notes
This is just a start and code is not always cleaned up and i'm not quite sure everything is covered like response codes, panel prefix as CONST so it can be added in path: etc.... I could make time to add these features and do a PR if you prefer.