laravel-api-to-postman
laravel-api-to-postman copied to clipboard
The second parameter in nested resources are renderend as `{param}` instead of `:param`
The second parameter in nested resources are renderend as {param} instead of :param. This adds extra work configuring the postman suite since you need to re-type all the parameters and you can't easily access them.
Thanks for this @mikevandiepen, do you have some example routes to reproduce this so I can try to add a test case and work on it?
As you can see the parameter for show audit-logs is rendered {audit_log} instead of :audit_log making it not show up in the parameter list below. For my application I have routes nested 6 layers deep highlighting this issue a lot.
See the docs on nested resources if you're unfamiliar with the concept. https://laravel.com/docs/11.x/controllers#restful-nested-resources
Thank you for the info @mikevandiepen, will take a look into this. Surprised this has only been caught by yourself haha, will add this into the test suite too.
@mikevandiepen do you do public function show($auditLog) so it inherits the param or public function show(AuditLog $auditLog) so it's route model bound?
@mikevandiepen I have been unable to reproduce this locally, please could you provide reproducible steps?
I added a test case to the repository in the below draft PR, and failed to reproduce it there too. I also downloaded the exports from test cases and it seems to be picking up the :user and :post correctly.
https://github.com/andreaselia/laravel-api-to-postman/pull/103/files
cc: @tomirons
Yep, I'm route-model-binding both the $user and the $auditLog, see the controller setup below;
Sorry for the late response, got carried away with other work. If you can point me the spot where it parses the params I might fork the project and give it a shot myself to reproducing it. Anyways OSD is thankless work for much of the time so hereby thanks for your work on this project, its awesome!
@mikevandiepen do you do
public function show($auditLog)so it inherits the param orpublic function show(AuditLog $auditLog)so it's route model bound?
Might it have something to do with your scenario having the route: users.posts and mine has users.audit-logs (having the hyphen) in between seeing it as audit and logs therefore not overwriting the {audit_logs} parameter for postman.
I don't have any clue about the internals, only took a quick look... thinking out loud here :)
Note:
This behaviour both happens on Laravel 10 and Laravel 11. I haven't adjusted the RouteServiceProvider or did anything uncommon on the app.php file
@mikevandiepen good spot, that was it! I've updated my test case in the draft PR to use the hyphen and "audit logs" instead of "posts" and now I'm able to reproduce it. Thanks for your help, and I'm glad you find the package helpful.
@andreaselia Awesome, I suggest adding more scenario's, multiple hyphens, lower-case, upper-case under_scores etc. Laravel is quite forgiving and I can see this going wrong in other cases as well.
@andreaselia Awesome, I suggest adding more scenario's, multiple hyphens, lower-case, upper-case under_scores etc. Laravel is quite forgiving and I can see this going wrong in other cases as well.
Good idea! Added a few cases here: https://github.com/andreaselia/laravel-api-to-postman/pull/103
@mikevandiepen this has been merged and a release tagged by @tomirons, please let us know how it goes.
@andreaselia Updating the package and exporting the suite 🚀
@andreaselia I'd call it a massive success, cheers for the work!! [--- redacted ---]
Awesome! Thanks again for helping us out with it.