簡體   English   中英

搖搖欲墜的模式數組

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM