Swagger 如何在定义中引用自我?
这是一个最小的例子。如果我在swagger editor中写这篇文章,它会显示父对象的类型是Swagger 如何在定义中引用自我?,swagger,Swagger,这是一个最小的例子。如果我在swagger editor中写这篇文章,它会显示父对象的类型是未定义的: 我该如何解决这个问题?我希望Thing引用其他Things.您可以有自引用,但您可能不使用allOf构造: --- swagger: '2.0' info: version: 0.0.0 title: Simple API paths: /: get: responses: 200: description: OK defin
未定义的
:
我该如何解决这个问题?我希望
Thing
引用其他Thing
s.您可以有自引用,但您可能不使用allOf
构造:
---
swagger: '2.0'
info:
version: 0.0.0
title: Simple API
paths:
/:
get:
responses:
200:
description: OK
definitions:
Thing:
properties:
parent_thing:
allOf:
- $ref: '#/definitions/Thing'
description: parent of this thing
上述内容是有效的,如果swagger编辑器没有正确显示,则这是一个bug。您可以通过代理模型()实现这一点:
两种方式都显示“未定义”。顺便说一句,你认为使用allOf是错误的吗?我使用它是因为我想使用自定义描述来说明属性的含义。请在swagger editor中提交一个票证。上面列出的内容是正确有效的,如果没有显示,则需要修复,似乎还没有修复;你确定是虫子吗?
definitions:
Thing:
properties:
parent_thing:
$ref: '#/definitions/Thing'
...
_MessageProxy:
description: Message
type: object
required:
- id
- user
- body
- publishedAt
properties:
id:
title: Message id
type: string
readOnly: true
example: '595f4acf828b0b766ad11290'
user:
$ref: '#/components/schemas/User'
Message:
allOf:
- $ref: '#/components/schemas/_MessageProxy'
- type: object
properties:
parent:
title: Parent
readOnly: true
allOf:
- $ref: '#/components/schemas/_MessageProxy'
...