Possible issue: "url" query/path parameter shadows the url module import in typescript-fetch generator
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 冷清
- 技术栈
- typescript
- 领域
- tooling
调研方向
从检查 modules/swagger-codegen/src/main/resources/typescript-fetch/api.mustache 中的 url 导入及其 parse/format 调用开始。使用保存的最小 Swagger 2.0 repro 生成带有名为 url 的参数的 typescript-fetch 客户端,然后验证生成的代码可以通过 tsc 编译,同时不更改公共参数名称。
由索引模型根据 Issue 内容生成。
描述
What's broken: In modules/swagger-codegen/src/main/resources/typescript-fetch/api.mustache, the file does import * as url from "url"; (line 5) and later calls url.parse(...) (line 104) and url.format(...) (line 238) inside each generated operation method. But generated method parameters are named directly from the OpenAPI spec's parameter names (line 93), with no collision check against url. AbstractTypeScriptClientCodegen's reserved-word list (lines 53-58) covers TS keywords and a few internal names but not url, and TypeScriptFetchClientCodegen doesn't add it either.
Result: Any operation with a parameter literally named url (e.g. GET /webhooks?url=...) generates a method like:
listWebhooks(url?: string, options: any = {}): FetchArgs {
const localVarUrlObj = url.parse(localVarPath, true); // url = the string param, not the module
...
return { url: url.format(localVarUrlObj), options: localVarRequestOptions };
}
Because the parameter is typed string, this isn't a subtle runtime issue — it's a hard tsc compile error: Property 'parse' does not exist on type 'string'.
Repro spec: minimal Swagger 2.0 doc with one GET operation taking a query param named url — included in full in the saved file.
Related prior art: #6698 (closed, fixed by PR #6717) fixed an almost identical collision for a parameter named path, but only by renaming the template's local variables to localVar*-prefixed names. That fix never touched the import * as url from "url" binding, so this specific case slipped through and is still present on current master (c7dd2fc, pom 2.4.53-SNAPSHOT).
Suggested fix (recommended): alias the import, e.g. import * as _nodeUrl from "url";, and use _nodeUrl.parse/_nodeUrl.format in the template — fixes the whole class of import-vs-parameter-name collisions without touching generated public API (param names, FetchArgs.url, etc. stay the same). Alternatives: add url to the reserved-word list so it gets escaped like other reserved names, or stop relying on a bare top-level import that any parameter name can shadow.
- 主要语言
- Mustache
- 星标
- 17.8k
- 派生
- 6k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
swagger-api/swagger-codegen 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
swagger-api/swagger-codegen#12445 ·
-
security vulnerability
难度 1/5 1 小时以内 新手友好度 62/100
swagger-api/swagger-codegen#11942 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
swagger-api/swagger-codegen#11812 · 1 个 reaction ·
-
security vulnerability
难度 2/5 1-3 小时 新手友好度 65/100
swagger-api/swagger-codegen#11594 ·
-
难度 1/5 1 小时以内 新手友好度 62/100
swagger-api/swagger-codegen#10969 ·
查看 swagger-api/swagger-codegen 的全部 Issue
相似的 Issue
-
documentation from-review-extraction github-actions priority: low severity:nit
难度 1/5 1 小时以内 新手友好度 92/100
LearningCircuit/local-deep-research#6946 ·
维护者通常 1 天内回复
-
Help-Wanted Needs-Triage Package-Request
难度 2/5 1-3 小时 新手友好度 68/100
microsoft/winget-pkgs#442309 ·
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 68/100
alunduil/zfs-replicate#730 ·
维护者通常 1 天内回复
-
infrastructure
难度 1/5 1-3 小时 新手友好度 65/100
alunduil/siren-json.hs#232 ·
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 68/100
alunduil/alunduil-infrastructure#629 ·
维护者通常 1 天内回复