在Apiary.io文档中,MSON中具有对象的嵌套数组为空

时间:2015-06-17 11:58:33

标签: json apiblueprint apiary.io apiary mson

我想创建一个嵌套数组,其中包含MSON格式的对象,以便与API Blueprint和Apiary一起使用。我的代码看起来正确但是当我在Apiary中呈现它时,我没有得到预期的JSON。

示例我想要创建:导航有多个类别。每个类别可以有多个子类别。每个类别和子类别都有一个名称。

我为此创建的MSON:

FORMAT: 1A

# Test nested arrays-in-object-arrays

A navigation has multiple categories. Each category can have multiple subcategories.

# GET /navigation

+ Response 200 (application/json)

    + Attributes

        + categories (array)
            + (object)
                + name: Category One (string) - Name of the category
                + subcategories (array)
                    + (object)
                        + name: Sub category One (string) - Name of the subcategory

我期望在JSON中输出:

{
  "categories": [
    {
      "name": "Category One",
      "subcategories":
      [
        {
          "name": "Sub category One"
        }
      ]
    }
  ]
}

我在Apiary获得的输出

{
  "categories": [
    {
      "name": "Category One",
      "subcategories": []
    }
  ]
}

2 个答案:

答案 0 :(得分:5)

我在做类似的事情时遇到了困难。我最终将嵌套类型声明为数据结构,并像这样引用它:

FORMAT: 1A

# Test nested arrays-in-object-arrays

A navigation has multiple categories. Each category can have multiple subcategories.

# GET /navigation

+ Response 200 (application/json)

    + Attributes

        + categories (array)
            + (object)
                + name: Category One (string) - Name of the category
                + subcategories (array[subcategory])

# Data Structures

## subcategory (object)
+ name: Sub category One (string) - Name of the subcategory

产生:

{
  "categories": [
    {
      "name": "Category One",
      "subcategories": [
        {
          "name": "Sub category One"
        }
      ]
    }
  ]
}

答案 1 :(得分:1)

+ Response 200 (application/json)

    + Attributes(CATEGORIES)


# Data Structures

## SUBCATEGORY (object)
- name: `Sub category One` (string) - Name of the subcategory

## CATEGORIES (object)
- categories (array)
    - (object)
        - name: `Category One` (string) - Name of the category
        - subcategories (array[SUBCATEGORY])