首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用openapi-generator-maven-plugin生成没有属性的基模型类

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

Stack Overflow用户
提问于 2021-01-15 16:29:11
回答 1查看 466关注 0票数 1

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

代码语言:javascript
复制
            <groupId>org.openapitools</groupId>
            <artifactId>openapi-generator-maven-plugin</artifactId>
            <version>4.3.1</version>

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

代码语言:javascript
复制
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类(CreateInstancesResponse)和一个继承类(PartialCreateInstancesResponse)。奇怪的是,生成了PartialCreateInstancesResponse类。但是基类不会生成。你能帮我解决这个问题吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-22 18:24:14

看起来它还不受支持。你可以参考一个开放的问题here

一个变通的办法是,在超类中添加虚拟属性。

代码语言:javascript
复制
"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"
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65732773

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档