New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EZP-25613 Add a way to register resources with the rest root #1619
Conversation
tests fail on RootTest. This is because the Root now expects an array of Resources to be provided. Should I pass an arbitrary array of resources and test them or should I replicate the hard coded resources in the original Root value object visitor by creating array of resources based on the resources in default_settings.yml? |
Can you please create an issue on JIRA if there isn't one, and link the PR to the issue ? I'll assign it to you and move it to dev. |
*/ | ||
class Resource extends RestValue | ||
{ | ||
public $name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
phpdoc with description + example for public properties of value objects.
Looks good overall. One thing I'd like to see improved is the separation between the Controller and the Root Value construction. Ideally, the Root value would be obtained via a service, and that service would have an implementation that uses an array of Resource objects, and uses the expression engine to generate the hrefs. |
Test are failing because the default_settings.yml are not loaded so the resources are not defined. They pass locally. Ideas on how I can fix this? |
/** @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\EzPublishCoreExtension $eZExtension */ | ||
$eZExtension = $container->getExtension('ezpublish'); | ||
$eZExtension->addConfigParser(new ConfigParser\RestResources()); | ||
$eZExtension->addDefaultSettings(__DIR__ . '/Resources/config', ['default_settings.yml']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was loading the default_settings.yml
file moved here? I don't think there's a reason for that.
I suspect this is the reason why the tests are not loading the config.
Okay, this should cover it. It's mostly about naming, but as Camus said: "Misnaming things adds to the evil of the world." Also, if you want to give it a try, it would be good to improve the REST functional tests, and check that we have the links we expect. This change removes some coverage from the visitor's unit tests, and I think we want to check that the root resource behaves as we expect it to. |
@@ -4,3 +4,83 @@ parameters: | |||
|
|||
# URI part that all REST routes begin with. By this a REST request is recognized. | |||
ezpublish_rest.path_prefix: /api/ezp/v2 | |||
|
|||
ezpublish_rest.root_resources: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you write directly to the siteaccess aware container config ? You could then skip loading the container config altogether: https://github.com/ezsystems/ezpublish-kernel/pull/1619/files#diff-0b45d72cefd7a4d4849d6d15e1527b31R40.
ezsettings.default.rest_root_resources:
content:
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this, this simpler. In service.yml
I can just pass '$rest_root_resources$'
. We would lose the checks from the semantic config.
To add a test for the default configured resources. What would be a good test name? Would I just load in the resources from the default_settings.yml build a Root and test against the original tests removed in RootTest? |
I meant a functional test, that uses the actual application, and validates the responses. |
@bdunogier Not sure if you saw but I had added the tests. |
I had a quick look on mobile, it seems fine. I'll check again from a proper
device (easter holiday here).
|
So how do we actually register custom root resources, apart from adding directly to internal Other than that: 👍 |
/** | ||
* This class represents a resource. | ||
*/ | ||
class Resource extends RestValue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too bad RestValue doesn't implement the base ValueObject. We could have used the same properties scheme :/
nice! besides the missing JIRA issue +1 |
$resources[] = new Values\Resource( | ||
$name, | ||
$resource['mediaType'], | ||
$language->evaluate($resource['href'], [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have a try/catch here ? what will evaluate()
do if the expression is invalid ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dpobel Missing JIRA issue? https://jira.ez.no/browse/EZP-25613
@bdunogier It throws an SyntaxError exception. Do you want the message more specific like new SyntaxError("Invalid expression '${resource['href']}' in resource '$name'");
or throw a different exception? If not to throw an exception then what?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An exception is good. It should end up as a 500 in REST, and that's good, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be good as is. evaluate
will throw an SyntaxError
already.
Great, let's merge this then. We can take care of semantic config in another pull-request. |
Not sure it counts but you can do:
|
This adds the ability to add resources in the rest root so rest consumers can discover them. For example you can register the resource and use the capi auto discovery to find the uri for the resource.
To add a resource a bundle would add the resource using the PrependExtensionInterface and pre-pending the new resource to the config.