2017-04-20 64 views
-1

這是模式定義。Swagger錯誤JSON模式對象的確定版本

serviceArea: [{ 
    states: [{ 
     type: String 
    }], 
    districts: [{ 
     type: String 
    }], 
    cities: [{ 
     type: String 
    }] 
}] 

這是招搖的定義。

serviceArea: 
    - states: 
     - type: String 
     districts: 
     - type: String 
     cities: 
     - type: String 

我收到上述錯誤。請幫忙。提前致謝。 這是瀏覽器中的搖擺樂編輯器。 Error

+0

這不是一個有效的Swagger規範。你的serviceArea對象應該如何在請求/響應中看起來像? – Helen

+0

我已經在上面提到過了。 –

+0

我認爲數據類型是小寫的,例如字符串而不是字符串,檢查一個例子並重新格式化 – Serge

回答

1

假設serviceArea應該是與性能statesdistrictscities對象,定義應該是這樣的:

serviceArea: 
    type: object 
    properties: 
    states: 
     type: string 
    districts: 
     type: string 
    cities: 
     type: string 

UPDATE對於OP的評論:

它是一個數組數組。

數組的數組被描述爲:

serviceArea: 
    type: array 
    items: 
    type: array 
    items: 
     type: string 


另一個錯誤是在這裏:

type: 
    - number 
    - "null" 

type必須是單一類型的,如type: number,不類型的數組。另外,OpenAPI規範2.0不支持null類型。一些工具使用擴展屬性x-nullable: true來表示可空類型,那麼你可以試試這個:

type: number 
x-nullable: true 

nullable本身會在下一版本中,OpenAPI的3.0的支持。

+0

不,它不是一個對象。這是一個數組和你正在說的屬性,它們也是數組。那麼你將如何格式化呢? –

+0

對不起,我不明白。通過「試用」發送/接收時,該陣列應如何格式化?它只是一個數組數組,如(JSON)'[[「a」,「b」,「c」],[「d」,「e」]]「? – Helen

+0

是的,它是一個數組數組。 –