作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在用 RAML 编写一些 REST 文档,但我被卡住了。
我的问题:
- 我有一个用于搜索的 GET 请求,它可以采用参数“id”或( 独占或 )“引用”。拥有 只有其中之一 是必须的。
我知道怎么说“需要这个参数”,但我不知道怎么说“需要这些参数之一”。甚至有可能吗?
最佳答案
以下以 RAML 1.0 编写的示例在 Url
中定义了两种对象类型。和 File
然后创建另一个对象 Item
这需要 Url
或 File
在 ext
.如果您更改包含的示例(当前已验证),您将看到如果属性不符合一个或另一个定义,它们将失败。希望有帮助! LMK 如果您有任何其他问题,我会尽力而为。
[编辑:嗯,我想我现在看到了你的问题,我刚刚添加的最后一个例子,名为 should_fail
,(在示例中包含每种类型中的一个)仍然有效,并且您需要一种方法使其无法通过验证。]
[更新:好的,我想出了一个有点老套的方法来做到这一点。使用 maxProperties: 1
在应该单独显示属性的对象中,请参阅下面的更新代码,该代码在验证期间未能通过最终示例。]
#%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 yet requiring
one AND ONLY one of two possible types using RAML 1.0
properties:
ext:
maxProperties: 1
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:
url: http://heres.a.url.com/asset.jpg
filename: video.mp4
关于api - RAML : How to require parameter A OR parameter B,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37006905/
我是一名优秀的程序员,十分优秀!