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

Scribe sends integers as strings in JSON? #640

Closed
alexweb opened this issue Mar 28, 2023 · 7 comments
Closed

Scribe sends integers as strings in JSON? #640

alexweb opened this issue Mar 28, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@alexweb
Copy link

alexweb commented Mar 28, 2023

Hi everyone.
Looks like scribe doesn't work properly with integer type when sending JSON?
My annotations look like this (see id type):

    /**
     * @group Coupon
     *
     * Update Coupon
     * @authenticated
     * @bodyParam data object required
     * @bodyParam data.id int required Example: 1
     * @bodyParam data.name string required Example: COUPONNAME
     * @bodyParam data.percentage int required Example: 30
     * @bodyParam data.permanent bool required Example: true
     * @bodyParam data.startDate string optional Example: 2023-01-05T14:48:00.000Z
     * @bodyParam data.endDate string optional Example: 2023-10-05T14:48:00.000Z
     * @throws Error422Exception|Throwable
     */

Resulting request:

{
  "id": "1",
  "name": "COUPONNAME",
  "percentage": "30",
  "permanent": true,
  "startDate": "2023-01-05T14:48:00.000Z",
  "endDate": "2023-10-05T14:48:00.000Z"
}

Looks like Scribe still wraps integers into quotes?

Or is there any option to change this behaviour? I would like it to send integer as integer instead (see id and percentage):

{
  "id": 1,
  "name": "COUPONNAME",
  "percentage": 30,
  "permanent": true,
  "startDate": "2023-01-05T14:48:00.000Z",
  "endDate": "2023-10-05T14:48:00.000Z"
}

Screenshot 2023-03-28 at 12 48 03

@alexweb alexweb added the bug Something isn't working label Mar 28, 2023
@shalvah
Copy link
Contributor

shalvah commented Mar 28, 2023

It's probably because when you're reading a text input in HTML, every value is a string (and Scribe doesn't do any conversion). The fix would probably be to render a number input for number types (rather than a text input). See

— we currently render booleans specially, but not numbers. PR welcome.

@alexweb
Copy link
Author

alexweb commented Mar 31, 2023

Thanks for the reply. Will need to fix this

@shalvah
Copy link
Contributor

shalvah commented Aug 19, 2023

Okay, I'm wrong. We do set it.

$inputType = match($baseType) {
'number', 'integer' => 'number',
'file' => 'file',
default => 'text',
};

I think it's the HTML/JS. IIRC, reading an input value in JS always gives you a string, even if the input type is number.

@mselmanyildirim
Copy link

Do we have a workaround to send booleans from Scribe UI?
Similar to reported above, when I generate the document via Laravel's validation as follows:

image

and select the parameter via Scribe API UI:

image

I get the following error:

image

When I try to debug with the following:

image

I get this result, saying it is not boolean, but rather string:

image

What I finally did as a workaround is adding the type as Enum in the codeblock as the following:

image

And Scribe UI becomes like:

image

It still gets sent as string, but at least Laravel validates it to be a boolean. It is not very handsome comparing to radio switch though 😉

@shalvah
Copy link
Contributor

shalvah commented Oct 4, 2023

IIRC, reading an input value in JS always gives you a string

PRs appreciated

@ptelevich
Copy link
Contributor

@shalvah got it, #830

@shalvah
Copy link
Contributor

shalvah commented Mar 26, 2024

fixed in 4.35.0

@shalvah shalvah closed this as completed Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants