Replies: 1 comment
-
currently this all I got <?php
declare(strict_types=1);
namespace App;
use Dedoc\Scramble\Extensions\TypeToSchemaExtension;
use Dedoc\Scramble\Support\Generator\Reference;
use Dedoc\Scramble\Support\Type\ObjectType;
use Dedoc\Scramble\Support\Type\Type;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use TiMacDonald\JsonApi\JsonApiResource;
class JsonApiResourceToSchemaExtension extends TypeToSchemaExtension
{
public function shouldHandle(Type $type): bool
{
return $type instanceof ObjectType
&& $type->isInstanceOf(JsonApiResource::class)
&& ! $type->isInstanceOf(AnonymousResourceCollection::class);
}
#[\Override]
public function toSchema(Type $type): mixed
{
$this->infer->analyzeClass($type->name);
$array = $type->getMethodDefinition('toAttributes')
->type
->getReturnType();
return $this->openApiTransformer->transform($array);
}
public function reference(ObjectType $type): Reference
{
return new Reference('schemas', $type->name, $this->components);
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I am using the json-api package and have found its documentation very helpful. However, I'm not very experienced with integrating this awesome library. Can anyone help me understand how to best integrate and utilize the json-api package for my project?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions