laravel-api-to-postman icon indicating copy to clipboard operation
laravel-api-to-postman copied to clipboard

The second parameter in nested resources are renderend as `{param}` instead of `:param`

Open mikevandiepen opened this issue 1 year ago • 6 comments

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.

mikevandiepen avatar May 05 '24 10:05 mikevandiepen

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?

andreaselia avatar May 05 '24 11:05 andreaselia

image image

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

mikevandiepen avatar May 05 '24 11:05 mikevandiepen

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.

andreaselia avatar May 06 '24 18:05 andreaselia

@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?

andreaselia avatar May 06 '24 21:05 andreaselia

@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

andreaselia avatar May 06 '24 21:05 andreaselia

cc: @tomirons

andreaselia avatar May 06 '24 21:05 andreaselia

Yep, I'm route-model-binding both the $user and the $auditLog, see the controller setup below; image

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 avatar May 08 '24 05:05 mikevandiepen

@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?

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 avatar May 08 '24 05:05 mikevandiepen

@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 avatar May 08 '24 10:05 andreaselia

@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.

mikevandiepen avatar May 08 '24 10:05 mikevandiepen

@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

andreaselia avatar May 08 '24 16:05 andreaselia

@mikevandiepen this has been merged and a release tagged by @tomirons, please let us know how it goes.

andreaselia avatar May 10 '24 07:05 andreaselia

@andreaselia Updating the package and exporting the suite 🚀

mikevandiepen avatar May 10 '24 15:05 mikevandiepen

@andreaselia I'd call it a massive success, cheers for the work!! [--- redacted ---]

mikevandiepen avatar May 10 '24 15:05 mikevandiepen

Awesome! Thanks again for helping us out with it.

andreaselia avatar May 10 '24 21:05 andreaselia