{"id":13796143,"url":"https://github.com/krakphp/api-platform-extra","last_synced_at":"2025-03-27T05:30:51.681Z","repository":{"id":57008998,"uuid":"151174837","full_name":"krakphp/api-platform-extra","owner":"krakphp","description":"API Platform Extra Bundle","archived":false,"fork":false,"pushed_at":"2020-12-30T18:14:25.000Z","size":25,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"0.x","last_synced_at":"2025-03-23T04:24:18.154Z","etag":null,"topics":["api-platform","symfony","symfony-bundle","symfony4"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/krakphp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-01T23:33:31.000Z","updated_at":"2024-03-17T20:12:43.000Z","dependencies_parsed_at":"2022-08-21T14:50:51.440Z","dependency_job_id":null,"html_url":"https://github.com/krakphp/api-platform-extra","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Fapi-platform-extra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Fapi-platform-extra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Fapi-platform-extra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Fapi-platform-extra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krakphp","download_url":"https://codeload.github.com/krakphp/api-platform-extra/tar.gz/refs/heads/0.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245791327,"owners_count":20672664,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-platform","symfony","symfony-bundle","symfony4"],"created_at":"2024-08-03T23:01:06.730Z","updated_at":"2025-03-27T05:30:50.969Z","avatar_url":"https://github.com/krakphp.png","language":"PHP","funding_links":[],"categories":["Table of Contents"],"sub_categories":["awesome-api-platform-bundles"],"readme":"# API Platform Extra\n\nAPI Platform Extra includes additional features or bug fixes into API Platform that haven't been released or won't be released.\n\n## Installation\n\nInstall with composer at `krak/api-platform-extra`.\n\n## Usage\n\nBy default all functionality provided by this library is *opt-in*, so you'll need to explicitly enable each feature in the config to make use of the features.\n\n### MessageBusDataPersister\n\nThe message bus data persister is enabled by default and controlled via the following config:\n\n```yaml\n\napi_platform_extra:\n    enable_message_bus_data_persister: true\n```\n\nThe `MessageBusDataPersister` will push any messages that aren't handled by the standard data persisters into the message bus.\n\nSo the only thing you need to do is simply just register message handlers for the ApiPlatform resources you want to handle via the message bus.\n\n### Additional Swagger Documentation\n\nThis allows you to merge and override in any additional swagger documentation to the generated swagger documentation from API Platform. This is useful if you need to provide any custom endpoints outside of your defined API Platform resources.\n\nThe configuration for defining the swagger file is here:\n\n```yaml\napi_platform_extra:\n    additional_swagger_path: \"%kernel.project_dir%/config/api_platform/swagger.yaml\"\n```\n\nIf that file exists, the additional swagger documentation will be merged. Else, nothing will happen.\n\n### Plural Data Path Segment Name Generator\n\nBy default, API Platform's inflector will transport any resource ending with `Data` as `Datas`. This fixes this specific use case, and could possibly extended to adjust multiple inflection fixes.\n\n### Constructor Denormalizer\n\nThis issue has actually been fixed but is pending release https://github.com/api-platform/core/pull/2178. This library will include that patch until api platform 2.4.0 is released.\n\nThis basically allows you to use constructor arguments with nested entities like so:\n\n```php\n\u003c?php\n\nnamespace App\\Entity;\n\nclass Book\n{\n    private $id;\n    private $name;\n    private $author;\n    private $createdAt;\n\n    public function __construct(string $name, Author $author) {\n        $this-\u003ename = $name;\n        $this-\u003eauthor = $author;\n        $this-\u003ecreatedAt = new \\DateTime();\n    }\n\n    public function getId(): ?int {\n        return $this-\u003eid;\n    }\n\n    public function getName(): string {\n        return $this-\u003ename;\n    }\n\n    public function getAuthor(): Author {\n        return $this-\u003eauthor;\n    }\n\n    public function getCreatedAt(): \\DateTimeInterface {\n        return $this-\u003ecreatedAt;\n    }\n}\n```\n\nThe actual POST API request for this would look like:\n\n```json\n{\n    \"name\": \"Book Name!\",\n    \"author\": \"/authors/1\"\n}\n```\n\n```yaml\napi_platform_extra:\n    enable_constructor_deserialization: true\n```\n\n### Operation Resource Classes\n\nThis feature is controlled via the following configuration:\n\n```yaml\napi_platform_extra:\n    enable_operation_resource_class: true\n```\n\nWhen enabled, this will allow with very simple configuration, the ability to define a specific resource class per operation. This is especially useful on POST collection operations where you want to use a special DTO resource instead of the actual Entity resource.\n\nHere's how you'd set it up:\n\n```php\n\u003c?php\n\n// under App\\Entity\nclass Book\n{\n    private $id;\n    private $name;\n    private $author;\n\n    public function __construct(string $name, Author $author) {\n        // assign\n    }\n}\n\n// under App\\DTO\nclass CreateBookRequest\n{\n    public $name;\n    public $authorName;\n\n    public function __construct(string $name, string $authorName) {\n        $this-\u003ename = $name;\n        $this-\u003eauthorName = $authorName;\n    }\n}\n\n// under App\\Service\nclass CreateBook\n{\n    public function __invoke(CreateBookRequest $req): Book {\n        // use the req data to actually create then pesist/flush the Book instance\n    }\n}\n```\n\nThen, you can configure the resources with the following yaml. You could use annotations or xml, but I find it more manageable to use yaml than either:\n\n```yaml\nApp\\Entity\\Book:\n  collectionOperations:\n    get: ~\n    post:\n      resource_class: App\\DTO\\CreateBookRequest\nApp\\DTO\\CreateBookRequest:\n  attributes:\n    schema_only: true\n```\n\nThis will make sure the documentation and the API use the schema of the `CreateBookRequest` instead of the normal `Book` entity schema. Using the `schema_only` attribute for the DTO ensures that no paths will be generated for that resource.\n\nYou'll need to make sure the Message Bus Data Persister is enabled so that the wiring of the Request to the `CreateBook` Service is done properly.\n\n\n### Definition Only Resources\n\nThere may be certain Resources that you want to only use for definitions, but use custom endpoints/swagger docs around them, to do that, you can just use the `schema_only: true` attribute.\n\n### ApiProperty Override\n\nAny definitions in the ApiProperty annotation do not override changes made from the Serializer Property Metadata Factory. You can control the ability for ApiProperty to override with the following option:\n\n```yaml\napi_platform_extra:\n    enable_overriding_annotation_property_metadata_factory: true\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrakphp%2Fapi-platform-extra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrakphp%2Fapi-platform-extra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrakphp%2Fapi-platform-extra/lists"}