Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When adding object[] in Docblock it is wrongly sending request #923

Open
1 task done
jerry4rahul opened this issue Nov 27, 2024 · 3 comments
Open
1 task done

When adding object[] in Docblock it is wrongly sending request #923

jerry4rahul opened this issue Nov 27, 2024 · 3 comments
Labels
awaiting requester action bug Something isn't working

Comments

@jerry4rahul
Copy link

jerry4rahul commented Nov 27, 2024

Scribe version

4.38.0

PHP version

8.2.12

Framework

Laravel

Framework version

11.31

Scribe config

auth.enabled => true

What happened?

/**
     * Create a new event
     *
     * This endpoint is used to create a new event.
     *
     * @authenticated
     *
     * @bodyParam media file required The cover image of the event.
     * @bodyParam title string required The title of the event. Example: My Event
     * @bodyParam description string required The description of the event. Example: This is an event
     * @bodyParam start_date date required The start date of the event. Example: 27-11-2024 10:00
     * @bodyParam end_date date required The end date of the event. Example: 27-11-2024 12:00
     * @bodyParam schedules object[] The schedules of the event.
     * @bodyParam schedules[].date date required The date of the schedule. Example: 27-11-2024 10:00
     * @bodyParam schedules[].detail string required The detail of the schedule. Example: This is a schedule
     */
    public function store(Request $request): JsonResponse
    {
        $data = $request->validate([
            'media' => 'required|file|mimes:jpeg,png,jpg|max:2048',
            'title' => 'required|string|max:255',
            'description' => 'required|string',
            'start_date' => 'required|date_format:d-m-Y H:i',
            'end_date' => 'required|date_format:d-m-Y H:i',
            'schedules' => 'nullable|array',
            'schedules.*.date' => 'required|date_format:d-m-Y H:i',
            'schedules.*.detail' => 'required|string'
        ]);
    }

For the above, Content-Type: multipart/form-data When i click on Send Request it sending schedules_0_date: 27-11-2024 10:00 and schedules_0_detail: 'This is a schedule'.

It should be send as
schedules: [{ date: "27-11-2024 10:00" detail: "This is a schedule" }]
Screenshot 2024-11-27 at 21-08-09 Laravel Documentation
Screenshot 2024-11-27 210950

Docs

@jerry4rahul jerry4rahul added bug Something isn't working triage labels Nov 27, 2024
@shalvah
Copy link
Contributor

shalvah commented Nov 29, 2024

Is Content-Type: multipart/form-data the correct content type here? Because it looks like you want it to be sent as JSON.

@jerry4rahul
Copy link
Author

Is Content-Type: multipart/form-data the correct content type here? Because it looks like you want it to be sent as JSON.

I have added media upload in the request which will make the Content-Type: multipart/form-data

@shalvah
Copy link
Contributor

shalvah commented Dec 8, 2024

In that case, the rest of the request body would be sent as form data (eg a=b&c=d). Can you share a screenshot of what is actually sent (browser DevTools)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting requester action bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants