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

Routes are not grouped properly into a subdirectory.

Open mikevandiepen opened this issue 1 year ago • 5 comments

When exporting the postman suite my routes are not grouped "correctly", these routes:

ROUTE: api/v1/versions/{version}/equipment/{equipment}/accessories NAME: versions.equipment.equipment-accessories.index

ROUTE: api/v1/versions/{version}/equipment/{equipment}/accessories NAME: versions.equipment.equipment-accessories.sync

ROUTE: api/v1/versions/{version}/equipment/{equipment}/accessories/{accessory} NAME: versions.equipment.equipment-accessories.attach

ROUTE: api/v1/versions/{version}/equipment/{equipment}/accessories/{accessory} NAME: versions.equipment.equipment-accessories.detach

Actual output: image

Expected output: image

I believe this issue is caused by mapping it using the "namespace" instead of the route-name?

This is my controller:

<?php

namespace App\Http\Controllers;

class EquipmentEquipmentAccessoryController extends Controller
{
    public function index(Version $version, Equipment $equipment): Response {}
    public function sync(Version $version, Equipment $equipment, Request $request): Response {}
    public function attach(Version $version, Equipment $equipment, EquipmentAccessory $accessory): Response {}
    public function detach(Version $version, Equipment $equipment, EquipmentAccessory $accessory): Response {}
}

mikevandiepen avatar Aug 01 '24 14:08 mikevandiepen

Hey @mikevandiepen,

They look grouped correctly to me. Each route is under "equipment-accessories" correctly and them being within folders as per the end of the route name makes it easily readable at a glance which route belongs to which without having to can your eyes across the length of the entire route.

andreaselia avatar Aug 01 '24 14:08 andreaselia

What I mean is the four separate requests belong to the same controller and are grouped to the same route-name, only a different identifier (..*.{x,y,z}). These requests are put in separate folders instead of grouped inside the parent, but if it is intentional then I understand it, it just threw me off haha

mikevandiepen avatar Aug 08 '24 17:08 mikevandiepen

Definitely understand, and it is indeed intentional so that at a glance you can see which route request is the "attach" one for example, or the "sync" one and so on, without having to put much thought into the request method (like PUT) or having to take a longer look at the route name.

I'd be open to a PR to add a config option for flattening this structure though if it were something you'd like to take on?

andreaselia avatar Aug 09 '24 08:08 andreaselia

If you can point me to the right direction I might try this weekend! A little clue could be a nice headstart :)

mikevandiepen avatar Aug 09 '24 10:08 mikevandiepen

Sure thing, @mikevandiepen.

You'll probably want to add a config option like 'flattened_routes' => false, (default to false), and if it's true, then you'll want to avoid adding the last route name segment as a nested directory.

This should be roughly the right area, as this is where we handle the other config options related to the route folder conventions.

https://github.com/andreaselia/laravel-api-to-postman/blob/main/src/Processors/RouteProcessor.php#L109

I'd recommend starting with a test case (we have existing ones for ensuring outputs are a certain way already), so you can duplicate one and modify it to suit what you expect the output to be, and then do the code changes necessary to get it to pass.

andreaselia avatar Aug 09 '24 19:08 andreaselia

Going to close this to keep the repository manageable, but if you'd like to re-visit this in the future feel free to re-open it or let me know and I'd be happy to.

andreaselia avatar Oct 28 '24 22:10 andreaselia