Fix TypeScript syntax error for operationIds starting with numbers #1371
+193
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: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 usingroute.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 theapi.ejs
templates to correctly distinguish between:Direct class methods (
isObjectProperty: false
) - should use assignment syntax:Object properties (
isObjectProperty: true
) - should use colon syntax:Changes
templates/default/api.ejs
andtemplates/modular/api.ejs
to pass theisObjectProperty
parameterprocedure-call.ejs
templates to use this parameter instead ofroute.namespace
Testing
Added test cases covering:
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.