首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >API Blueprint中的MSON Array对象"undefined“错误

API Blueprint中的MSON Array对象"undefined“错误
EN

Stack Overflow用户
提问于 2015-08-16 02:59:47
回答 1查看 488关注 0票数 2

我们正在使用HAL+JSON开发一个新的应用程序接口,利用Apiary.io的API Blueprint。我们一直在蓝图本身的响应中使用JSON。我正在测试转而使用MSON,但我在数组对象上遇到了问题。

以下是API Blueprint代码。除了包含一个objectcuries数组(接近底部)之外,一切都运行得很好。

代码语言:javascript
复制
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 Blueprint输出返回:

代码语言:javascript
复制
"curies": [
  {
    "undefined": null
  }
]

当JSON看起来像这样的时候:

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

据我从MSON规范可以看出,curies数组和对象的语法是正确的。

我希望有类似的MSON探索者的反馈。

EN

回答 1

Stack Overflow用户

发布于 2015-09-16 00:06:49

我在API Blueprint、MSON和嵌套结构中遇到过很多奇怪的行为。在这种情况下,您将假定您所做的工作是有效的,或者可能将其指定为

代码语言:javascript
复制
+ 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,似乎可以正确地呈现它

代码语言:javascript
复制
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

的响应来呈现端点。

代码语言:javascript
复制
{
  "_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"
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32028246

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档