RAML文件在Anypoint Studio中抛出无效的Json架构响应

时间:2017-01-09 22:46:50

标签: json mule jsonschema anypoint-studio raml

我正在使用Anypoint Studio 6.2和Mule 3.8.1,我添加了一个raml和JSON模式,它在api-workbench中没有显示错误,但在Anypoint Studio中显示Json模式无效错误。

我发现如果我从链接到raml的所有Json模式中删除了必需的字段(即raml,traits和types),那么一切正常。有办法解决这个问题吗?

我使用的语法是:

"required": [
    "Organisation",
    "Address"
  ],
  

更新

我还看到org.mule.common.metadata.parser.json.SchemaException: java.net.MalformedURLException: no protocol:,当使用JSON模式创建要在Dataweave中使用的元数据类型时,无法解析$ ref:

{
    "id": "http://localhost:8000/schemas/products.json#",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "Products",
    "type": "object",
    "properties": {
        "Products": {
            "$ref": "common/text.json"
        }
    },
    "additionalProperties": false
}

由于

2 个答案:

答案 0 :(得分:1)

我也这样做,所以它在Studio中肯定受到支持。在没有看到整个JSON模式文件的情况下,我必须猜测原因,我的假设是你要么没有指定JSON模式版本,要么指定了错误的版本(至少应该是v4,而不是v3才能使用它)。以下适用于我:

{
  "$schema": "http://json-schema.org/draft-04/schema",
  "type": "object",
  "properties": {
    "Organisation": { "type": "string" },
    "Address": { "type": "string" }
  },
  "required": [ "Organisation", "Address" ]
}

答案 1 :(得分:0)

关于新添加 - $ ref - 我们也使用它,它似乎被APIKit正确解析(即消息被正确验证)但是我不使用这些模式来创建Dataweave元数据所以我不能保证它会表现相同(我希望它使用相同的解析器,但不能肯定地说)。

Common.json:

{
    "$schema": "http://json-schema.org/draft-04/schema",
    "definitions": {
        "emailAddress": {
            "description": "Basic RegEx for an email address",
            "type": ["string","null"],
            "pattern": "^[a-zA-Z0-9'._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"
        }
    }   
}

Sample.json:

{
    "$schema": "http://json-schema.org/draft-04/schema",
    "type": "object",
    "properties": {
        "email": {
            "$ref": "common.json#/definitions/emailAddress"
        }
    }
}