raml中& standardResponses和* standardResponses之间的差异

时间:2016-04-14 11:04:55

标签: raml

我是使用RAML的新API文档的新手。在一个例子中,我看到了像

这样的代码

resourceTypes: - base: get?: responses: &standardResponses put?:
responses: *standardResponses post?: responses: *standardResponses delete?: responses: *standardResponses
- collection: type: base
get: is: [showActive] responses: 200: body:
application/json: schema: <<schema>> post: body: application/json: schema: <<schema>> responses: 200: body:
application/json: schema: <<schema>>

那么&amp; standardResponses和* standardResponses有什么区别? 为什么我们在http方法之后使用问号(?),当我们使用type:base?

时是什么意思

1 个答案:

答案 0 :(得分:1)

&amp; {name} - 声明一个块 * {name} - 使用块

简单示例:

/customers:
  get:
    responses:
      200:
        headers: &commonResponseHeaders
          Server-Transaction-Id:
            description: Transaction id in the middleware. Can be used for debugging.
            type: string
            required: true
        body:
          example: !include examples/customers.json
          schema: !include schemas/customers.json
  /{customerId}:
    get:
      responses:
        200:
          description: The request was successful and a customer was found
          headers: *commonResponseHeaders
        404:
          description: Customer was not found with `customerId = {customerId}`
          headers: *commonResponseHeaders

因此,您不需要在每个响应中重复相同的标题。