[英]declare raml data type with array of different objects
I have two different Datatypes
(this collection can grow and can have more types):我有两种不同的
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
I wish I could define both of them as elements of another Datatype
, such as the input JSON could be like:我希望我可以将它们都定义为另一个
Datatype
的元素,例如输入 JSON 可能像:
{
"alarms":[
{
"sftp":{
"directory":"/upload",
"host":"223.198.120.125",
"port":"2222",
"user":"foo",
"pass":"pass"
}
},
{
"file":{
"path":"/mule/inbound"
}
}
]
}
I have created 3 RAML files with your DataType input in question我已经使用您的 DataType 输入创建了 3 个 RAML 文件
DataType input that is mentioned in your question saved as data3.raml您的问题中提到的 DataType 输入保存为 data3.raml
DataType input that is mentioned in your question saved as data2.raml您的问题中提到的 DataType 输入保存为 data2.raml
crated an another DataType named as data.raml and add both above RAML added into this as elements that is corelating with your inputJSOn mentioned in question创建了另一个名为 data.raml 的 DataType 并将上面的 RAML 添加到其中作为与您在问题中提到的 inputJSOn 相关的元素
all 3 RAMLS kept inside a folder called types所有 3 个 RAMLS 都保存在一个名为 types 的文件夹中
data.raml file is as below: data.raml 文件如下:
#%RAML 1.0 DataType
type: object
properties:
sftp: !include data3.raml
file: !include data2.raml
crated a examples folder and inside created a file with name data.json and paste the JSON content that was given in your question.创建了一个示例文件夹,并在其中创建了一个名为 data.json 的文件,然后粘贴您问题中给出的 JSON 内容。
created a sample RAML file with resource name /notification that will use all 3rd data type file as below创建了一个资源名称为 /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
below are the snippet of theses folder structure以下是这些文件夹结构的片段
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.