Разница между &standardResponses и *standardResponses в raml

Я новичок в правильной документации API с использованием RAML. В одном примере я видел код как

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>>

Так в чем же разница между &standardResponses и *standardResponses? И почему мы использовали Вопросительный знак (?) После методов http и что означает, когда мы используем тип: base?

1 ответ

& {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

Так что вам не нужно повторять в каждом ответе одни и те же заголовки.

Другие вопросы по тегам