如何使用 openapi-generator-maven-plugin 生成没有属性的基本模型 class

How to generate a base model class that has no properties using openapi-generator-maven-plugin

我正在为我的 java 项目使用 maven 插件:

            <groupId>org.openapitools</groupId>
            <artifactId>openapi-generator-maven-plugin</artifactId>
            <version>4.3.1</version>

在 openapi 配置文件 (yml) 中,我描述了一个 post 请求和响应模型:

post:
  tags:
    - instance
  summary: createInstances
  description: Creates instances for given ids
  operationId: createInstances
  requestBody:
    description: Params for creation
    required: true
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/CreateInstancesRequest'
  responses:
    200:
      description: Ok
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/CreateInstancesResponse'
    206:
      description: Partial Content
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/PartialCreateInstancesResponse'

CreateInstancesResponse:
  type: object

PartialCreateInstancesResponseResponse:
  allOf:
    - $ref: '#/components/schemas/CreateInstancesResponse'
  required:
    - failedIds
  properties:
    failedIds:
      $ref: '#/components/schemas/Ids'

我预计它将生成一个没有字段的基础 java class (CreateInstancesResponse) 和一个继承的 class (PartialCreateInstancesResponse)。奇怪的是,生成了 PartialCreateInstancesResponse class。但是没有生成基础 class 。你能帮我解决这个问题吗?

看起来还不支持。您可以为此参考未解决的问题 here

一个解决方法是,在 super class.

中添加虚拟 属性
"Pet": {
    "title": "AbstractPet",
    "type": "object",
    "properties": {
        "dummyProperty": {
            "type": "string",
            "description": "Workaround - OpenAPI generator does not consider definitions without properties"
        }
    },
    "description": "model containing all the details of a pet",
    "discriminator": {
        "propertyName": "petTypeName"
    }
}