andreaselia/laravel-api-to-postman

creating a new feature to make package generate other routes without having 'api' middleware

sepisoltani opened this issue · 6 comments

Hi @andreaselia
I am considering if we can add a new feature to make it possible to generate routes without having 'api' middleware only.
I saw in ExportPostmanCommand file that the package has this line of code :

 if (empty($middleware) || ! in_array('api', $middleware)) {
                    continue;
 }

I think hard coding the 'api' and just generating postman collection only for routes that have 'api' middleware is not a good way. In my project I have about 200 routes but the package can only generate roughly 20 routes in the exported collection.
I noticed that that's because other routes didn't have 'api' middleware.

Hey @sepisoltani,

What would your ideal outcome be here to match your needs? Would you prefer "api" was configurable or would an option to disable the api middleware check be better for you?

@andreaselia My idea is to defining a new config in config file . for example : 'ignored_middlewares'

then in the package we can check every route and then deny the one if it has middleware which exists in the 'ignored_middlewares' array.

I think 'ignored_middlewares' can have default value of 'web' . which ignore routes that hav 'web' middleware and users can add other middlewares in 'ignored_middlewares' array.

The issue with an ignored-first approach would be that nobody wants to have to enter all of the non-API related middleware that they wouldn't want included.

We would do an included-first approach, where it's something like included_middleware and that would be something like:

'included_middleware' => ['api'],

This would then allow you to add whatever middleware names you'd like to the list.

Unrelated to this comment, but related to this issue - Are you trying to include web routes within your Postman export?

@andreaselia I do not need to include web routes in the postman collection . but I wanna include routes with custom middlewares . something like this :

 Route::group(['middleware' => ['web_service', 'role:user']], function () {

});

'included_middleware' would be nice

@sepisoltani new config option added in v1.6.4