OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVASCRIPT] constructFromObject redundantly re-initializes fields belonging to the parent
未关闭
还没有人认领这个 Issue。
Issue: Bug
- 主要语言
- Java
- 星标
- 26.8k
- 派生
- 7.7k
- PR 合并指标
- PR 指标待抓取
描述
Description
In MyObject.js :
static constructFromObject(data, obj) {
if (data) {
obj = obj || new MyModel();
BaseModel.constructFromObject(data, obj);
if (data.hasOwnProperty('myProperty')) {
obj['myProperty'] = ApiClient.convertToType(data['myProperty'], 'String');
}
if (data.hasOwnProperty('baseProprty')) {
obj['baseProprty'] = ApiClient.convertToType(data['baseProprty'], 'String');
}
}
return obj;
}
In BaseObject.js :
static constructFromObject(data, obj) {
if (data) {
obj = obj || new BaseModel();
if (data.hasOwnProperty('baseProperty')) {
obj['baseProperty'] = ApiClient.convertToType(data['baseProperty'], 'String');
}
}
return obj;
}
baseProperty is initialized from the call to BaseModel.constructFromObject and then initialized again after the properties unique to the derived object.
openapi-generator version
7.2.0
OpenAPI declaration file content or url
components:
schemas:
BaseModel:
type: object
properties:
baseProperty:
type: string
MyModel:
allOf:
- $ref: "#/components/schemas/BaseModel"
type: object
properties:
myProperty:
type: string
Generation Details
I used the Gradle plugin with the "javascript" generatorName
Steps to reproduce
Define a schema using allOf (without discriminators) and generate JavaScript models.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从生成的 MyObject.js 和 BaseObject.js 示例开始,使用提供的 allOf 模式以及 JavaScript 生成器和 Gradle 插件重现该问题。跟踪 constructFromObject 如何处理继承的属性,然后重新生成模型,以验证父类字段不再被重复初始化。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript
- 领域
- tooling
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100