andreaselia / laravel-api-to-postman

Generate a Postman collection automatically from your Laravel API
MIT License
958 stars 99 forks source link

Idea, somehow get data required and optional from FormRequest #89

Closed AucT closed 11 months ago

AucT commented 1 year ago

I think would be noice to have autofetching data from rules in FromRequest and add this inputs to postman.

AucT commented 1 year ago

one more thing. I think it is better to make this tool external.

andreaselia commented 1 year ago

I feel like there would be a considerable amount of work to be able to implement auto data placement for rules, although not impossible. What do you think @tomirons? Maybe a version 2 of the package thing?

@AucT what do you mean about making the tool external? 😄

AucT commented 1 year ago

Something like binary u download and run. Or at least require dev

tomirons commented 1 year ago

@andreaselia is right, it would be a very heavy lift in order to "fake" the data properly. I've had this thought for v2 and I keep going in circles about how to hand it. The simplest way I can think of would be to map the type of attribute to the equivalent in faker, i.e. 'name' => 'string' would be faker()->string().

There aren't any plans currently to make this an executable.

kodunmi commented 1 year ago

Hi Team, when I enable_formdata postman API rejects my collection "name":"malformedRequestError","message":"Found 241 errors with the supplied collection."

andreaselia commented 1 year ago

@kodunmi could you post the collection here please? Feel free to remove any sensitive data.

kodunmi commented 1 year ago

Okay bro @andreaselia

I have been trying all I can be it wouldn't just work, any help would be greatly appreciated. spv2devapi.json

kodunmi commented 1 year ago

I can import it directly, but it doesn't allow me, when I try creating collection via API

andreaselia commented 1 year ago

Have you tried commenting out all of the routes apart from one, and generating it to see if it works?

Re-enable routes one by one to find the problematic one perhaps?

kodunmi commented 1 year ago

Okay, I will try that today and get back to you.

kodunmi commented 1 year ago

Hi @andreaselia thanks for your help

I just left only the login route and I still got errors

Route::prefix('users')->group(function () { Route::prefix('auth')->group(function () { Route::post('login', LoginController::class); }); });

My request rules

public function rules(): array { return [ 'phone' => ['required', 'string'], 'phone_code' => ['required_with:phone', 'string', Rule::exists('countries', 'phone_code')], 'password' => ['required', 'string'], ]; }

Response Data: {"error":{"name":"malformedRequestError","message":"Found 8 errors with the supplied collection.","details":["item/0/request/body/urlencoded/0/value: must be string","item/0/request/body/urlencoded/1/value: must be string","item/0/request/body: must be null","item/0/request/body: must match exactly one schema in oneOf","item/0/request: must be string","item/0/request: must match exactly one schema in oneOf","item/0: must have required property 'item'","item/0: must match exactly one schema in oneOf"]}}

My setting

'structured' => true, 'enable_formdata' => true,

andreaselia commented 1 year ago

Thanks for the information. One thing I can see is there's no name on your route.

// without name
Route::post('login', LoginController::class);

// with name
Route::post('login', LoginController::class)->name('login');
kodunmi commented 1 year ago

Okay @andreaselia, let's try to add a name and see.

kodunmi commented 1 year ago

Hi, @andreaselia I love this package too much to give up.

I have added a name to the login route, but it still 400

Route::post('login', LoginController::class)->name('login');

The package works just fine if I don't enable enable_formdata, but immediately after I set it to try, we start having issues

andreaselia commented 1 year ago

@kodunmi thank you for your package love! I will certainly try to resolve this issue with you.

Do you have time to try to reproduce this issue with a test case in the package (if you know how to do that)? It would help us greatly in trying to reproduce the issue.

kodunmi commented 1 year ago

Okay, I will try to do that today, so I should do the following

  1. Create a fresh laravel project
  2. Install package
  3. Add some route
  4. Enable form_data
  5. Add actions to push collection to postman using api
  6. Add you to the repo

Would this be okay? @andreaselia

andreaselia commented 1 year ago

That would be great @kodunmi, thank you very much 😄

andreaselia commented 11 months ago

Going to close this for now. If you're able to reproduce this in a fresh repo that we could try it out in that would be great @kodunmi. I'll re-open this if an issue is found in said replication repo.