fix: preserve TypeScript builders for trailing-slash paths - #8251
Shubham Padkonde (Shubham-Padkonde) wants to merge 11 commits into
Conversation
|
Shubham Padkonde (@Shubham-Padkonde) your behaviour is disruptive, opening about 30 PRs on the repos in a couple of hours time, most likely code that was AI generated and not tested/reviewed, will only clog our review pipeline. Please stop opening additional pull requests and work on the comments added to existing ones. We have turned on pull requests limits on this repository, and will proceed to blocking you at the organization level if additional pull requests are opened on other repositories before the already opened ones are reviewed and closed/or merged. |
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The changes align with TypeScript path normalization behavior, add targeted regression coverage, and the updated writer logic correctly preserves per-builder URI template associations without introducing new unsafe literal emissions.
Review effort: Lite
Findings: None
What changed in this PR
This PR fixes a TypeScript codegen edge case where request builders for paths that differ only by a trailing slash (e.g., /token and /token/) end up targeting the same emitted file (index.ts), causing one builder’s declarations (including inline model serializers/factories and request metadata) to be overwritten.
Changes:
- Group TypeScript request-builder
CodeFiles per namespace before import cleanup so all declarations that normalize to the same output file are written together. - Ensure each requests-metadata constant references the URI-template constant associated with its own original request-builder class (via
OriginalCodeElement), not the first template in the file. - Add/adjust tests to cover the trailing-slash collision scenario and validate correct URI-template selection per metadata constant.
| File | Description |
|---|---|
src/Kiota.Builder/Refiners/TypeScriptRefiner.cs |
Adds request-builder file grouping to prevent index.ts overwrite when multiple builders normalize to the same output path. |
src/Kiota.Builder/Writers/TypeScript/CodeConstantWriter.cs |
Fixes URI-template association for request metadata by matching on OriginalCodeElement. |
tests/Kiota.Builder.Tests/Writers/TypeScript/CodeConstantWriterTests.cs |
Updates fixtures to set OriginalCodeElement on URI-template constants to reflect production behavior. |
tests/Kiota.Builder.Tests/KiotaBuilderTests.TypeScriptTrailingSlash.cs |
Adds regression test ensuring both trailing-slash builders and their inline types survive, and metadata uses the correct template constant. |
CHANGELOG.md |
Documents the TypeScript trailing-slash preservation fix. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Shubham Padkonde (@Shubham-Padkonde) this PR is conflicting, would you mind handling the conflicts when you have a minute please? |
|
Fixed the merged-file import/declaration collision in 2de1c6a. After grouping request-builder files, the refiner now aliases child imports against the complete set of declarations in the merged file. Added an OpenAPI regression with Prepared and tested with OpenAI Codex assistance. |
|
This pull request has conflicting changes, the author must resolve the conflicts before this pull request can be merged. |
|
Conflicts have been resolved. A maintainer will take a look shortly. |
|
This pull request has conflicting changes, the author must resolve the conflicts before this pull request can be merged. |
|
Conflicts have been resolved. A maintainer will take a look shortly. |
|
This pull request has conflicting changes, the author must resolve the conflicts before this pull request can be merged. |
|
Conflicts have been resolved. A maintainer will take a look shortly. |
|
Conflicts have been resolved. A maintainer will take a look shortly. |
|
This pull request has conflicting changes, the author must resolve the conflicts before this pull request can be merged. |
|
Conflicts have been resolved. A maintainer will take a look shortly. |

Fixes #7861.
Request builders for /token and /token/ occupy the same namespace but were placed in separate CodeFiles. Both files normalize to index.ts, so writing one overwrote the other, losing request metadata and inline model serializers/factories. Group the request-builder files before import cleanup so each output path contains all its declarations.
When several builders share a file, select the URI template belonging to the metadata's original request-builder class rather than the first template in that file. Update hand-built writer test fixtures to supply the same original-class association as generated constants.
Validation:
Prepared with Codex assistance.