如何描述open api 3.0中DTO的继承以在生成的类中具有java继承?

问题描述 投票:0回答:1

我有3个实体

parent 
 - child_1
 - child_2

还有我的 openApi 定义:

 Parent:
  description: Parent
  properties:
    id: 
      $ref: '#/components/schemas/id'
  
  Child1:
    allOf:
      - $ref: '#/components/schemas/Parent'
      - type: object
        description: Child_1
        properties:
          child1Fied:
            $ref: '#/components/schemas/child1Fied'

   Child2:
    allOf:
      - $ref: '#/components/schemas/Parent'
      - type: object
        description: Child_2
        properties:
          child1Fied:
            $ref: '#/components/schemas/child2Fied'

我期望生成这样的类:

Child1 extends Parent
...
Child2 extends Parent
...

但结果是,所有 3 个类都是独立的,有自己的字段(parent 有 id 字段,Child1 有他自己的 id 和 child1Fied,Child2 有他自己的 id 和 child2Fied)。

有没有办法让代码生成器通过继承实现类的提示?

附注 我在这里没有找到答案:https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/

java swagger openapi code-generation swagger-codegen
1个回答
0
投票

我不知道为什么,但它有效:

Parent:
   discriminator:
     propertyName: stub_type
   description: Parent
   properties:
     id: 
        $ref: '#/components/schemas/id'
© www.soinside.com 2019 - 2024. All rights reserved.