我们正在使用HAL+JSON开发一个新的应用程序接口,利用Apiary.io的API Blueprint。我们一直在蓝图本身的响应中使用JSON。我正在测试转而使用MSON,但我在数组对象上遇到了问题。
以下是API Blueprint代码。除了包含一个object的curies数组(接近底部)之外,一切都运行得很好。
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输出返回:
"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探索者的反馈。
发布于 2015-09-16 00:06:49
我在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"
}https://stackoverflow.com/questions/32028246
复制相似问题