这是indexloc提供的服务,不要输入任何密码
Skip to content

transformer "transforms" dates unintentionally #1260

@mrclrchtr

Description

@mrclrchtr

Description

Even with dates switched off, transformers are created for the dates and the dates are “passed” through the transformers.

At the end they are strings again. The types do not have the type Date.

The problem is that I want to have a string like this for date: 2024-10-10. However, I get 2024-10-10T00:00:00.000Z.

This is the server response:

"date": "2024-10-10",

This happens because of:

export const XXXModelResponseTransformer: XXXModelResponseTransformer =
  (data) => {
    if (data?.date) {
      data.date = new Date(data.date);
    }
    return data;
  };

My config:

export default defineConfig({
  input: "../../specifications/service.yaml",
  output: {
    path: "src/generated/client/service",
    format: "prettier",
    lint: "eslint",
  },
  plugins: [
    "@hey-api/schemas",
    {
      asClass: true,
      name: "@hey-api/services",
    },
    {
      enums: "typescript",
      name: "@hey-api/types",
    },
    {
      dates: false,
      name: "@hey-api/transformers",
    },
    "@tanstack/react-query",
  ],
  client: "@hey-api/client-fetch",
});

Reproducible example or configuration

No response

OpenAPI specification (optional)

e.g.:

        orderDate:
          type: string
          format: date

System information (optional)

"@hey-api/client-fetch": "0.4.2",
"@hey-api/openapi-ts": "0.54.4",

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🔥Something isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions