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

GET request with formData for query parameters

Open mateusz-peczkowski opened this issue 1 year ago • 2 comments

Hi,

I have a problem with generating correct documentation whenever I have a GET request that has form data for "query" parameters. It resolves URL for Postman as: ?lat&lng&distance&start_date&end_date&filters instead of: {{base_url}}/api/v1/garages/find?lat&lng&distance&start_date&end_date&filters while on the name there is the correct route path... image

Version of package: v2.0.2 Version of Laravel: v10.48.3

Here is my function:

/**
     * Find available garages
     */
    public function index(FindRequest $request)
    {
        $garageAvailableFor = 'visitor';

        $user = $this->guard()->user();

        if ($user && $user->employee_id)
            $garageAvailableFor = 'employee';

        $departmentId = NULL;
        $workLocationId = NULL;
        $customerDailyInventoryExemption = false;

        if ($user) {
            $departmentId = $this->guard()->user()->entity_work_location_department_id;
            $workLocationId = $this->guard()->user()->entity_work_location_id;
            $customerDailyInventoryExemption = !!$user->daily_inventory_exemption;
        }

        return response()->json(
            $this->garages->getFilteredDaily(
                !is_null($request->get('lat')) ? $request->get('lat') : NULL,
                !is_null($request->get('lng')) ? $request->get('lng') : NULL,
                !is_null($request->get('distance')) ? $request->get('distance') : NULL,
                $request->get('start_date') ?: NULL,
                $request->get('end_date') ?: NULL,
                $request->get('filters') ?: [],
                $garageAvailableFor,
                $workLocationId,
                $departmentId,
                $customerDailyInventoryExemption
            )
        );
    }

And here is a FindRequest:

<?php

namespace App\Http\Requests\Api\Garage;

use App\Http\Requests\FormRequest;

class FindRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'lat'        => 'required_with:lng,distance',
            'lng'        => 'required_with:lat,distance',
            'distance'   => 'required_with:lat,lng',
            'start_date' => 'required_with:end_date|date',
            'end_date'   => 'required_with:start_date|date',
            'filters'    => 'sometimes|array',
        ];
    }
}

Opposite of that everything looks nice :) The only question I have is whether there is an option to add Authorization headers per middleware group? I have different key name and value for /api and for /webhooks

mateusz-peczkowski avatar Apr 04 '24 12:04 mateusz-peczkowski

Hey @mateusz-peczkowski, do you have the route from your routes file too please?

andreaselia avatar Apr 04 '24 16:04 andreaselia

#97 Should solve this issue as this is what i had as well

Menkveld-24 avatar Apr 15 '24 07:04 Menkveld-24