Skip to content

fix: OpenAPI code generator to sanitize hyphenated parameters into camelCase identifiers - #10427

Open
aaqilniz wants to merge 1 commit into
loopbackio:masterfrom
aaqilniz:fix/push-correct-arg
Open

aaqilniz wants to merge 1 commit into
loopbackio:masterfrom
aaqilniz:fix/push-correct-arg

Conversation

@aaqilniz

@aaqilniz aaqilniz commented Mar 21, 2024 •

Copy link
Copy Markdown
Contributor

Description

Problem

When generating controllers and service methods using lb4 openapi, query or path parameters containing hyphens (e.g., limit-number, status-code) were emitted as raw literals inside method parameter binding calls. This resulted in invalid TypeScript code (e.g., this.openApiService.getCustomers(limit-number, status-code)), where the TypeScript compiler interprets the hyphen as a subtraction operator rather than part of a valid identifier.

Solution

Updated the OpenAPI parameter generation logic to sanitize hyphenated parameter names into camelCase identifiers (argName) before they are written to the method body call arguments.

Changes

  • Modified the parameter iteration loop in the generator to pass the resolved, sanitized argName to method calls instead of the raw param.name.

  • Added an integration test suite and specification fixture (hyphenated-params.json) validating that hyphenated query parameters correctly map to camelCase identifiers in generated controllers without syntax regressions.

Closes #11887

Checklist

  • DCO (Developer Certificate of Origin) signed in all commits
  • npm test passes on your machine
  • 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

👉 Check out how to submit a PR 👈

@coveralls

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 8380587546

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 55.371%

Totals Coverage Status
Change from base Build 8377065394: 0.0%
Covered Lines: 9563
Relevant Lines: 12457

💛 - Coveralls

@aaqilniz
aaqilniz marked this pull request as ready for review March 21, 2024 19:31
@aaqilniz
aaqilniz requested a review from raymondfeng as a code owner March 21, 2024 19:31

@samarpanB samarpanB left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add or update a test case for this please ?

@dhmlau dhmlau added the need-tests Need to add tests in the PR label Mar 18, 2025
@aaqilniz
aaqilniz marked this pull request as draft October 18, 2026 05:17
@aaqilniz
aaqilniz force-pushed the fix/push-correct-arg branch from 1e8dd38 to 79e4027 Compare November 8, 2026 17:14
@aaqilniz
aaqilniz marked this pull request as ready for review November 8, 2026 17:27
@aaqilniz aaqilniz changed the title fix: add correct parameter name for controller method fix: OpenAPI code generator to sanitize hyphenated parameters into camelCase identifiers Nov 8, 2026
@aaqilniz

aaqilniz commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi, @samarpanB. Can you please have a quick look at this PR whenever you get a chance? I have added the new tests and updated an existing snapshot.
Thanks.

Signed-off-by: Muhammad Aaqil <aaqilcs102@gmail.com>
@aaqilniz
aaqilniz force-pushed the fix/push-correct-arg branch from 79e4027 to 8c7dc39 Compare November 8, 2026 17:40

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

need-tests Need to add tests in the PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lb4 openapi generator produces invalid TypeScript code when OpenAPI parameters contain hyphens

4 participants