Skip to content

zod schema and ts type don't match when bigint is generated #1802

@aldirrix

Description

@aldirrix

Description

First of all, let me thank you for all the effort. The progress of this package is stunning.
We were trying to use the zod plugin and realised that when we have a property that is int64 it generates a schema with a property of z.coerce.bigint().optional() however the generated type is not matching as it's only generated as number.
This is not ideal as we would like to pass the parsed object to another function and then types are incompatible.

Using the provided openapi schema we get the following

// Current generated schema

// This file is auto-generated by @hey-api/openapi-ts

import { z } from 'zod';

export const zGetHelloResponse = z.object({
    someBigInt: z.coerce.bigint().optional()
});

// types
export type GetHelloResponses = {
    /**
     * A successful response
     */
    200: {
        /**
         * Amount of adults in
         */
        someBigInt?: number;
    };
};

export type GetHelloResponse = GetHelloResponses[keyof GetHelloResponses];
Image

Let me know if that's clear and if I can assist in any form. Again thanks for providing an amazing package

Reproducible example or configuration

import { defineConfig } from '@hey-api/openapi-ts';

export default defineConfig({
  input: './openapi-spec.json',
  output: {
    path: './src/generated',
  },
  plugins: [
    {
      name: '@hey-api/typescript',
      style: 'PascalCase',
    },
    '@hey-api/sdk',
    'zod',
    '@hey-api/client-fetch',
    {
      exportFromIndex: true,
      name: '@hey-api/client-fetch',
    },
    {
      exportFromIndex: true,
      name: 'zod',
    },
  ],
});

OpenAPI specification (optional)

{
"openapi": "3.1.0",
"info": {
"title": "Minimal API",
"description": "A minimal OpenAPI specification example",
"version": "1.0.0"
},
"paths": {
"/hello": {
"get": {
"summary": "Returns a greeting message",
"responses": {
"200": {
"description": "A successful response",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"someBigInt": {
"type" : "integer",
"format" : "int64",
"description" : "some amount",
"example" : 3
}
}
}
}
}
}
}
}
}
}
}

System information (optional)

using latest version of everything

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🔥Broken or incorrect behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions