swagger 如何在open API 3.0中描述DTO的继承,以便在生成的类中具有Java继承?

3htmauhk  于 2023-10-18  发布在  Java
关注(0)|答案(1)|浏览(131)

我有三个实体

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)。
有没有办法提示代码生成器通过继承来实现类?

t98cgbkg

t98cgbkg1#

我不知道为什么,但它工作:

Parent:
   discriminator:
     propertyName: stub_type
   description: Parent
   properties:
     id: 
        $ref: '#/components/schemas/id'

相关问题