MSON Array Object "undefined" Error in API Blueprint

523 views Asked by At

We are developing a new API using HAL+JSON, leveraging Apiary.io's API Blueprint. We have been using JSON in our responses within the Blueprint itself. I'm testing a shift to using MSON instead, but am having an issue with an array object.

Here is the API Blueprint code. Everything works great, except for the curies array (toward the bottom), which contains one object.

FORMAT: 1A

# Content API
An API for retrieving content from NBC News Group.

# Group Root resource
The starting point for the Content API.

## Root Resource [/]

### Request root resource [GET]
+ Response 200 (application/hal+json)

    + Attributes (required, object)
        + _links (object) - Linked resources in HAL
              + self (required, object) - Self link to current document
                  + href: / (required, string) - URI of this resource
                  + profile: `http://domain.com/docs/profiles/root` (required, string) - URI to profile description for this resource
              + `nbng:content` (object) - Link relation to all content
                  + href: `http://apiary-mock.com/content` (required, string) - URI to content
                  + title: Browse all NBC News Group content (required, string) - title of the link relation
              + `nbcng:publishers` (object) - Link relation to all publishers
                  + href: `http://apiary-mock.com/publishers` (required, string)  - URI to publishers
                  + title: Browse all NBC News Group publishers (required, string) - title of the link relation
              + `nbcng:publisher` (object) - Link relation to an individual publisher
                  + href: `http://apiary-mock.com/publisher/{id}` (required, string) - URI to an individual publisher, with `{id}` query string param
                  + templated: true (required, boolean) - Notes if the link has a URI template associated to it
                  + title: Get a publisher by name (required, string) - title of the link relation
              + curies (required, array) - Link relation to documentation
                  + (object)
                      + href: `http://www.domain.com/docs/relation/nbcng/{rel}` (required, string) - URI to documentation
                      + name: nbcng (required, string) - prefix of the link relation documentation is tied to
                      + title: NBC News Group Link Relation (required, string) - title of the link relation
                      + templated: true (required, boolean) - Notes if the link has a URI template associated to it
        + welcome: Welcome to the NBC News Group Content API (required, string) - Welcome message for resource

For that curies array, the API Blueprint output in JSON returns:

"curies": [
  {
    "undefined": null
  }
]

When what is expected would be JSON that looks like this:

"curies": [
      {
        "href": "http://www.nbcnewsdigitaldev.com/docs/relation/nbcng/{rel}",
        "name": "nbcng",
        "title": "NBC News Group Link Relation",
        "templated": true
      }
    ]

Insofar as I can tell from the MSON specification, the syntax for the curies array and object are correct.

Would love any feedback from folks who've been on a similar MSON exploration.

1

There are 1 answers

0
Rami Massoud On

I've run into a fair share of strange behavior with API Blueprint, MSON, and nested structures. In this case, you would assume what you did would work, or maybe specifying it as

+ curies (required, array) - Link relation to documentation
    + Attributes (object)
         + href: `http://www.domain.com/docs/relation/nbcng/{rel}` (required, string) - URI to documentation
         + name: nbcng (required, string) - prefix of the link relation documentation is tied to
         + title: NBC News Group Link Relation (required, string) - title of the link relation
         + templated: true (required, boolean) - Notes if the link has a URI template associated to it

That was still broken for me. But if you use Data Structures that seems to get it to render properly

FORMAT: 1A

# Content API
An API for retrieving content from NBC News Group.

# Group Root resource
The starting point for the Content API.

## Root Resource [/]

### Request root resource [GET]
+ Response 200 (application/hal+json)

    + Attributes (required, object)
        + _links (object) - Linked resources in HAL
              + self (required, object) - Self link to current document
                  + href: / (required, string) - URI of this resource
                  + profile: `http://domain.com/docs/profiles/root` (required, string) - URI to profile description for this resource
              + `nbng:content` (object) - Link relation to all content
                  + href: `http://apiary-mock.com/content` (required, string) - URI to content
                  + title: Browse all NBC News Group content (required, string) - title of the link relation
              + `nbcng:publishers` (object) - Link relation to all publishers
                  + href: `http://apiary-mock.com/publishers` (required, string)  - URI to publishers
                  + title: Browse all NBC News Group publishers (required, string) - title of the link relation
              + `nbcng:publisher` (object) - Link relation to an individual publisher
                  + href: `http://apiary-mock.com/publisher/{id}` (required, string) - URI to an individual publisher, with `{id}` query string param
                  + templated: true (required, boolean) - Notes if the link has a URI template associated to it
                  + title: Get a publisher by name (required, string) - title of the link relation
              + curies (required, array) - Link relation to documentation
                  + Attributes (Cury)
        + welcome: Welcome to the NBC News Group Content API (required, string) - Welcome message for resource


# Data Structures

## Cury (object)
+ href: `http://www.domain.com/docs/relation/nbcng/{rel}` (required, string) - URI to documentation
+ name: nbcng (required, string) - prefix of the link relation documentation is tied to
+ title: NBC News Group Link Relation (required, string) - title of the link relation
+ templated: true (required, boolean) - Notes if the link has a URI template associated to it

Which rendered the endpoint with a response of

{
  "_links": {
    "self": {
      "href": "/",
      "profile": "http://domain.com/docs/profiles/root"
    },
    "nbng:content": {
      "href": "http://apiary-mock.com/content",
      "title": "Browse all NBC News Group content"
    },
    "nbcng:publishers": {
      "href": "http://apiary-mock.com/publishers",
      "title": "Browse all NBC News Group publishers"
    },
    "nbcng:publisher": {
      "href": "http://apiary-mock.com/publisher/{id}",
      "templated": true,
      "title": "Get a publisher by name"
    },
    "curies": [
      {
        "href": "http://www.domain.com/docs/relation/nbcng/{rel}",
        "name": "nbcng",
        "title": "NBC News Group Link Relation",
        "templated": true
      }
    ]
  },
  "welcome": "Welcome to the NBC News Group Content API"
}