问题描述
1)编写RAML时,可以在架构定义中使用嵌套吗?
1) When writing RAML, can I use nesting in my schema definition?
例如:
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)我可以围绕一组可嵌套模式使用选择/枚举吗?
2) Can I use a choices/enum around a set of nestable schemas?
"items": [ARecord, MXRecord, PTRRecord, ...]
推荐答案
1)是的,可以.参见此示例.那应该是:
1) Yes, you can. See this example. That would be:
"items": { "$ref": "ARecord" }
2)我相信使用 oneOf 指令.我不认为这是RAML支持的.或者,您可以创建一个基础架构,并让ARecord,MXRecord和PTRRecord扩展此基础架构,然后允许该基础架构中的项.这在语义上不会很丰富,但是可以帮助您入门.
2) I believe this is possible in Draft 4 of JSON Schema, using the oneOf directive. I don't think this is supported by RAML though. Alternatively, you could create a base schema and have ARecord, MXRecord and PTRRecord extend this base schema and then allow items of the base schema. This won't be very semantically rich but could get you started.
这篇关于RAML:嵌套架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!