lb4 openapi generator produces invalid TypeScript code when OpenAPI parameters contain hyphens
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 76/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- node.js, openapi, typescript
调研方向
先阅读 lb4 OpenAPI 生成器中构建控制器方法参数的代码,并追踪它如何将 OpenAPI 规范中的参数名称映射到生成的 TypeScript。使用提供的规范重现问题,并检查生成的控制器。当带连字符的名称在服务调用参数中得到一致的规范化处理,且生成的 TypeScript 可以编译时,即为完成。
由索引模型根据 Issue 内容生成。
描述
Bug Description
When generating server controllers or services using the lb4 openapi generator from an OpenAPI specification containing query or path parameters with hyphens (kebab-case, like limit-number or status-code), the code generator incorrectly emits literal code containing hyphens (e.g., limit-number, status-code) directly inside the TypeScript method body call arguments instead of sanitizing/camelCasing them into valid TypeScript identifiers (limitNumber, statusCode).
This causes immediate compilation/syntax errors.
Steps to Reproduce
Create an OpenAPI 3.0 specification JSON file (openapi.json) with an endpoint having hyphenated query parameters:
{
"openapi": "3.0.3",
"info": {
"title": "Hyphenated Bug API",
"version": "1.0.0"
},
"paths": {
"/customers": {
"get": {
"operationId": "getCustomers",
"parameters": [
{
"name": "limit-number",
"in": "query",
"schema": { "type": "integer" }
},
{
"name": "status-code",
"in": "query",
"schema": { "type": "string" }
}
],
"responses": {
"200": { "description": "OK" }
}
}
}
}
}
- Run the LoopBack OpenAPI generator command pointing to this spec:
lb4 openapi openapi.json - Inspect the generated Controller file.
Current Output (Buggy Code)
The controller method tries to pass raw hyphenated strings as variable names into the service layer call:
async getCustomers(
@param({
name: 'limit-number',
in: 'query',
// ...
}) limitNumber: number | undefined,
@param({
name: 'status-code',
in: 'query',
// ...
}) statusCode: string | undefined
): Promise<any[]> {
// BUG: TypeScript treats 'limit-number' and 'status-code' as invalid mathematical subtraction expressions
return this.openApiService.getCustomers(limit-number, status-code);
}
Expected Output
The generated controller should correctly use the sanitized camelCase parameter identifiers (limitNumber, statusCode) inside the implementation body:
async getCustomers(...): Promise<any[]> {
return this.openApiService.getCustomers(limitNumber, statusCode);
}
- 主要语言
- TypeScript
- 星标
- 5.1k
- 派生
- 1.1k
- 平均合并
- 1 天 23 小时
- 30 天内合并 PR
- 44
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
loopbackio/loopback-next 的其他 Issue
-
Avoid constructor source scanning for classes without a base class in @loopback/context可能已有人在做 @zuhairkhalid229 于 14 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 72/100
loopbackio/loopback-next#11878 ·
维护者通常 1 天内回复
-
Docs good first issue help wanted
难度 1/5 1-3 小时 新手友好度 68/100
loopbackio/loopback-next#683 · 3 条评论 ·
维护者通常 1 天内回复
-
Loopback packages include an older core peer dependency, which causes installation failures可能已有人在做 @abd1rahmane 于 6 天前认领。 未关闭bug
难度 3/5 半天 新手友好度 66/100
loopbackio/loopback-next#11901 ·
维护者通常 1 天内回复
-
Model discovery should populate `jsonSchema.maxLength` alongside `length` to support strict-mode validation可能已有人在做 @officialasishkumar 于 8 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 68/100
loopbackio/loopback-next#11869 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 55/100
loopbackio/loopback-next#11726 ·
维护者通常 1 天内回复
查看 loopbackio/loopback-next 的全部 Issue
相似的 Issue
-
truapi-release
难度 2/5 1-3 小时 新手友好度 72/100
paritytech/product-sdk#529 ·
维护者通常 1 天内回复
-
Environments table lists page size 5 after 30可能已有人在做 @raus7n 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 90/100
litmuschaos/litmus#5743 ·
维护者通常 2 天内回复
-
desktop grp:admin-donors type:graphics-bug ui-admin
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
milind-soni/OpenMausBot#6730 ·
维护者通常 1 天内回复
-
Status: Triage Type: Bug / Error
难度 2/5 1-3 小时 新手友好度 69/100
mermaid-js/mermaid-v13#1059 ·
维护者通常 1 天内回复