![](/img/trans.png)
[英]How to declare argument type in method when argument passed is an array of different objects?
[英]declare raml data type with array of different objects
我有兩種不同的Datatypes
(這個集合可以增長並且可以有更多類型):
#%RAML 1.0 DataType
type: object
properties:
sftp:
type: object
properties:
directory:
type: string
example: /upload
host:
type: string
example: 223.198.120.125
port:
type: string
example: "2222"
user:
type: string
example: foo
pass:
type: string
example: pass
#%RAML 1.0 DataType
type: object
properties:
file:
type: object
properties:
path:
type: string
example: /mule/inbound
我希望我可以將它們都定義為另一個Datatype
的元素,例如輸入 JSON 可能像:
{
"alarms":[
{
"sftp":{
"directory":"/upload",
"host":"223.198.120.125",
"port":"2222",
"user":"foo",
"pass":"pass"
}
},
{
"file":{
"path":"/mule/inbound"
}
}
]
}
我已經使用您的 DataType 輸入創建了 3 個 RAML 文件
您的問題中提到的 DataType 輸入保存為 data3.raml
您的問題中提到的 DataType 輸入保存為 data2.raml
創建了另一個名為 data.raml 的 DataType 並將上面的 RAML 添加到其中作為與您在問題中提到的 inputJSOn 相關的元素
所有 3 個 RAMLS 都保存在一個名為 types 的文件夾中
data.raml 文件如下:
#%RAML 1.0 DataType
type: object
properties:
sftp: !include data3.raml
file: !include data2.raml
創建了一個示例文件夾,並在其中創建了一個名為 data.json 的文件,然后粘貼您問題中給出的 JSON 內容。
創建了一個資源名稱為 /notification 的示例 RAML 文件,該文件將使用所有第三種數據類型文件,如下所示
#RAML 1.0
title: test raml
version: v1
protocols: [HTTPS]
types:
testdata:
type: !include types/data.raml
examples: !include examples/data.json
/notifications:
post:
body:
application/json
type: testdata
以下是這些文件夾結構的片段
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.