【问题标题】:RAML file is throwing invalid Json schema response in Anypoint StudioRAML 文件在 Anypoint Studio 中引发无效的 Json 模式响应
【发布时间】:2017-05-24 07:40:10
【问题描述】:

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

我发现,如果我从所有链接到 raml(即 raml、特征和类型)的 Json 模式中删除必填字段,那么一切正常。有没有办法解决这个问题?

我使用的所需语法是:

"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
}

谢谢

【问题讨论】:

  • 也许它只支持 v3 模式。尝试在每个字段中使用 put "required": "true"(这是 v3 模式格式)

标签: json mule jsonschema anypoint-studio raml


【解决方案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" ]
}

【讨论】:

  • 我发现当我按照 Pedro 的建议解决所有问题时,如果我恢复使用所需的数组,那么错误就会返回,所以看起来它目前仅与 v3 兼容。我需要做些什么来更新到最新版本吗?
  • 您是否按照 Brad 的建议将“$schema”:“json-schema.org/draft-04/schema”添加到您的 json 架构中?
  • 是的,根据 Pedro 的评论和我的回答,您需要指定架构版本 4。正如我最初所说,这绝对适用于我正在从事的项目的工作室。
  • 谢谢。添加 $schema 已经能够解决我看到的大部分错误。我确实还有一个地方,当我使用使用 $ref 创建元数据类型的模式时,它会引发错误,但是当我删除引用并直接从文件中添加代码时它会起作用。你知道是什么导致这种情况发生吗?我已经用一个失败的示例模式更新了上面的代码。
【解决方案2】:

关于新添加的 - $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"
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-31
    • 2018-12-07
    • 2019-02-11
    • 1970-01-01
    • 2014-11-18
    • 1970-01-01
    • 2018-12-04
    • 2015-03-03
    相关资源
    最近更新 更多