嘿家伙我正在尝试创建OAS3 200响应,它返回JSON内部的JSON。问题是我根本不知道我应该在这里使用什么语法。我试图做一个双重参考,但我不知道是否可以这样做。
{
"success": false,
"messageType": "error",
"error": {
"apiKey": "apiKey must not be empty"
}
}
responses:
'200':
description: Upon successful generated invoice you will be returned with the following JSON.
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/success'
- $ref: '#/components/schemas/invalid'
components:
schemas:
invalid:
type: object
properties:
success:
description: Says if the invoice was generated successfully.
type: boolean
example: false
messageType:
description: Type of the message
type: string
example: error
error:
schema:
$ref: '#/def/data'
def:
data:
type: object
properties:
apikey:
description: lol
type: string
example: lolol
你快到了。在data
中定义components/schemas
模式,并将error
属性设置为此模式的$ref
。
components:
schemas:
invalid:
type: object
properties:
success:
...
messageType:
...
error:
$ref: '#/components/schemas/data' # <--------
data: # <--------
type: object
properties:
apikey:
description: lol
type: string
example: lolol
另一种方法是内联定义嵌套模式:
components:
schemas:
invalid:
type: object
properties:
success:
...
messageType:
...
error:
type: object # <--------
properties:
apikey:
description: lol
type: string
example: lolol