From 717a9fb0a31417bcf27fc1cd25b9f74cc4f252fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Wed, 25 Oct 2023 20:40:41 +0200 Subject: [PATCH] Fixed API Platform deprecations --- VERSION | 2 +- composer.json | 1 + composer.lock | 2 +- config/packages/api_platform.yaml | 2 ++ src/ApiResource/PartDBInfo.php | 3 ++- src/Entity/Attachments/AttachmentType.php | 3 ++- src/Entity/Parts/Category.php | 7 +++++-- src/Entity/Parts/Footprint.php | 7 +++++-- src/Entity/Parts/Manufacturer.php | 7 +++++-- src/Entity/Parts/MeasurementUnit.php | 7 +++++-- src/Entity/Parts/StorageLocation.php | 7 +++++-- src/Entity/Parts/Supplier.php | 7 +++++-- src/Entity/PriceInformations/Currency.php | 7 +++++-- src/Entity/PriceInformations/Orderdetail.php | 7 +++++-- src/Entity/ProjectSystem/Project.php | 7 +++++-- src/Entity/ProjectSystem/ProjectBOMEntry.php | 7 +++++-- src/Entity/UserSystem/ApiToken.php | 5 ++++- src/Entity/UserSystem/User.php | 13 +++++++++---- 18 files changed, 72 insertions(+), 29 deletions(-) diff --git a/VERSION b/VERSION index 53adb84c..b57588e5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.8.2 +1.9.0-dev diff --git a/composer.json b/composer.json index a16706b9..a47bd12a 100644 --- a/composer.json +++ b/composer.json @@ -70,6 +70,7 @@ "symfony/runtime": "6.3.*", "symfony/security-bundle": "6.3.*", "symfony/serializer": "6.3.*", + "symfony/string": "6.3.*", "symfony/translation": "6.3.*", "symfony/twig-bundle": "6.3.*", "symfony/ux-translator": "^2.10", diff --git a/composer.lock b/composer.lock index 4facb6fc..f8a2abeb 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a3d850bada24e7349d2181693a50c637", + "content-hash": "258be26a5e5d25abc80062849a2a948e", "packages": [ { "name": "api-platform/core", diff --git a/config/packages/api_platform.yaml b/config/packages/api_platform.yaml index b53cc7e0..9bc2168c 100644 --- a/config/packages/api_platform.yaml +++ b/config/packages/api_platform.yaml @@ -8,6 +8,8 @@ api_platform: # eager_loading: # max_joins: 100 + keep_legacy_inflector: false + swagger: api_keys: # overridden in OpenApiFactoryDecorator diff --git a/src/ApiResource/PartDBInfo.php b/src/ApiResource/PartDBInfo.php index 9a06f262..25aed05e 100644 --- a/src/ApiResource/PartDBInfo.php +++ b/src/ApiResource/PartDBInfo.php @@ -26,6 +26,7 @@ namespace App\ApiResource; use ApiPlatform\Metadata\ApiFilter; use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\Get; +use ApiPlatform\OpenApi\Model\Operation; use ApiPlatform\Serializer\Filter\PropertyFilter; use App\State\PartDBInfoProvider; @@ -35,7 +36,7 @@ use App\State\PartDBInfoProvider; #[ApiResource( uriTemplate: '/info.{_format}', description: 'Basic information about Part-DB like version, title, etc.', - operations: [new Get(openapiContext: ['summary' => 'Get basic information about the installed Part-DB instance.'])], + operations: [new Get(openapi: new Operation(summary: 'Get basic information about the installed Part-DB instance.'))], provider: PartDBInfoProvider::class )] #[ApiFilter(PropertyFilter::class)] diff --git a/src/Entity/Attachments/AttachmentType.php b/src/Entity/Attachments/AttachmentType.php index d4cc7b25..241f3d18 100644 --- a/src/Entity/Attachments/AttachmentType.php +++ b/src/Entity/Attachments/AttachmentType.php @@ -33,6 +33,7 @@ use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\Link; use ApiPlatform\Metadata\Patch; use ApiPlatform\Metadata\Post; +use ApiPlatform\OpenApi\Model\Operation; use ApiPlatform\Serializer\Filter\PropertyFilter; use App\ApiPlatform\Filter\LikeFilter; use App\Entity\Parts\Footprint; @@ -70,7 +71,7 @@ use Symfony\Component\Validator\Constraints as Assert; #[ApiResource( uriTemplate: '/attachment_types/{id}/children.{_format}', operations: [ - new GetCollection(openapiContext: ['summary' => 'Retrieves the children elements of an attachment type.'], + new GetCollection(openapi: new Operation(summary: 'Retrieves the children elements of an attachment type.'), security: 'is_granted("@attachment_types.read")') ], uriVariables: [ diff --git a/src/Entity/Parts/Category.php b/src/Entity/Parts/Category.php index b1dc8c97..95e2295c 100644 --- a/src/Entity/Parts/Category.php +++ b/src/Entity/Parts/Category.php @@ -34,6 +34,7 @@ use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\Link; use ApiPlatform\Metadata\Patch; use ApiPlatform\Metadata\Post; +use ApiPlatform\OpenApi\Model\Operation; use ApiPlatform\Serializer\Filter\PropertyFilter; use App\ApiPlatform\Filter\LikeFilter; use App\Entity\Attachments\Attachment; @@ -72,8 +73,10 @@ use Symfony\Component\Validator\Constraints as Assert; #[ApiResource( uriTemplate: '/categories/{id}/children.{_format}', operations: [ - new GetCollection(openapiContext: ['summary' => 'Retrieves the children elements of a category.'], - security: 'is_granted("@categories.read")') + new GetCollection( + openapi: new Operation(summary: 'Retrieves the children elements of a category.'), + security: 'is_granted("@categories.read")' + ) ], uriVariables: [ 'id' => new Link(fromProperty: 'children', fromClass: Category::class) diff --git a/src/Entity/Parts/Footprint.php b/src/Entity/Parts/Footprint.php index 2cdf9fba..c3f70087 100644 --- a/src/Entity/Parts/Footprint.php +++ b/src/Entity/Parts/Footprint.php @@ -34,6 +34,7 @@ use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\Link; use ApiPlatform\Metadata\Patch; use ApiPlatform\Metadata\Post; +use ApiPlatform\OpenApi\Model\Operation; use ApiPlatform\Serializer\Filter\PropertyFilter; use App\ApiPlatform\Filter\LikeFilter; use App\Entity\Attachments\Attachment; @@ -72,8 +73,10 @@ use Symfony\Component\Validator\Constraints as Assert; #[ApiResource( uriTemplate: '/footprints/{id}/children.{_format}', operations: [ - new GetCollection(openapiContext: ['summary' => 'Retrieves the children elements of a footprint.'], - security: 'is_granted("@footprints.read")') + new GetCollection( + openapi: new Operation(summary: 'Retrieves the children elements of a footprint.'), + security: 'is_granted("@footprints.read")' + ) ], uriVariables: [ 'id' => new Link(fromProperty: 'children', fromClass: Footprint::class) diff --git a/src/Entity/Parts/Manufacturer.php b/src/Entity/Parts/Manufacturer.php index 14b31409..1a5db9ba 100644 --- a/src/Entity/Parts/Manufacturer.php +++ b/src/Entity/Parts/Manufacturer.php @@ -33,6 +33,7 @@ use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\Link; use ApiPlatform\Metadata\Patch; use ApiPlatform\Metadata\Post; +use ApiPlatform\OpenApi\Model\Operation; use ApiPlatform\Serializer\Filter\PropertyFilter; use App\ApiPlatform\Filter\LikeFilter; use App\Entity\Attachments\Attachment; @@ -71,8 +72,10 @@ use Symfony\Component\Validator\Constraints as Assert; #[ApiResource( uriTemplate: '/manufacturers/{id}/children.{_format}', operations: [ - new GetCollection(openapiContext: ['summary' => 'Retrieves the children elements of a manufacturer.'], - security: 'is_granted("@manufacturers.read")') + new GetCollection( + openapi: new Operation(summary: 'Retrieves the children elements of a manufacturer.'), + security: 'is_granted("@manufacturers.read")' + ) ], uriVariables: [ 'id' => new Link(fromProperty: 'children', fromClass: Manufacturer::class) diff --git a/src/Entity/Parts/MeasurementUnit.php b/src/Entity/Parts/MeasurementUnit.php index f9f45ca5..299c230d 100644 --- a/src/Entity/Parts/MeasurementUnit.php +++ b/src/Entity/Parts/MeasurementUnit.php @@ -33,6 +33,7 @@ use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\Link; use ApiPlatform\Metadata\Patch; use ApiPlatform\Metadata\Post; +use ApiPlatform\OpenApi\Model\Operation; use ApiPlatform\Serializer\Filter\PropertyFilter; use App\ApiPlatform\Filter\LikeFilter; use App\Entity\Attachments\Attachment; @@ -75,8 +76,10 @@ use Symfony\Component\Validator\Constraints as Assert; #[ApiResource( uriTemplate: '/footprints/{id}/children.{_format}', operations: [ - new GetCollection(openapiContext: ['summary' => 'Retrieves the children elements of a MeasurementUnit.'], - security: 'is_granted("@measurement_units.read")') + new GetCollection( + openapi: new Operation(summary: 'Retrieves the children elements of a MeasurementUnit.'), + security: 'is_granted("@measurement_units.read")' + ) ], uriVariables: [ 'id' => new Link(fromProperty: 'children', fromClass: MeasurementUnit::class) diff --git a/src/Entity/Parts/StorageLocation.php b/src/Entity/Parts/StorageLocation.php index 3a7847d9..564f30ce 100644 --- a/src/Entity/Parts/StorageLocation.php +++ b/src/Entity/Parts/StorageLocation.php @@ -33,6 +33,7 @@ use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\Link; use ApiPlatform\Metadata\Patch; use ApiPlatform\Metadata\Post; +use ApiPlatform\OpenApi\Model\Operation; use ApiPlatform\Serializer\Filter\PropertyFilter; use App\ApiPlatform\Filter\LikeFilter; use App\Entity\Attachments\Attachment; @@ -71,8 +72,10 @@ use Symfony\Component\Validator\Constraints as Assert; #[ApiResource( uriTemplate: '/storage_locations/{id}/children.{_format}', operations: [ - new GetCollection(openapiContext: ['summary' => 'Retrieves the children elements of a storage location.'], - security: 'is_granted("@storelocations.read")') + new GetCollection( + openapi: new Operation(summary: 'Retrieves the children elements of a storage location.'), + security: 'is_granted("@storelocations.read")' + ) ], uriVariables: [ 'id' => new Link(fromProperty: 'children', fromClass: Manufacturer::class) diff --git a/src/Entity/Parts/Supplier.php b/src/Entity/Parts/Supplier.php index 83289439..5103a565 100644 --- a/src/Entity/Parts/Supplier.php +++ b/src/Entity/Parts/Supplier.php @@ -33,6 +33,7 @@ use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\Link; use ApiPlatform\Metadata\Patch; use ApiPlatform\Metadata\Post; +use ApiPlatform\OpenApi\Model\Operation; use ApiPlatform\Serializer\Filter\PropertyFilter; use App\ApiPlatform\Filter\LikeFilter; use App\Entity\Attachments\Attachment; @@ -75,8 +76,10 @@ use Symfony\Component\Validator\Constraints as Assert; )] #[ApiResource( uriTemplate: '/suppliers/{id}/children.{_format}', - operations: [new GetCollection(openapiContext: ['summary' => 'Retrieves the children elements of a supplier'], - security: 'is_granted("@manufacturers.read")')], + operations: [new GetCollection( + openapi: new Operation(summary: 'Retrieves the children elements of a supplier.'), + security: 'is_granted("@manufacturers.read")' + )], uriVariables: [ 'id' => new Link(fromClass: Supplier::class, fromProperty: 'children') ], diff --git a/src/Entity/PriceInformations/Currency.php b/src/Entity/PriceInformations/Currency.php index a108feeb..2e95dc09 100644 --- a/src/Entity/PriceInformations/Currency.php +++ b/src/Entity/PriceInformations/Currency.php @@ -33,6 +33,7 @@ use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\Link; use ApiPlatform\Metadata\Patch; use ApiPlatform\Metadata\Post; +use ApiPlatform\OpenApi\Model\Operation; use ApiPlatform\Serializer\Filter\PropertyFilter; use App\ApiPlatform\Filter\LikeFilter; use App\Entity\Attachments\Attachment; @@ -75,8 +76,10 @@ use Symfony\Component\Validator\Constraints as Assert; #[ApiResource( uriTemplate: '/currencies/{id}/children.{_format}', operations: [ - new GetCollection(openapiContext: ['summary' => 'Retrieves the children elements of a currency.'], - security: 'is_granted("@currencies.read")') + new GetCollection( + openapi: new Operation(summary: 'Retrieves the children elements of a currency.'), + security: 'is_granted("@currencies.read")' + ) ], uriVariables: [ 'id' => new Link(fromProperty: 'children', fromClass: Currency::class) diff --git a/src/Entity/PriceInformations/Orderdetail.php b/src/Entity/PriceInformations/Orderdetail.php index 62426597..6fed2d75 100644 --- a/src/Entity/PriceInformations/Orderdetail.php +++ b/src/Entity/PriceInformations/Orderdetail.php @@ -34,6 +34,7 @@ use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\Link; use ApiPlatform\Metadata\Patch; use ApiPlatform\Metadata\Post; +use ApiPlatform\OpenApi\Model\Operation; use ApiPlatform\Serializer\Filter\PropertyFilter; use App\ApiPlatform\Filter\LikeFilter; use Doctrine\DBAL\Types\Types; @@ -73,8 +74,10 @@ use Symfony\Component\Validator\Constraints as Assert; #[ApiResource( uriTemplate: '/parts/{id}/orderdetails.{_format}', operations: [ - new GetCollection(openapiContext: ['summary' => 'Retrieves the orderdetails of a part.'], - security: 'is_granted("@parts.read")') + new GetCollection( + openapi: new Operation(summary: 'Retrieves the orderdetails of a part.'), + security: 'is_granted("@parts.read")' + ) ], uriVariables: [ 'id' => new Link(toProperty: 'part', fromClass: Part::class) diff --git a/src/Entity/ProjectSystem/Project.php b/src/Entity/ProjectSystem/Project.php index 81b1fc09..0859c7f1 100644 --- a/src/Entity/ProjectSystem/Project.php +++ b/src/Entity/ProjectSystem/Project.php @@ -33,6 +33,7 @@ use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\Link; use ApiPlatform\Metadata\Patch; use ApiPlatform\Metadata\Post; +use ApiPlatform\OpenApi\Model\Operation; use ApiPlatform\Serializer\Filter\PropertyFilter; use App\ApiPlatform\Filter\LikeFilter; use App\Entity\Attachments\Attachment; @@ -74,8 +75,10 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface; #[ApiResource( uriTemplate: '/projects/{id}/children.{_format}', operations: [ - new GetCollection(openapiContext: ['summary' => 'Retrieves the children elements of a project.'], - security: 'is_granted("@projects.read")') + new GetCollection( + openapi: new Operation(summary: 'Retrieves the children elements of a project.'), + security: 'is_granted("@projects.read")' + ) ], uriVariables: [ 'id' => new Link(fromProperty: 'children', fromClass: Project::class) diff --git a/src/Entity/ProjectSystem/ProjectBOMEntry.php b/src/Entity/ProjectSystem/ProjectBOMEntry.php index 8ecaa1ed..b45e1af0 100644 --- a/src/Entity/ProjectSystem/ProjectBOMEntry.php +++ b/src/Entity/ProjectSystem/ProjectBOMEntry.php @@ -32,6 +32,7 @@ use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\Link; use ApiPlatform\Metadata\Patch; use ApiPlatform\Metadata\Post; +use ApiPlatform\OpenApi\Model\Operation; use ApiPlatform\Serializer\Filter\PropertyFilter; use App\ApiPlatform\Filter\LikeFilter; use App\Validator\UniqueValidatableInterface; @@ -69,8 +70,10 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface; #[ApiResource( uriTemplate: '/projects/{id}/bom.{_format}', operations: [ - new GetCollection(openapiContext: ['summary' => 'Retrieves the BOM entries of the given project.'], - security: 'is_granted("@projects.read")') + new GetCollection( + openapi: new Operation(summary: 'Retrieves the BOM entries of the given project.'), + security: 'is_granted("@projects.read")' + ) ], uriVariables: [ 'id' => new Link(fromProperty: 'bom_entries', fromClass: Project::class) diff --git a/src/Entity/UserSystem/ApiToken.php b/src/Entity/UserSystem/ApiToken.php index 88a0ad84..95919e1d 100644 --- a/src/Entity/UserSystem/ApiToken.php +++ b/src/Entity/UserSystem/ApiToken.php @@ -26,6 +26,7 @@ namespace App\Entity\UserSystem; use ApiPlatform\Metadata\ApiFilter; use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\Get; +use ApiPlatform\OpenApi\Model\Operation; use ApiPlatform\Serializer\Filter\PropertyFilter; use App\Entity\Base\AbstractNamedDBElement; use App\Entity\Base\TimestampTrait; @@ -46,7 +47,9 @@ use Symfony\Component\Validator\Constraints\NotBlank; #[ApiResource( uriTemplate: '/tokens/current.{_format}', description: 'A token used to authenticate API requests.', - operations: [new Get(openapiContext: ['summary' => 'Get information about the API token that is currently used.'])], + operations: [new Get( + openapi: new Operation(summary: 'Get information about the API token that is currently used.'), + )], normalizationContext: ['groups' => ['token:read', 'api:basic:read'], 'openapi_definition_name' => 'Read'], provider: CurrentApiTokenProvider::class, )] diff --git a/src/Entity/UserSystem/User.php b/src/Entity/UserSystem/User.php index a6caaa0f..2ee96406 100644 --- a/src/Entity/UserSystem/User.php +++ b/src/Entity/UserSystem/User.php @@ -31,6 +31,7 @@ use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\Get; use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\Post; +use ApiPlatform\OpenApi\Model\Operation; use ApiPlatform\Serializer\Filter\PropertyFilter; use App\ApiPlatform\Filter\LikeFilter; use App\Entity\Attachments\Attachment; @@ -86,10 +87,14 @@ use Jbtronics\TFAWebauthn\Model\TwoFactorInterface as WebauthnTwoFactorInterface #[ApiResource( shortName: 'User', operations: [ - new Get(openapiContext: ['summary' => 'Get a specific user.'], - security: 'is_granted("read", object)'), - new GetCollection(openapiContext: ['summary' => 'Get all users defined in the system.'], - security: 'is_granted("@users.read")'), + new Get( + openapi: new Operation(summary: 'Get information about the current user.'), + security: 'is_granted("read", object)' + ), + new GetCollection( + openapi: new Operation(summary: 'Get all users defined in the system.'), + security: 'is_granted("@users.read")' + ), ], normalizationContext: ['groups' => ['user:read'], 'openapi_definition_name' => 'Read'], )]