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

Conversation

Copy link
Contributor

Copilot AI commented Nov 3, 2025

Codegen was outputting invalid _heyapi_xxx_ identifiers in generated code when external symbols (e.g., zod's z) were referenced before registration, leaving placeholders unreplaced.

Root Cause

When referenceSymbol() creates stubs for external symbols, they lack a name property. During rendering, replacerFn returns undefined for nameless symbols, causing renderIds to preserve placeholders in output.

Changes

  • renderer.ts: Added fallback to derive symbol name from meta.resource when name is undefined
    • For { resource: 'zod.z' } → extracts 'z'
    • Includes type guard for non-string resources
  • renderer-placeholders.test.ts: Added test coverage for stub and external symbol scenarios

Example

Before fix:

export const zErrorResponseDto = _heyapi_671_.object({
  success: _heyapi_671_.boolean(),
  message: _heyapi_671_.string(),
});

After fix:

export const zErrorResponseDto = z.object({
  success: z.boolean(),
  message: z.string(),
});

Type-only imports already emit correctly with import { type Foo } syntax.

Original prompt

This section details on the original issue you should resolve

<issue_title>Codegen outputs invalid ‎_heyapi_xxx_ identifiers after 0.86 and type‑only imports regressed</issue_title>
<issue_description>### Description

Since version 0.86, generated code appears incorrect and references non‑existent internal identifiers. I’m not aware of any breaking changes that would explain this behavior.
Here is a representative example from a freshly generated file:

// This file is auto-generated by @hey-api/openapi-ts

export const zErrorResponseDto = _heyapi_671_.object({
  success: _heyapi_671_.boolean(),
  message: _heyapi_671_.string(),
  errorCode: _heyapi_671_.number(),
  error: _heyapi_671_.string(),
  timestamp: _heyapi_671_.string(),
});

In the generated output, many ‎_heyapi_xxx_ symbols (e.g., ‎_heyapi_671_) do not exist or are not imported from anywhere, causing compile-time failures.

Additionally, enabling verbatimModuleSyntax would require the generator to emit ‎import { type ClientOptions } instead of ‎import { ClientOptions }. If the codegen ignores this constraint, TypeScript will error

  • In 0.85.x (correct): import { type ClientOptions, type Config, createClient, createConfig } from "./client";

  • In 0.86.x (regressed): import { ClientOptions, Config, createClient, createConfig } from "./client";

Reproducible example or configuration

Switch between 0.85.2 and 0.86.x to compare the output differences.

// openapi-ts.config.ts
import path from "node:path";

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

export default defineConfig({
  input: `https://gist.githubusercontent.com/nghiepdev/b2c9996750505ec82adb04fdc9b95ea6/raw/ebe990458001a5c4d3e1de0218f93dcb8f132db8/test-openapi.json`,
  output: {
    format: "prettier",
    lint: null,
    path: "generated/client",
  },
  plugins: [
    {
      name: "@hey-api/transformers",
    },
    {
      name: "@hey-api/client-next",
      runtimeConfigPath: path.resolve(process.cwd(), "./generated/hey-api.ts"),
      throwOnError: false,
    },
    {
      name: "@tanstack/react-query",
    },
    {
      name: "zod",
    },
    {
      name: "@hey-api/sdk",
      validator: true,
      transformer: true,
    },
  ],
});

OpenAPI specification (optional)

https://gist.githubusercontent.com/nghiepdev/b2c9996750505ec82adb04fdc9b95ea6/raw/ebe990458001a5c4d3e1de0218f93dcb8f132db8/test-openapi.json

System information (optional)

@hey-api/openapi-ts@0.86.x</issue_description>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@bolt-new-by-stackblitz
Copy link

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

@changeset-bot
Copy link

changeset-bot bot commented Nov 3, 2025

⚠️ No Changeset found

Latest commit: 068d80c

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

@vercel
Copy link

vercel bot commented Nov 3, 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 Nov 3, 2025 0:22am

- Add fallback logic to derive symbol name from resource when name is undefined
- This fixes the issue where _heyapi_xxx_ placeholders remained in generated code
- Add comprehensive test coverage for placeholder replacement scenarios
- Type-only imports already work correctly with 'type' keyword

Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
- Add type guard for resource property before string operations
- Update test comment to reflect current behavior instead of old bug
- All tests still pass with improved type safety

Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Copilot AI changed the title [WIP] Codegen outputs invalid ‎_heyapi_xxx_ identifiers after 0.86 and type‑only imports regressed Fix placeholder replacement for external symbols without names Nov 3, 2025
Copilot AI requested a review from mrlubos November 3, 2025 12:25
Copilot finished work on behalf of mrlubos November 3, 2025 12:25
@mrlubos mrlubos closed this Nov 3, 2025
@mrlubos mrlubos deleted the copilot/fix-164436240-741524414-a56356ea-21a1-4068-91e4-87a9f8fda312 branch November 3, 2025 15:20
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.

Codegen outputs invalid ‎_heyapi_xxx_ identifiers after 0.86 and type‑only imports regressed

2 participants