Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Aug 25, 2025

This PR fixes a TypeScript syntax error introduced in version 13.2.8 where operationIds starting with numbers would generate invalid TypeScript code when used as direct class methods.

Problem

The issue occurred when generating API classes where methods with operationIds starting with numbers (e.g., "123getUser") would use incorrect syntax:

// ❌ Invalid TypeScript - colon syntax in class method
export class Api extends HttpClient {
  "123GetUser": (params: RequestParams = {}) => // SyntaxError!
    this.request({...});
}

This caused TypeScript compilation errors:

  • Expected '=' for property initializer.ts(1442)
  • ',' expected.ts(1005)
  • Expression expected.ts(1109)

Root Cause

The procedure-call.ejs template was using route.namespace to determine whether to use colon syntax (:) vs assignment syntax (=). However, route.namespace indicates route grouping for module organization, not the actual rendering context (class method vs object property).

Solution

Added an explicit isObjectProperty parameter passed from the api.ejs templates to correctly distinguish between:

  1. Direct class methods (isObjectProperty: false) - should use assignment syntax:

    "123GetUser" = (params: RequestParams = {}) => this.request({...});
  2. Object properties (isObjectProperty: true) - should use colon syntax:

    users = {
      "123GetUser": (params: RequestParams = {}) => this.request({...}),
    }

Changes

  • Modified templates/default/api.ejs and templates/modular/api.ejs to pass the isObjectProperty parameter
  • Updated procedure-call.ejs templates to use this parameter instead of route.namespace
  • Added comprehensive tests to prevent regression
  • Maintains backward compatibility with existing schemas

Testing

Added test cases covering:

  • Direct class methods with operationIds starting with numbers
  • Object properties with operationIds starting with numbers
  • Normal identifiers to ensure no regression

All existing tests (130 total) continue to pass.

Fixes #1366.


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

Copy link
Author

Copilot AI commented Aug 25, 2025

@smorimoto 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copy link

changeset-bot bot commented Aug 25, 2025

⚠️ No Changeset found

Latest commit: f9ab68d

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

@Copilot Copilot AI changed the title [WIP] Version 13.2.8 generates incorrect TS Fix TypeScript syntax error for operationIds starting with numbers Aug 25, 2025
@Copilot Copilot AI requested a review from smorimoto August 25, 2025 15:25
Copilot finished work on behalf of smorimoto August 25, 2025 15:25
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.

Version 13.2.8 generates incorrect TS
2 participants