Ошибка объекта массива MSON в проекте API Blueprint

Мы разрабатываем новый API с использованием HAL+JSON, используя API Blueprint Apiary.io. Мы использовали JSON в наших ответах в рамках самого Blueprint. Я тестирую переход на использование MSON вместо этого, но у меня проблема с объектом массива.

Вот код API Blueprint. Все отлично работает, кроме curies массив (внизу), который содержит один 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

Для этого curies массив, вывод API Blueprint в JSON возвращает:

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

Когда ожидается, что будет JSON, который выглядит следующим образом:

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

Насколько я могу судить по спецификации MSON, синтаксис для curies массив и объект верны.

Хотелось бы получить отзывы от людей, которые участвовали в аналогичных исследованиях MSON.

1 ответ

Я столкнулся с довольно странным поведением API Blueprint, MSON и вложенных структур. В этом случае вы бы предположили, что вы работали, или, возможно, указав это как

+ 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

Это все еще было сломано для меня. Но если вы используете Data Structures, это, кажется, заставляет его отображаться правильно

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

Который представил конечную точку с ответом

{
  "_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"
}
Другие вопросы по тегам