首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RAML:嵌套模式

RAML:嵌套模式
EN

Stack Overflow用户
提问于 2014-11-21 06:39:22
回答 2查看 8.8K关注 0票数 5

1)在编写RAML时,我可以在我的模式定义中使用嵌套吗?

例如:

代码语言:javascript
复制
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)我可以在一组可嵌套的模式周围使用选择/枚举吗?

代码语言:javascript
复制
"items": [ARecord, MXRecord, PTRRecord, ...]
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-11-21 19:46:10

1)不,你可以。见这个例子。这将是:

代码语言:javascript
复制
"items": { "$ref": "ARecord" }

2)我相信在使用oneOf指令的JSON草案4中,这是可能的。但我不认为这得到了RAML的支持。或者,您可以创建一个基本架构,并让ARecord、MXRecord和PTRRecord扩展这个基本架构,然后允许基架构的项。这将不是非常丰富的语义,但可以让你开始。

票数 6
EN

Stack Overflow用户

发布于 2016-05-13 14:27:35

我认为下面的例子适用于这里。它演示了定义两种类型UrlFile (使用Raml1.0),然后使用逻辑OR允许Item中的任一类型(也称为模式)作为子模式。如果需要,您可以包含更多类型。

我还定义了一些内联示例,这些示例演示了如果您使用raml-解析器,它是如何工作的。

代码语言:javascript
复制
#%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: blah
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27055536

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档