It would be nice to configure global defaults for all class marked with @ApiResource (or configured in YAML/XML etc).
It could be a new config section such as the following:
api_platform:
defaults:
attributes: # ...
item_operations: # ...
collection_operations: # ...
normalization_context: # ...
graphql: # ...
# ...
# All properties defined in https://github.com/api-platform/core/blob/master/src/Annotation/ApiResource.php should be configurable
For instance, it would allow to make the API globally read only:
api_platform:
defaults:
itemOperations: ["get"]
collectionOperations: ["get"]
Other example, enable Mercure for all resource:
api_platform:
defaults:
mercure: true
Or always use Messenger:
api_platform:
defaults:
messenger: true
Implementing this feature should be trivial:
Most options are stored in metadata's attributes, some other are top level metadata properties (itemCollections and collectionOperations and graphql AFAIR). Basically, the content of defaults should be passed as-is to resources' attributes, except the special one previously mentioned.
Existing configuration option for resource attributes (pagination, cache headers...) should probably be deprecated for consistency.
It would be nice to configure global defaults for all class marked with
@ApiResource(or configured in YAML/XML etc).It could be a new config section such as the following:
For instance, it would allow to make the API globally read only:
Other example, enable Mercure for all resource:
Or always use Messenger:
Implementing this feature should be trivial:
ResourceMetadataFactory, with a low priority, applying the defaults if not setMost options are stored in metadata's attributes, some other are top level metadata properties (itemCollections and collectionOperations and graphql AFAIR). Basically, the content of
defaultsshould be passed as-is to resources' attributes, except the special one previously mentioned.Existing configuration option for resource attributes (pagination, cache headers...) should probably be deprecated for consistency.