1)在编写RAML时,我可以在我的模式定义中使用嵌套吗?
例如:
schemas:
- DNSResponse: |
{
"type": "object",
"properties": {
"AnswerSection": {
"type": "array",
"items": (((I want a re-useable schema here. ex: ARecord)))
},
"AA": {"type": "boolean"},
"AD": {"type": "boolean"},
...
}
}
- ARecord: |
{
"type": "object",
"properties": {
"address": "string",
"ttl": "number",
"name": "string"
}
}2)我可以在一组可嵌套的模式周围使用选择/枚举吗?
"items": [ARecord, MXRecord, PTRRecord, ...]发布于 2014-11-21 19:46:10
1)不,你可以。见这个例子。这将是:
"items": { "$ref": "ARecord" }2)我相信在使用oneOf指令的JSON草案4中,这是可能的。但我不认为这得到了RAML的支持。或者,您可以创建一个基本架构,并让ARecord、MXRecord和PTRRecord扩展这个基本架构,然后允许基架构的项。这将不是非常丰富的语义,但可以让你开始。
发布于 2016-05-13 14:27:35
我认为下面的例子适用于这里。它演示了定义两种类型Url和File (使用Raml1.0),然后使用逻辑OR允许Item中的任一类型(也称为模式)作为子模式。如果需要,您可以包含更多类型。
我还定义了一些内联示例,这些示例演示了如果您使用raml-解析器,它是如何工作的。
#%RAML 1.0
types:
Url:
properties:
url:
type: string
example: http://www.cats.com/kittens.jpg
description: |
The url to ingest.
File:
properties:
filename:
type: string
example: kittens.jpg
description: |
Name of the file that will be uploaded.
Item:
description: |
An example of a allowing multiple types using RAML 1.0
properties:
ext:
type: File | Url
examples:
file_example:
content:
ext:
filename: video.mp4
url_example:
content:
ext:
url: http://heres.a.url.com/asset.jpg
should_fail:
content:
ext:
unexpected: blahhttps://stackoverflow.com/questions/27055536
复制相似问题