Nested array with object in MSON is empty in Apiary.io documentation

4.4k views Asked by At

I would like to create a nested array with objects in MSON format to use with API Blueprint and Apiary. I code looks correct but when I render it in Apiary I don't get the expected JSON.

Example I want to create: A navigation has multiple categories. Each category can have multiple subcategories. Each category and subcategory have a name.

The MSON I created for this:

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

The output I would expect in JSON:

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

The output I get in Apiary

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

There are 2 answers

2
The Davester On

I was having difficulties with doing something similar. I ended up declaring the nested type as a data structure and referencing it like so:

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

Which produces:

{
  "categories": [
    {
      "name": "Category One",
      "subcategories": [
        {
          "name": "Sub category One"
        }
      ]
    }
  ]
}
0
Mkax On
+ 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])