Closed APTy closed 4 months ago
@APTy , this is not a bug of express-zod-api
, it's the bug of the third party software you're using.
The theory of the original issue's author is most likely correct, but it does not mean that express-zod-api
should divide MAX_VALUE
by 10
. No, it means that the difference between min
and max
should not be assigned to a variable having the type that can not fit such number.
Please refer to the maintainer of openapi-generator
for elaborating on its fix.
Meanwhile, until the bug in that generator is not fixed, you'd have to set min
and max
manually, as a workaround for the particular case.
Description
This feels like it'd be a common issue, but there's very little information about it online, and the error message is not very clear.
It occurs when using
z.number()
in your types and then trying to generate HTML docs based on that.It seems related to https://github.com/OpenAPITools/openapi-generator/issues/12111. If that issue author's theory is correct, then maybe a solution would be for
zod-express-api
to use a default min/max ofmin(-1 * Number.MAX_VALUE / 10).max(Number.MAX_VALUE / 10)
.Expected
I expected to be able to use a
z.number()
type and then generate HTML docs based on that.Reproduction
z.number()
in one of the typesnew Documentation({ ... }).getSpecAsYaml()
and write toapi.yaml
openapi-generator-cli generate -g html -i api.yaml
Workarounds
Currently, using
z.number().int()
is a workaround if you don't need decimal precision. Or you can also set reasonablemin().max()
manually based on your use case.EDIT: Probably using these workarounds is the correct thing to do until the problem is fixed in
openapi-generator
project.. it does seem likeexpress-zod-api
's behavior working as intended, and it's the other library that is broken.Context
express-zod-api
version: ^19.2.2Appreciate your help!