问题描述
我正在尝试为我的 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.21
、openapi-generator-cli-5.2.0
我的问题是:
- 在
swagger-codegen
或openapi-generator
中甚至支持这种行为吗? - 如果是 - 如何实现?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)