[英]schema array in swagger
我有些招搖不定。 當我認為我了解其運作方式時,總會有不起作用的地方
那幾行有什么問題
responses:
'200':
allOf:
- $ref: '../index.yaml#/components/responses/200Ok'
content:
application/json:
schema:
allOf:
- $ref: '../index.yaml#/components/schemas/Pagination'
properties:
data:
type: array
items:
schema:
$ref: '../index.yaml#/components/schemas/Client'
“ data”屬性應該是$ ref中給定的模式類型的數組,但這是結果
"data": [
null
]
好的,看來正確的方法是將$ ref直接放在items項下面,我的問題是使用保留鍵“狀態”,那么,如何在對象模式中使用保留鍵?
在我的客戶模式中,我兩次輸入了屬性狀態,但沒有看到它已經存在,因此,當我更改屬性名稱時,它起作用了,並且我認為“狀態”可能是保留關鍵字。
你快到了 有兩個問題:
1)您不能將allOf
直接放在響應代碼下。 您可以$ref
整個響應定義。
2)您不需要items
下的schema
。
另外,雖然將allOf
與其他關鍵字一起使用是完全可以的,但是如果所有組合的模式都列在 allOf
,則某些工具可能會更喜歡它。
試試這個版本:
responses:
'200':
description: OK
content:
application/json:
schema:
allOf:
- $ref: '../index.yaml#/components/schemas/Pagination'
- properties:
data:
type: array
items:
$ref: '../index.yaml#/components/schemas/Client'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.