Skip to content

Transformers do properly not handle fields which are both required and nullable #2022

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

Closed
yallxe opened this issue May 7, 2025 · 3 comments
Closed
Labels
bug 🔥 Something isn't working prioritized 🚚 This issue has been prioritized and will be worked on soon

Comments

@yallxe
Copy link

yallxe commented May 7, 2025

Description

Transformers does not check whether a field is a null. As an example:
Suppose we have a schema

export type Pet = {
  id?: bigint;
  name: string;
  createdAt: Date | null;
  photoUrls: Array<string>;
  /**
   * pet status in the store
   */
  status?: 'available' | 'pending' | 'sold';
};

Here is the transformer for it

const petSchemaResponseTransformer = (data: any) => {
  if (data.id) {
    data.id = BigInt(data.id.toString());
  }

  // May result in new Date(null), because createdAt is Date | null (but still required)
  data.createdAt = new Date(data.createdAt);
  return data;
};

Reproducible example or configuration

https://stackblitz.com/edit/hey-api-client-fetch-example-2simwjzc?file=src%2Fclient%2Ftransformers.gen.ts

OpenAPI specification (optional)

Inside the stackblitz link, I changed the swagger example.

System information (optional)

No response

@yallxe yallxe added the bug 🔥 Something isn't working label May 7, 2025
Copy link

@yallxe yallxe changed the title Transformers do not handle properly fields which are both required and nullable Transformers do properly not handle fields which are both required and nullable May 7, 2025
@mrlubos
Copy link
Member

mrlubos commented May 7, 2025

Thanks for reporting!

@mrlubos mrlubos added the prioritized 🚚 This issue has been prioritized and will be worked on soon label May 30, 2025
@mrlubos
Copy link
Member

mrlubos commented May 30, 2025

@yallxe this has been fixed in a previous release, please upgrade to the latest 🙌

@mrlubos mrlubos closed this as completed May 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🔥 Something isn't working prioritized 🚚 This issue has been prioritized and will be worked on soon
Projects
None yet
Development

No branches or pull requests

2 participants