2

Apiary.io の API Blueprint を活用して、HAL+JSON を使用した新しい API を開発しています。ブループリント自体の応答で JSON を使用しています。代わりに MSON の使用への移行をテストしていますが、配列オブジェクトに問題があります。

これが API ブループリント コードです。curiesone を含む配列 (下部に向かって)を除いて、すべてがうまく機能します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配列に対して、JSON の API ブループリント出力は以下を返します。

"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 調査を行ったことのある方からのフィードバックをお待ちしております。

4

1 に答える 1

1

API ブループリント、 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

それは私にとってまだ壊れていました。しかし、適切にレンダリングされるように見えるデータ構造を使用する場合

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"
}
于 2015-09-15T16:06:48.990 に答える