Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

BigInt is not supported for output validation #264

Open
reteps opened this issue Feb 26, 2023 · 5 comments
Open

BigInt is not supported for output validation #264

reteps opened this issue Feb 26, 2023 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@reteps
Copy link

reteps commented Feb 26, 2023

I have code with the following output validator:

.output(z.array(z.bigint()))

Which gives me a "500 Internal Server Error".

However, using,

.output(z.array(z.number()))

Works fine.

@stale
Copy link

stale bot commented Apr 27, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 27, 2023
@stale stale bot closed this as completed May 4, 2023
@reteps
Copy link
Author

reteps commented May 11, 2023

not completed

@jlalmes jlalmes removed the stale label May 24, 2023
@jlalmes jlalmes reopened this May 24, 2023
@jlalmes
Copy link
Collaborator

jlalmes commented May 24, 2023

Hi @reteps, can you share the full error & possibly a reproduction? Is this related to this issue? 👉 #275

@KATT
Copy link
Member

KATT commented May 24, 2023

BigInt isn't a JSON-thing, sounds weird that an OpenAPI compat API would support it.

If anything I'd do something like this in the output:

type BigIntString = string & z.BRAND<'BigInt'>;
z.bigint().transform(v => v.toString() as BigIntString);

@jlalmes jlalmes added the help wanted Extra attention is needed label May 24, 2023
@testerez
Copy link

testerez commented Feb 25, 2024

I have a similar requirement. Using transform in the output zod schema works pretty well.
Unfortunately the generated openapi document indicates the wrong type in response.

Here is what I get:

"amount": {
  "type": "integer",
  "format": "int64"
}

Edit: Here is a potential solution to fix the openapi document response definition: #439

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants