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

Add support for bigint #824

Closed
mkermani144 opened this issue Apr 16, 2023 · 11 comments · Fixed by #829
Closed

Add support for bigint #824

mkermani144 opened this issue Apr 16, 2023 · 11 comments · Fixed by #829

Comments

@mkermani144
Copy link
Contributor

mkermani144 commented Apr 16, 2023

What happens?

When we generate code using an open api spec which contains int64 numbers, they are converted to numbers in the generated code.

What were you expecting to happen?

The int64 values should be converted to bigint, as js Number.MAX_SAFE_INTEGER cannot contain very large numbers (larger than 2^53).

Anyway, I think this should be an option, not a default.

@mkermani144
Copy link
Contributor Author

I wonder if the main part of the fix is as simple as changing this:

https://github.com/anymaniax/orval/blob/94e2c8e4d8d07c76d249e90b6cc07c225e177ee0/packages/core/src/getters/scalar.ts#L31

to this:

let value = item.format === 'int64' ? 'bigint' : 'number'; 

@anymaniax
Copy link
Collaborator

Hello @mkermani144, indeed should be only that

@mkermani144
Copy link
Contributor Author

mkermani144 commented Apr 18, 2023

@anymaniax
Hi,
I can open a PR if you want.

But I still don't know if this should be the default behavior, or a configuration option.

@anymaniax
Copy link
Collaborator

@mkermani144 with pleasure!

@mkermani144
Copy link
Contributor Author

Opened #829.

@anymaniax
Copy link
Collaborator

Merged @mkermani144. thanks

@RichardLindhout
Copy link

This results in a lot of frontend error can we please make this optional?

@RichardLindhout
Copy link

Scherm­afbeelding 2023-04-24 om 17 08 51
Stuff like this

@anymaniax
Copy link
Collaborator

sure @RichardLindhout can you do a pull request with that?

@GBDev13
Copy link
Contributor

GBDev13 commented Apr 24, 2023

@anymaniax would that work well? #841

@lukaw3d
Copy link
Contributor

lukaw3d commented May 8, 2023

Can you add a test where #829 works?

When targeting react-query neither bigint parameters nor bigint responses work correctly.

paths:
  /big-param:
    get:
      parameters:
        - in: query
          name: aaa
          schema:
            type: integer
            format: int64

useGetBigParam({ aaa: 5n }) throws Uncaught TypeError: Do not know how to serialize a BigInt

paths:
  /big-response:
    get:
      responses:
        '200':
          description: a
          content:
            application/json:
              schema:
                type: object
                properties:
                  aaa:
                    type: integer
                    format: int64

useGetBigResponse().data?.data.aaa is typed as bigint | undefined but is still number | undefined in runtime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants