api-platform-tools / extended-resource
API Platform Tools: Extend api-platform/core ApiResource attribute
Fund package maintenance!
Issuehunt
Requires
- php: >=8.1.0
- api-platform/core: *
- symfony/config: *
Requires (Dev)
- friendsofphp/php-cs-fixer: *
- phpunit/phpunit: >=10.0
- roave/security-advisories: dev-latest
Conflicts
- api-platform/core: <3.1.0
This package is auto-updated.
Last update: 2024-10-21 23:36:53 UTC
README
Installation
The recommended way to install is via Composer:
composer require api-platform-tools/extended-resource
This package requires at least PHP 8.1.0.
Other packages may come with api resources that with some configuration may not be suited for
straight away usage in a project. This is why ExtendedApiResource
is useful to override part of options defined
in default attributes.
For example, take a look at ApiPlatformTools\Tests\Assets\BaseResource
class. It defines api resource.
If you want iri to be /api/vendor/bases
, you have to do the following:
- Create new class that extends resource you want to override
- Add
ExtendedApiResouce
attribute insted ofApiResource
attribute - Pass only those options that you want to override, others will be taken from resource you are extending
namespace ApiPlatformTools\Tests\Assets; use ApiPlatformTools\Attribute\ExtendedApiResource; #[ExtendedApiResource(routePrefix: '/vendor')] class VendorResource extends ApiPlatformTools\Tests\Assets\BaseResource { }
ExtendedApiResouce
attribute checks which resource you are extending and overrides options given in extension,
keeping other options same as in parent resource.
IMPORTANT: You need to disable extended resource using api_platform.openapi.factory decorator, otherwise you will have 2 instances of base resource: one with
/api/bases
iri and one with/api/vendor/bases
iri.