You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The text was updated successfully, but these errors were encountered:
RealJTG
changed the title
Requirements are actually not required for generating URL in some cases
Parameters without defaults are not required to generate URL in some cases
Nov 14, 2019
Hi @RealJTG, thanks for pointing out this issue.
It was actually introduced in 8298523#diff-8e1e018bfe2bd15df10d1864a922ff0cR64, the diff you indicated was just a rewrite of the same code.
It has to do with the definition of optional parameters in Symfony, of which more can be read here: https://symfony.com/doc/current/routing.html#optional-parameters.
The current implementation in this bundle does not comply with the requirements written there.
I think it is not doable to make it comply with that, since defaults for parameters can be implemented by giving a default value in the PHP method definition when using annotations.
These default values are not available to the tools generating the routing export, so instead of that it is implemented by looking for the first defined variable routing part (or text part), after which each variable is required to be defined since otherwise the route will be invalid.
Any routes not sticking to this assumption will be invalid for that place, which will lead to interesting behavior.
Do you have any suggestions on how to implement this in a better way?
We cannot simply assume every parameter to be defined or have a default in the export, since that is not required by Symfony.
Route definition
translated into this
Cases:
Works as expected when setting an optional parameter:
Setting
optional = false
by default here https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/blob/master/Resources/public/js/router.js#L293 fixes my issue, although I haven't tested other cases yet and not quite sure what is the purpose of this variable at all.The text was updated successfully, but these errors were encountered: