[BUG][JAVA] 当一个组件以小写字母开头时,具有相同名称的组件无法区分

作者: phlechev创建于 2025年3月6日更新于 2026年9月15日
标签Issue: Bug
描述 当存在同名的引用组件时,生成器无法正确生成类,其中一个组件以小写字母开头,另一个以大写字母开头。以下是一个示例: cat.yaml schemas: Cat: type: object properties: age: type: integer color: type: string sound: $ref: '#/components/schemas/sound' dog.yaml schemas: Dog: type: object properties: age: type: integer color: type: string sound: $ref: '#/components/schemas/Sound' Sound: type: string enum: [WOOF, RRRR] pet-shop.yaml paths: /cat/{catId}: get: operationId: getCat description: Gets a cat parameters: - in: path name: catId description: Id of the cat schema: type: integer required: true responses: '200': description: 'OK' content: application/json schema: $ref: 'cat.yaml#/components/schemas/Cat' /dog/{dogId}: get: operationId: getDog description: Gets a dog parameters: - in: path name: dogId description: Id of the dog schema: type: integer required: true responses: '200': description: 'OK' content: application/json schema: $ref: 'dog.yaml#/components/schemas/Dog' 当我们运行 pet-shop.yaml 的 generate-sources 时,只会生成一个 SoundDto.java 枚举 - 以小写字母开头的那个,因此 DogDto 中包含一个 [MEOUW, MRRR] 枚举。如果两个枚举都称为 Sound 或 sound,则生成器正确生成两个枚举 - SoundDto 和 Sound1Dto,但是当一个以小写字母开头,另一个以大写字母开头时,小写字母优先,因此 Dog 对象的 sound 属性具有不正确的类型。预期的行为是生成器会识别这些是两种不同的类型,并生成两个不同的类。

内容来源: OpenAPITools/openapi-generator