reindert-vetter / api-version-control

A Laravel package to manage versions of endpoints in an elegant way

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Trouble getting version statement to work

VFAndrew opened this issue · comments

Getting exception Attempt to assign property "permit" on string when I am trying to implement a test version statement.

added $pipe = new $pipe(); before line 81 and also in file ApiVersionControl.php I reordered the chaining to ->filterByVersionCompare() ->permitVersionStatement()

it now seems to work as intended. I am on php8.1

Thanks! Feel free to make a pull request. Otherwise I will process it after work.

@VFAndrew

added $pipe = new $pipe(); before line 81 and also in file ApiVersionControl.php

I was able to reproduce your error and solve it in PR #11

I reordered the chaining to ->filterByVersionCompare() ->permitVersionStatement()

Do you remember what it was for? Is the above fix sufficient for you?

@VFAndrew

added $pipe = new $pipe(); before line 81 and also in file ApiVersionControl.php

I was able to reproduce your error and solve it in PR #11

I reordered the chaining to ->filterByVersionCompare() ->permitVersionStatement()

Do you remember what it was for? Is the above fix sufficient for you?

in my api_version_control.php
'catalog.search' => [ '<=1' => [ Test::class, ], ],

Originally when ->permitVersionStatement() was run before ->filterByVersionCompare() The VersionStatement $permit would be set to true always regardless of matched version.

GET /v2/catalog/search would return true for Test version statement
GET /v1/catalog/search would return true for Test version statement

When I put ->filterByVersionCompare() before ->permitVersionStatement() my version would be filtered before the statement $permit was set to true.

GET /v2/catalog/search would return false for Test version statement
GET /v1/catalog/search would return true for Test version statement

That is actually quite true indeed. Thanks for debugging!

There you have it; even though I have small unit tests for everything, I haven't fully tested everything yet.

My pleasure. Thanks for providing an elegant way to API version control. Out of all the designs I researched this one seems to be the most forward thinking.

Thank you. It surprised me at the time that there weren't many solutions for it. Are you familiar with other packages?

In my opinion, it was the only way to support multiple versions with 1 controller.

Fixed in 2.1.6.