hey-api / openapi-ts

✨ Turn your OpenAPI specification into a beautiful TypeScript client
https://heyapi.vercel.app
MIT License
639 stars 45 forks source link

FormData date type casted with qutoes #622

Open WildEgo opened 1 month ago

WildEgo commented 1 month ago

Description

After running the code below with a new Date() the code gets parsed as the snippet below the code, I'd expect it to return 2024-05-22T23:00:00.000Z as opposed to "2024-05-22T23:00:00.000Z"

RequestsService.storeRequest({
  formData: payload,
});
-----------------------------52018713130791794643838276982
Content-Disposition: form-data; name="01HYDKBR6VACJAJ8HVEYEZKF4X"

"2024-05-22T23:00:00.000Z"

OpenAPI specification (optional)

No response

Configuration

No response

System information (optional)

OS: EndeavourOS rolling x86_64 Browser: Firefox, Opera, Chromium Bun version: 1.1.8

mrlubos commented 1 month ago

Hey, can you share your config, which version you're on, and OpenAPI spec?

WildEgo commented 1 month ago

Hey, can you share your config, which version you're on, and OpenAPI spec?

Version should be 0.45.1, the config is below

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

export default defineConfig({
  client: 'fetch',
  input: '../dashboard/api.json',
  output: {
    format: false,
    lint: false,
    path: 'src/client',
  },
  types: {
    enums: 'typescript',
  },
});
mrlubos commented 1 month ago

I assume the same happens with the latest version? Can you share your OpenAPI spec?

WildEgo commented 1 month ago

I assume the same happens with the latest version? Can you share your OpenAPI spec?

Yes it does happen on 0.46.2, I can provide the spec but it's not gonna do much for this specifically this is the part that is probably causing the issue, I should add that it generates the code below, I'll also add an expected behaviour

        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "additionalProperties": {
                  "type": "{}"
                }
              }
            }
          }
        },

Generates:

export type StoreRequestData = {
    acceptLanguage?: string;
    formData?: {
        [key: string]: ();
    };
    service: string;
};

I'd expect it to be

export type StoreRequestData = {
    acceptLanguage?: string;
    formData?: {
        [key: string]: unknown;
    };
    service: string;
};
mrlubos commented 1 month ago

Great, thanks! And what does your payload passed to form data look like?

WildEgo commented 1 month ago

Great, thanks! And what does your payload passed to form data look like?

It's a simple structure, there's no depth, some values are string, some are Date some are File, I haven't had a look at the files, I'll have to see if they work or not