From 0e7dec2f4044a1f36984ad284458a2ea95a5545d Mon Sep 17 00:00:00 2001 From: Constantin Graf Date: Wed, 17 Jul 2024 16:25:34 +0200 Subject: [PATCH] Updated scramble --- ...aginatedResourceCollectionTypeToSchema.php | 22 ++++++++++++++----- app/Http/Resources/V1/BaseResource.php | 1 + composer.lock | 8 +++---- docker-compose.yml | 1 - 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/app/Extensions/Scramble/PaginatedResourceCollectionTypeToSchema.php b/app/Extensions/Scramble/PaginatedResourceCollectionTypeToSchema.php index a88224dc..7e0e5412 100644 --- a/app/Extensions/Scramble/PaginatedResourceCollectionTypeToSchema.php +++ b/app/Extensions/Scramble/PaginatedResourceCollectionTypeToSchema.php @@ -27,13 +27,10 @@ class PaginatedResourceCollectionTypeToSchema extends TypeToSchemaExtension && $type->isInstanceOf(PaginatedResourceCollection::class); } - /** - * @param Generic $type - */ - public function toResponse(Type $type): ?Response + public function toSchema(Type $type): ?OpenApiObjectType { /** @var Type|null $collectingClassType */ - $collectingClassType = $type->templateTypes[0]; + $collectingClassType = $type->templateTypes[0] ?? null; if (! $collectingClassType instanceof ObjectType) { return null; @@ -79,6 +76,21 @@ class PaginatedResourceCollectionTypeToSchema extends TypeToSchemaExtension ); $type->setRequired(['data', 'links', 'meta']); + return $type; + } + + /** + * @param Generic $type + */ + public function toResponse(Type $type): ?Response + { + /** @var ObjectType|null $collectingClassType */ + $collectingClassType = $type->templateTypes[0] ?? null; + if (! $collectingClassType instanceof ObjectType) { + return null; + } + $type = $this->toSchema($type); + return Response::make(200) ->description('Paginated set of `'.$this->components->uniqueSchemaName($collectingClassType->name).'`') ->setContent('application/json', Schema::fromType($type)); diff --git a/app/Http/Resources/V1/BaseResource.php b/app/Http/Resources/V1/BaseResource.php index e757881c..a9a0a6f6 100644 --- a/app/Http/Resources/V1/BaseResource.php +++ b/app/Http/Resources/V1/BaseResource.php @@ -12,5 +12,6 @@ abstract class BaseResource extends JsonResource protected function formatDateTime(?Carbon $carbon): ?string { return $carbon?->toIso8601ZuluString(); + } } diff --git a/composer.lock b/composer.lock index f410d2d1..04d1b85a 100644 --- a/composer.lock +++ b/composer.lock @@ -1403,12 +1403,12 @@ "source": { "type": "git", "url": "https://github.com/korridor/scramble.git", - "reference": "78b2a5a5eb8071b006bddc95e34e0620c8bf3b7d" + "reference": "ff692e60e3827ee395007d19ae377fc0d7274fe3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/korridor/scramble/zipball/78b2a5a5eb8071b006bddc95e34e0620c8bf3b7d", - "reference": "78b2a5a5eb8071b006bddc95e34e0620c8bf3b7d", + "url": "https://api.github.com/repos/korridor/scramble/zipball/ff692e60e3827ee395007d19ae377fc0d7274fe3", + "reference": "ff692e60e3827ee395007d19ae377fc0d7274fe3", "shasum": "" }, "require": { @@ -1487,7 +1487,7 @@ "url": "https://github.com/romalytvynenko" } ], - "time": "2024-03-19T15:56:18+00:00" + "time": "2024-07-17T11:33:15+00:00" }, { "name": "defuse/php-encryption", diff --git a/docker-compose.yml b/docker-compose.yml index bad1a13c..586df428 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,7 +28,6 @@ services: extra_hosts: - 'host.docker.internal:host-gateway' environment: - SUPERVISOR_PHP_COMMAND: "/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan octane:start --server=frankenphp --host=0.0.0.0 --admin-port=2019 --port=80 --watch" XDG_CONFIG_HOME: /var/www/html/config XDG_DATA_HOME: /var/www/html/data WWWUSER: '${WWWUSER}'