Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transformer "transforms" dates unintentionally #1260

Open
mrclrchtr opened this issue Nov 9, 2024 · 2 comments
Open

transformer "transforms" dates unintentionally #1260

mrclrchtr opened this issue Nov 9, 2024 · 2 comments
Labels
bug 🔥 Something isn't working
Milestone

Comments

@mrclrchtr
Copy link

mrclrchtr commented Nov 9, 2024

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",

@mrclrchtr mrclrchtr added the bug 🔥 Something isn't working label Nov 9, 2024
@mrlubos
Copy link
Member

mrlubos commented Nov 9, 2024

That's a good feedback. I will change it as you describe, though I wonder why you use the plugin at all if you don't want to transform dates?

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.

I don't fully understand this. How do you end up with a string if the transformer gives you a date?

@mrlubos mrlubos added the prioritized 🚚 This issue has been prioritized and will be worked on soon label Nov 9, 2024
@mrlubos mrlubos added this to the Parser milestone Nov 9, 2024
@mrclrchtr
Copy link
Author

Yes, I turned off the transformer yesterday and realized that this fixed my problem without losing other functions.

I thought the transformer transformed more than just dates. I wanted to be as typed as possible.

@mrlubos mrlubos removed the prioritized 🚚 This issue has been prioritized and will be worked on soon label Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🔥 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants