YAML单个状态代码的多个响应

时间:2017-01-04 13:29:07

标签: json yaml

使用yaml格式的单个状态代码帮助我处理多个响应正文。

实施例::

'401':
  description: Not Found
  headers:
    Content-Type :
      type: string
      default: application/json;charset=UTF-8
  examples:
    errorCode: '48'
    errorLabel: RONotAllowed
    errorDescription: Unable to execute the remote operation as it is not allowed for the vehicle
'401':
  description: Not Found
  headers:
    Content-Type :
      type: string
      default: application/json;charset=UTF-8
  examples:
    errorCode: '45'
    errorLabel: VehicleNotFound
    errorDescription: Vehicle could not be found using VIN provided  in request
'401':
  description: Not Found
  headers:
    Content-Type :
      type: string
      default: application/json;charset=UTF-8
  examples:
    errorCode: '49'
    errorLabel: VehicleAlreadyOnline
    errorDescription: Unable to execute the remote operation since   vehicle is already online

使用上面的代码我发现错误 ✖YAML语法错误 第608行第9行的重复映射键:' 401'

1 个答案:

答案 0 :(得分:1)

如果我理解正确,您正在尝试提供错误代码的示例列表。为此你需要:

'401':
  description: Not Found
  headers:
    Content-Type :
      type: string
      default: application/json;charset=UTF-8
  examples:
    - errorCode: '48'
      errorLabel: RONotAllowed
      errorDescription: 'Unable to execute the remote operation as it is not allowed for the vehicle'
    - errorCode: '45'
      errorLabel: VehicleNotFound
      errorDescription: 'Vehicle could not be found using VIN provided  in request'
    - errorCode: '49'
      errorLabel: VehicleAlreadyOnline
      errorDescription: 'Unable to execute the remote operation since   vehicle is already online'