![](/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.