Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 27, 2025

TypeScript reports private type errors when using methodNameBuilder in SDK plugin configuration because the Operation type referenced in its signature is not exported from the package.

Changes

  • Export Operation type from packages/openapi-ts/src/index.ts
  • Add test in packages/openapi-ts/src/__tests__/exports.test.ts to verify Operation type is properly exported and can be used in methodNameBuilder signatures

The SDK plugin's methodNameBuilder accepts (operation: IR.OperationObject | Operation) => string. While IR.OperationObject is accessible via the exported IR namespace, Operation from ~/types/client was not exported, causing TypeScript to treat it as private.

Example

Users can now use methodNameBuilder without TypeScript errors:

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

export default defineConfig({
  plugins: [
    {
      name: '@hey-api/sdk',
      methodNameBuilder: (operation) => {
        // No more "private name 'Operation'" errors
        if ('operationId' in operation && operation.operationId) {
          return operation.operationId.split('_')[1];
        }
        return operation.path ?? '';
      },
    },
  ],
});

Testing

  • ✅ All 969 tests pass (2 new tests added)
  • ✅ TypeScript typecheck passes
  • ✅ Linting passes
  • ✅ Build completes successfully
  • ✅ Package export check passes (attw)

The new tests verify that:

  1. Operation type can be imported and used with IR.OperationObject in a union type
  2. Operation type works in the exact same signature as the SDK plugin's methodNameBuilder

Fixes #2813

Original prompt

This section details on the original issue you should resolve

<issue_title>TypeScript errors when using methodNameBuilder (private type 'IROperationObject' / 'Operation')</issue_title>
<issue_description>### Description

After updating to the latest version, TypeScript shows errors when using methodNameBuilder.

Default export of the module has or is using private name 'IROperationObject'.ts
Default export of the module has or is using private name 'Operation'.

Reproducible example or configuration

import { defineConfig } from '@hey-api/openapi-ts';
import { isNil } from 'lodash';

export default defineConfig({
  input: 'http://localhost:5000/api/docs-json',
  output: './lib',
  parser: {
    transforms: {
      enums: false,
    },
  },
  plugins: [
    {
      name: '@hey-api/client-fetch',
      throwOnError: true,
      baseUrl: false,
      bundle: true,
    },
    {
      name: '@hey-api/transformers',
      dates: true,
    },
    {
      name: '@hey-api/sdk',
      transformer: true,
      asClass: true,
      classNameBuilder: (name: string) => `${name}Service`,
      methodNameBuilder: (operation) => {
        if ('operationId' in operation && !isNil(operation.operationId)) {
          const parts = operation.operationId!.split('_');

          if (parts.length === 1) {
            return parts[0];
          }

          return parts[1];
        }

        if ('id' in operation && !isNil(operation.id)) {
          return operation.id!;
        }

        return operation.path ?? '';
      },
    },
    {
      name: '@hey-api/typescript',
      enums: 'typescript',
    },
  ],
});

OpenAPI specification (optional)

No response

System information (optional)

No response</issue_description>

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

@mrlubos @ArtemAstakhov can you share your tsconfig?

💡 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.

@changeset-bot
Copy link

changeset-bot bot commented Oct 27, 2025

🦋 Changeset detected

Latest commit: 857c464

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@hey-api/openapi-ts Patch

Not sure what this means? Click here to learn what changesets are.

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

@vercel
Copy link

vercel bot commented Oct 27, 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 27, 2025 11:04am

Copilot AI changed the title [WIP] Fix TypeScript errors with methodNameBuilder Export Operation type to fix methodNameBuilder TypeScript errors Oct 27, 2025
Copilot AI requested a review from mrlubos October 27, 2025 03:20
Copilot finished work on behalf of mrlubos October 27, 2025 03:20
@mrlubos
Copy link
Member

mrlubos commented Oct 27, 2025

@copilot can you add a test verifying this solution?

Copy link
Contributor Author

Copilot AI commented Oct 27, 2025

@copilot can you add a test verifying this solution?

Added test in packages/openapi-ts/src/__tests__/exports.test.ts that verifies the Operation type can be imported and used in methodNameBuilder signatures. The test includes two scenarios:

  1. Verifying Operation type can be used with IR.OperationObject in a union type
  2. Verifying Operation type works in the exact same signature as the SDK plugin's methodNameBuilder

All tests pass (969 total, including 2 new tests).

Commit: 774e408

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 27, 2025
@mrlubos mrlubos marked this pull request as ready for review October 27, 2025 11:04
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Oct 27, 2025
@dosubot dosubot bot added bug 🔥 Something isn't working client Client package related labels Oct 27, 2025
@codecov
Copy link

codecov bot commented Oct 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 30.59%. Comparing base (1a7b35b) to head (857c464).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2862   +/-   ##
=======================================
  Coverage   30.59%   30.59%           
=======================================
  Files         488      488           
  Lines       39938    39938           
  Branches     2442     2442           
=======================================
  Hits        12219    12219           
  Misses      27685    27685           
  Partials       34       34           
Flag Coverage Δ
unittests 30.59% <ø> (ø)

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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 27, 2025

Open in StackBlitz

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/codegen-core@2862
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/nuxt@2862
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/openapi-ts@2862
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/vite-plugin@2862

commit: 857c464

@mrlubos mrlubos merged commit 366adfe into main Oct 27, 2025
17 checks passed
@mrlubos mrlubos deleted the copilot/fix-typescript-errors-method-name-builder branch October 27, 2025 11:11
@hey-api hey-api bot mentioned this pull request Oct 27, 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 client Client package related lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeScript errors when using methodNameBuilder (private type 'IROperationObject' / 'Operation')

2 participants