微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Swagger-codegen 中具有映射的鉴别器不显示 HTML2 中的子类,只显示父类

如何解决Swagger-codegen 中具有映射的鉴别器不显示 HTML2 中的子类,只显示父类

我正在尝试为我的 API 生成文档,但被困在应该很容易的小问题上,但花费了太多时间:映射的多态性未将子类显示HTML2 中的一个选项(仅显示父母)

我在 API (java) 中的基本类是:

public abstract class Animal { ..}
public class Cat extends Animal {..}
public class Dog extends Animal {..}

请求正文是

public class AnimalRequest 
{
    long id;
    Animal animal;
    ...
} 

当谈到架构时,它看起来像这样:

Animal:
  required:
    - type
  type: object
  properties:
    type:
      type: string
  discriminator:
    propertyName: type
    mapping:
      Cat: '#/components/schemas/Cat'
      Dog: '#/components/schemas/Dog'
  //this oneOf is not generated or used. if I do add it - SwaggerHub documentation looks closer to the way I wish it looked (with child options),but it actually results in unintended infinite recursion between parent/child classes and Errors the generation
  //oneOf:
  //  - $ref: '#/components/schemas/Cat'
  //  - $ref: '#/components/schemas/Dog'
Dog:
  type: object
  allOf:
    - $ref: '#/components/schemas/Animal'
    - type: object
      properties:
        ...
Cat:
  type: object
  allOf:
    - $ref: '#/components/schemas/Animal'
    - type: object
      properties:
        ...

我面临的问题是,在此设置中,当我生成 HTML2 时 - 只有 Parent (Animal) 类作为选项可见,并且通过查看文档,您看不到任何孩子您可以(并且应该,因为我从不期望只有动物)发送到 API(猫、狗)的选项。

我尝试使用的生成器:swagger-codegen-cli-2.4.21openapi-generator-cli-5.2.0

我还发现,redoc 支持我希望的行为,但我还不愿意切换。

我的问题是:

  • swagger-codegenopenapi-generator 中甚至支持这种行为吗?
  • 如果是 - 如何实现?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。