假设我有一个端点,它支持三个方法: GET、POST和PUT。
返回的类型包含两个属性:id和name。两者都是required。
我的问题是如何在RAML定义中定义这种类型,因为在POST上,id应该是自动创建的,而在PUT上,id将是一个URI参数。你们是否创建了两个Types (一个用于GET,另一个用于PUT、POST),或者对所有操作使用相同的类型,将id声明为非required
如果这看起来像是一个如此基本的问题,我很抱歉,但我搜索了这个问题,没有得到任何确凿的答复。
非常感谢!
发布于 2017-02-01 21:35:25
也许您可以提供一个示例,说明您希望它如何工作。另外,请指定您正在使用的RAML版本(目前假设为1.0 )。
您的终结点提供了一个POST。这意味着某种类型的集合,您可以向其中添加项。然后,您可以使用GET来检索这样的项。
/collection (所有项目)和一个/collection/12345678 (只包含一个项目,具体地说,就是id为12345678的项目)/collection?id=12345678 (恰好包含一个项目而不是多个项目的集合的子集)也许,您还可以研究一下的用法。
举例说明:
/types:
myidtype:
type: string
pattern: ^[0-9]{8}$
/collection:
get: # to retrieve the entire collection
queryParameters: # to be able to filter the collection into a subset of 1 or more items
id:
type: myidtype
required: false
name:
type: string
required: false
post: # to create a new item and add it to the collection, id and name will go in the body
/{myId}: # this is one item
uriParameters:
myId:
type: myidtype
get: # to retrieve all information on this item
post: # to post some property to this item请注意,我的示例并不完全正确。它是关于概念的,而不是精确的语法。
https://stackoverflow.com/questions/41503559
复制相似问题