【问题标题】:Apiary blueprint markdown for an array response body数组响应体的蜂房蓝图降价
【发布时间】:2014-07-30 01:09:04
【问题描述】:

我有一个 REST 服务,它返回一个字符串数组(即不是一个对象)。 Apiary 的相关 Blueprint markdown 如下:

+ Model (application/json)

    + Body

            [
                "element1",
                "element2",
                "element3"
            ]

    + Schema

            {
                "type": "array",
                "items": {
                    "type": "string"
                }
            }

当我在 Apiary 中运行模拟服务时,它可以工作,但在 apiary 流量检查器中出现以下错误:

This API request was compared to a documented resource but was found invalid. 
Check your request headers and body below. 
... 
JSON schema is not valid! invalid type: object (expected [object Object]/array) 
at path "/items"

有什么技巧可以让它工作(对降价的更改),或者这是 Apiary 的一个错误?

【问题讨论】:

标签: jsonschema apiblueprint apiary


【解决方案1】:

Apiary 支持 JSON Schema 草案 3,这使用 JSON 模式生成器 - http://www.jsonschema.net/

{ "type":"object", "$schema": "http://json-schema.org/draft-03/schema", "id": "http://jsonschema.net", "required":false, "properties":{ "0": { "type":"string", "id": "http://jsonschema.net/0", "required":false }, "1": { "type":"string", "id": "http://jsonschema.net/1", "required":false }, "2": { "type":"string", "id": "http://jsonschema.net/2", "required":false } } }

【讨论】:

  • 该架构不允许使用数组 - 它需要这样的 JSON:{"0": "element1","1": "element2","2": "element3"}
  • 在 jsonschema.net 中比较,数组和对象。数组有属性选项和对象无。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多