【问题标题】:Wrapping Data Structure in a data key API Blueprint / Apiary在数据密钥 API Blueprint / Apiary 中包装数据结构
【发布时间】:2017-03-11 20:06:35
【问题描述】:

假设我有一个200 响应正文应该是:

{
  "data": [
    {
      "id": 1,
      "title": "Activity 1"
    },
    {
      "id": 1,
      "title": "Activity 2"
    }
  ]
}

我已经设法通过在 API 蓝图中使用它来获得响应主体的这种行为。

+ Response 200 (application/json)
    + Attributes
        + data (array[Activity])

(请注意,我不能将数据键添加到数据结构本身,因为它只存在于单个响应中。如果我需要将 Activity 嵌套在另一个结构中,它不应该有数据键。)

这似乎不对

我认为这不是正确的做法的原因是因为这个响应的 JSON 模式是:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "data": {
      "type": "array"
    }
  }
}

注意如何排除实际活动。

如何正确地将我的响应包装在数据键中,并将其反映在正文和架构中?

【问题讨论】:

    标签: apiblueprint apiary.io apiary mson


    【解决方案1】:

    你应该使用这一行:

    + data(array[Activity], fixed-type)
    

    fixed-type 关键字固定数组中项的类型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-10
      • 2021-03-18
      • 2021-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多