Skip to content

[typescript-nestjs] Use paramName for URL path substitution (fixes #16668)#23868

Open
reichhartd wants to merge 1 commit into
OpenAPITools:masterfrom
reichhartd:fix/typescript-nestjs-snake-case-path-param
Open

[typescript-nestjs] Use paramName for URL path substitution (fixes #16668)#23868
reichhartd wants to merge 1 commit into
OpenAPITools:masterfrom
reichhartd:fix/typescript-nestjs-snake-case-path-param

Conversation

@reichhartd
Copy link
Copy Markdown

@reichhartd reichhartd commented May 25, 2026

Fixes #16668. Same change as #16669, which never got merged because the original author's commits weren't linked to a GitHub account.

The bug: when a path parameter is declared with hyphens or underscores in the spec (e.g. {payment_method_id}), the typescript-nestjs generator emits a function signature with the camelCase identifier but a URL template that still references the raw spec name:

public retailBrokerageApiGetPaymentMethod(paymentMethodId: string, ...) {
    return this.httpClient.get(
        `${this.basePath}/api/v3/brokerage/payment_methods/${encodeURIComponent(String(payment_method_id))}`,
        ...
    );
}

TypeScript then fails with TS2304: Cannot find name 'payment_method_id'. paramNaming=original doesn't help, it only changes the signature, not the URL template.

The fix: in postProcessOperationsWithModels the existing findPathParameterByName lookup result is now also used for the URL template substitution. When the parameter resolves, its already-normalised paramName is appended. Falls back to the previous toVarName behaviour otherwise.

New unit test testPathPropertyName covers a snake_case and a camelCase path parameter. I verified it fails on master without the fix and passes with it. ./bin/generate-samples.sh ./bin/configs/typescript-nestjs*.yaml produces no sample drift because the petstore specs only use camelCase path parameters.

/cc @macjohnny from the TypeScript technical committee, and @wing328 who reviewed the original #16669.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Fixes incorrect path param substitution in the typescript-nestjs generator by using the normalized paramName in URL templates. Fixes #16668 and prevents TS2304 errors when specs use snake_case or kebab-case path params.

  • Bug Fixes
    • Use the resolved path parameter’s paramName for URL template substitution in postProcessOperationsWithModels, falling back to toVarName if not found.
    • Add testPathPropertyName to verify correct substitution for both snake_case and camelCase path parameters.

Written for commit 2c42049. Summary will update on new commits. Review in cubic

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

Re-trigger cubic

@reichhartd reichhartd closed this May 25, 2026
@reichhartd reichhartd reopened this May 25, 2026
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.

[BUG] NestJs Typescript generator path param error with hyphen

1 participant