如何在RAML中定义Expand API的数据类型

时间:2018-01-11 07:25:56

标签: api raml

我正在设计API操作,并将使用扩展标准。

以下是我的第一个API响应示例....

{
    "id": "000000001",
    "createdDateTime": "2017-12-19T16:39:57-08:00",
    "lastUpdatedDateTime": "2017-12-19T16:45:57-08:00",
    "holdingDetails": {
        "status": "SUCCESSFUL",
        "instrument": "/api/v1//instruments/123456789"
    }
}

以下是我的第二个API响应示例....

{
    "id": "000000001",
    "createdDateTime": "2017-12-19T16:39:57-08:00",
    "lastUpdatedDateTime": "2017-12-19T16:45:57-08:00",
    "holdingDetails": {
        "status": "SUCCESSFUL",
        "instrument": {
          "instrumentId":"123456789",
          "nickName":"My NickName",
          "type": "BLAH"    
        }
    }
}

在我的raml中,我想为此定义一种类型,我不确定它会是什么样的......

#%RAML 1.0 DataType
type: object
properties:
  id?:
    type: string
  createdDateTime?:
    type: datetime
  lastUpdatedDateTime?:
    type: datetime

What goes next? i.e. How do I say it can be either listed below   

instrument?:
  type: string
  description: A link to the instrument

  instrument?:
    type: !include instrument.raml

1 个答案:

答案 0 :(得分:0)

您可以使用 union e.g:

instrument?:
  type: string | InstrumentType

当然也定义了InstrumentType,例如:

InstrumentType:
   properties:
     instrumentId:
     nickName:
     type: