Skip to content

fix(cli): pass the controller's own argument names to the service - #11938

Open
sarankumar1325 wants to merge 1 commit into
loopbackio:masterfrom
sarankumar1325:fix/openapi-hyphenated-param-implementation
Open

sarankumar1325 wants to merge 1 commit into
loopbackio:masterfrom
sarankumar1325:fix/openapi-hyphenated-param-implementation

Conversation

@sarankumar1325

@sarankumar1325 sarankumar1325 commented Dec 5, 2026 •

Copy link
Copy Markdown

Fixes #11937

lb4 openapi --client writes a controller method that passes each OpenAPI parameter to the service by its spec name (param.name). The method signature declares the escaped name instead (escapeIdentifier, the argName of buildParameter). So a name that isn't a valid identifier gives code that doesn't compile:

  • pet-id → getPet(pet-id) while the argument is petId.
  • The reserved word if → getCustomers(if, …) while the argument is _if.

The request body was passed as a hard-coded _requestBody. That happens to equal the escaped body name today.

buildMethodSpec now records the argument names as it builds the signature, including the body's. The implementation passes those, so it always matches what the method declares.

Tests:

  • test/unit/openapi/spec-helper.unit.js: two new generateControllerSpecs tests. The hyphenated pet-id gives getPet(petId); it fails without the fix with getPet(pet-id). A query parameter plus a request body gives getPet(limit, _requestBody).
  • snapshots/unit/openapi/controller-spec.unit.snapshots.js: the customer.yaml fixture's snapshot recorded the broken output. It changes in two strings only: getCustomers(if, limit, access-token) becomes getCustomers(_if, limit, accessToken), and createCustomer(access-token, _requestBody) becomes createCustomer(accessToken, _requestBody). I regenerated it with UPDATE_SNAPSHOTS=1 and checked that nothing else in the file changed.
  • I ran the old and new generator over every spec in test/fixtures/openapi and compared the output. Only those two implementations differ, so the openapi-client integration snapshots (petstore) are unchanged.
  • mocha test/unit/openapi/*.unit.js: 48 passing. One failure, the uspto "schema to model" before all hook, also fails on master in my checkout. I installed only packages/cli, not the whole monorepo.
  • Prettier is clean on the changed files.

Checklist

  • DCO (Developer Certificate of Origin) signed in all commits
  • npm test passes on your machine (unit tests for the openapi generator only; see above)
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

I wrote this with an AI assistant and checked the change and the tests myself.

The generated controller implementation passed each OpenAPI parameter by
its spec name, so a name that is not a valid identifier (pet-id, or the
reserved word if) produced code that does not compile, while the method
signature declares the escaped name (petId, _if). Pass the names the
signature declares, including the request body's.

Fixes loopbackio#11937

Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-12-05T05:30:01.618657Z
We couldn’t complete this review. Comment @codex review to try again.
947984d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

This branch has not been deployed

No deployments
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.

OpenAPI generator produces invalid TypeScript for hyphenated parameter names

1 participant