-
-
Notifications
You must be signed in to change notification settings - Fork 923
Closed
Labels
Description
Description
I like using ApiPlatform but I find the configuration painfull to set up (lack of autocompletion, no reusability, no automation, break easily without usefull warning...).
Being able to configure API platform using simple PHP class would solve these problems.
Example
function __invoke(ApiConfigurator $configurator) {
// itemOperations
$operations = array_map(function ($method) {
return (new ItemOperation(Comment::class, $method))
->setNormalizationContext(['read:comment'], 'ReadComment')
->setSecurity($method === 'GET' ? CommentVoter::READ : CommentVoter::EDIT, 'object');
;
}, ['GET','DELETE','PUT']);
$operations[] = new ItemOperation(Comment::class, 'patch');
// collection operation
$operations[] = new CollectionOperation(Comment::class, 'get')
$configurator->addOperations($operations);
}
This approach solve many problems I have with the configuration right now :
- It's self documenting. It's easier to discover features reading the source code
- It's easier to automate some features using functions or custom classes.
- It's easier to detect problems when the configuration API changes using static analysis.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
[-]PHP based configuration[/-][+][RFC] PHP based configuration[/+]alanpoulain commentedon May 12, 2020
Somehow related: symfony/symfony#36778
dunglas commentedon May 12, 2020
+1 on my side to have a PHP configuration. The metadata subsystem already allows to plug any source of configuration, so it should not be too hard. I agree with @alanpoulain, it must be consistent with what Symfony provides.
@Grafikart are you using PHPStorm? Is yes, the PHP Annotations plugin will enable auto completion for almost everything. As we provide XSDs, autocompletion should also work with XML config file (but TBH I’ve not tested).
Grafikart commentedon May 12, 2020
@dunglas I'm using PHPStorm and it offers autocompletion for top level property but doesn't work for parameters for operations for instance. Also I couldn't figure out how to use constant for the security is_granted.
It's easy to mix up normalizationContext and normalization_context and with annotation you have no feedback for this kind of typo :(
I'm not a fan of the symfony suggestion since it's not easy to know what options are available. But It could work since it could be decorated easily.
weaverryan commentedon Aug 13, 2020
I would love this feature also. API Platform metadata is too powerful (and thus, complex) to fit nicely into annotations (and I normally LOVE annotations). I also just replied to a user on SymfonyCasts that loves API Platform, but dislikes the annotations.
Getting this BEST "syntax" of a config system is the problem. If someone has some time to work on it, I would be very happy with an "first try" imperfect system. Once we have that, I have no doubt that the community will start iterating on it to improve it. But we need that first version!
Cheers!
stale commentedon Nov 5, 2022
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
soyuka commentedon Nov 5, 2022
Its easier in 3.0 closing this for now