Skip to content
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

LoadableRoute::setUrl() doesn't empty the parameter array #663

Open
SunflowerFuchs opened this issue May 5, 2023 · 0 comments
Open

LoadableRoute::setUrl() doesn't empty the parameter array #663

SunflowerFuchs opened this issue May 5, 2023 · 0 comments

Comments

@SunflowerFuchs
Copy link
Contributor

Current behavior

Lets take the following example snippet:

$route = SimpleRouter::get('/route/with/{parameter}', function() {});
$parameters  = $route->getParameters();
// $parameters == [ 'parameter' => null ]

$route->setUrl('/route/with/{differentparameter}');
$parameters = $route->getParameters();
// $parameters == [ 'differentparameter' => null ]

$route->setUrl('/route/without/parameter');
$parameters = $route->getParameters();
// $parameters == [ 'differentparameter' => null ]

The last setUrl() call doesn't empty the parameters, and instead keeps them as before.

Expected behavior

The last $parameters should be empty, since the URL has no parameters.

Context

We're currently generating an OpenAPI specification based on all of our registered routes. Since OpenAPI doesn't allow route parameters to be optional, we have to split the routes in two (/route/{optional?} to /route and /route/optional), which is easily possible with a simple clone $route followed by setUrl(). But due to the parameters not being cleared we get problems further down the line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant