gpt4 book ai didi

api - RAML : How to require parameter A OR parameter B

转载 作者:行者123 更新时间:2023-12-04 11:49:15 25 4
gpt4 key购买 nike

我正在用 RAML 编写一些 REST 文档,但我被卡住了。

我的问题:
- 我有一个用于搜索的 GET 请求,它可以采用参数“id”或( 独占或 )“引用”。拥有 只有其中之一 是必须的。

我知道怎么说“需要这个参数”,但我不知道怎么说“需要这些参数之一”。甚至有可能吗?

最佳答案

以下以 RAML 1.0 编写的示例在 Url 中定义了两种对象类型。和 File然后创建另一个对象 Item这需要 UrlFileext .如果您更改包含的示例(当前已验证),您将看到如果属性不符合一个或另一个定义,它们将失败。希望有帮助! 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com