2

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": []
    }
  ]
}
JeroenVdb
  • 798
  • 1
  • 12
  • 21
  • 2
    I have tested your example and it looks like a bug in the parser, so I have submitted an [github issue](https://github.com/apiaryio/drafter/issues/47) on you behalf to the parser if you don't mind. –  Jun 17 '15 at 13:44
  • 1
    The bug has been fixed, so it should work as expected. –  Jan 07 '16 at 17:45

2 Answers2

5

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"
        }
      ]
    }
  ]
}
The Davester
  • 498
  • 3
  • 8
  • I also found this workaround. Thanks for sharing but as this is still a workaround I would rather see an (API Blueprint parser) fix as the correct "answer". – JeroenVdb Jun 18 '15 at 08:40
  • 1
    Hey @JeroenVdb, We have it on the radar. We are just trying to fix some internal things first. – Pavan Kumar Sunkara Jul 28 '15 at 11:34
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])
Mkax
  • 21
  • 1