我正在用RAML编写一些REST文档但是我被卡住了.
我的问题: - 我有一个用于搜索的GET请求,可以使用参数"id"或(独占或)"引用".已经只有一个是必需的.
我知道如何说"这个参数是必需的",但我不知道如何说"需要其中一个参数".它甚至可能吗?
以下用 RAML 1.0 编写的示例在 in 中定义了两种对象类型Url
,File
然后创建了另一个Item
需要Url
OR File
in 的对象ext
。如果您更改包含的示例(当前已验证),您将看到如果属性不符合一个或另一个定义,它们将失败。希望有帮助!LMK 如果您有任何其他问题,我会尽力而为。
[编辑:嗯,我想我现在看到了你的问题,我刚刚添加的最后一个例子,named 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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5408 次 |
最近记录: |