Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 31, 2025

Date and BigInt transformers were generating expressions that created transformed objects but failed to return them in array map callbacks, causing runtime type mismatches where TypeScript claimed Date but runtime had string.

Changes

  • expressions.ts: Wrap dateExpressions and bigIntExpressions in return statements when dataExpression is a string (array item context)

Before/After

// Before - creates Date but doesn't return it
data = data.map((item: any) => {
    new Date(item);
    return item;  // returns original string
});

// After - returns transformed value
data = data.map((item: any) => {
    return new Date(item);
});

Test Coverage

Added transformers-array-date-ref.json spec covering:

  • Arrays of primitive dates (array<string format=date-time>)
  • Collection schemas via $ref to array types
  • SDK integration with responseTransformer option
Original prompt

This section details on the original issue you should resolve

<issue_title>Date transformers not generated for collection endpoints using $ref</issue_title>
<issue_description>### Description

Description

Date transformers are not generated for collection endpoints, when:

  1. Collection items use $ref to reference component schemas (not inline schemas)
  2. The same schema component IS transformed correctly when used directly

Expected Behavior

The same schema component (UserMatch.jsonld-match.collection.read) IS transformed correctly when used directly:

  • Single-item endpoint (/api/admin/{company}/matches/{id}/{kind}) → transformer generated
  • Collection endpoint (/api/admin/{company}/matches) → transformer NOT generated

Generated code:

export function getAdminCompanyMatchesIdKind(...) {
  return client.get({
    responseTransformer: apiAdminCompanymatchesIdKindGetResponseTransformer,
    url: '/api/admin/{company}/matches/{id}/{kind}',
  })
}

export function listAdminCompanyMatches(...) {
  return client.get({
    // responseTransformer: MISSING
    url: '/api/admin/{company}/matches',
  })
}

Actual Behavior

  1. TypeScript types claim dates are Date: lastMessageSentAt?: Date | null
  2. Runtime data has dates as strings (JSON doesn't have Date types)
  3. Code expecting Date objects fails at runtime (e.g., calling .getTime() on a string)

Reproducible example or configuration

https://stackblitz.com/edit/hey-api-client-fetch-example-a95akxjr?file=repro-client%2Fsdk.gen.ts

OpenAPI specification (optional)

No response

System information (optional)

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@vercel
Copy link

vercel bot commented Oct 31, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
hey-api-docs Ready Ready Preview Comment Oct 31, 2025 4:00pm

@changeset-bot
Copy link

changeset-bot bot commented Oct 31, 2025

⚠️ No Changeset found

Latest commit: 691b212

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix date transformers for collection endpoints using $ref Fix: Date/BigInt transformers not returning transformed values in array map callbacks Oct 31, 2025
Copilot finished work on behalf of mrlubos October 31, 2025 16:03
Copilot AI requested a review from mrlubos October 31, 2025 16:03
@codecov
Copy link

codecov bot commented Oct 31, 2025

Codecov Report

❌ Patch coverage is 0% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 30.89%. Comparing base (6d2622f) to head (691b212).
⚠️ Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
...s/src/plugins/@hey-api/transformers/expressions.ts 0.00% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2906      +/-   ##
==========================================
- Coverage   30.89%   30.89%   -0.01%     
==========================================
  Files         488      488              
  Lines       40458    40464       +6     
  Branches     2522     2523       +1     
==========================================
  Hits        12501    12501              
- Misses      27922    27928       +6     
  Partials       35       35              
Flag Coverage Δ
unittests 30.89% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Date transformers not generated for collection endpoints using $ref

2 participants