Java版openapi-generator-maven-plugin无法正确处理allOf组合模式
openapi-generator-maven-plugin allOf组合模式生成类异常问题
使用org.openapitools:openapi-generator-maven-plugin时发现,若响应体schema使用由多个对象组成的allOf组合模式,插件不会生成合并所有对象属性的类,仅会采用allOf节点中第一个定义的类。
最小复现示例
openapi.yaml文件内容如下:
openapi: 3.0.0 info: title: Test version: v1 paths: /test: get: operationId: get responses: '200': description: Get content: application/json: schema: allOf: - $ref: '#/components/schemas/A' - $ref: '#/components/schemas/B' components: schemas: A: type: object properties: attA: type: string B: type: object properties: attB: type: integer
通过以下命令生成Java类:
mvn org.openapitools:openapi-generator-maven-plugin:5.2.0:generate \ -Dopenapi.generator.maven.plugin.inputSpec=openapi.yaml \ -Dopenapi.generator.maven.plugin.generatorName=java
实际运行结果
执行后输出警告:
[WARNING] allOf with multiple schemas defined. Using only the first one: A
插件正常生成A、B两个类,但调用get()接口时,返回值类型为A:
DefaultApi api = new DefaultApi(); A a = api.get();
预期结果
期望得到同时包含attA、attB属性的组合对象,与主流OpenAPI编辑器生成结果一致。
限制说明
无法修改openapi.yaml文件,该文件是对接的第三方API提供的OpenAPI规范,修改后会大幅提升后续版本迭代的维护成本。
内容的提问来源于stack exchange,提问作者norbjd
相关产品推荐
相关产品推荐

