小编use*_*984的帖子

使用 ajv json 模式验证器的用户友好错误消息

假设我有架构和 JSON:

JSON 架构:

const schema = {
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "required": [ "countries" ],
  "definitions": {
    "europeDef": {
      "type": "object",
      "required": ["type"],
      "properties": { "type": {"const": "europe"} }
    },
    "asiaDef": {
      "type": "object",
      "required": ["type"],
      "properties": { "type": {"const": "asia"} }
    }
  },
  "properties": {
    "countries": {
      "type": "array",
      "items": {
        "oneOf":[
          { "$ref": "#/definitions/europeDef" },
          { "$ref": "#/definitions/asiaDef"}
        ]
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

JSON:

const data = {
  "countries":[
    {"type": "asia1"},
    {"type": "europe1"}
  ]
}
Run Code Online (Sandbox Code Playgroud)
const isValid …
Run Code Online (Sandbox Code Playgroud)

jsonschema json-schema-validator ajv

8
推荐指数
3
解决办法
6472
查看次数

在 AWS Cloudwatch Logs Insights 中处理单引号

以下是一些包含单引号的文本:

Cannot read property 'email' of undefined:
Run Code Online (Sandbox Code Playgroud)

当我使用上述文本运行以下查询时

filter @message like /Cannot read property 'email' of undefined/
| stats count()
Run Code Online (Sandbox Code Playgroud)

我无法计数。然而,实际上我的日志中有很多上面的文字。

问题是,如何转义查询中的单引号?

amazon-web-services aws-cloudwatch-log-insights

6
推荐指数
1
解决办法
5045
查看次数

在 JSON 模式的 anyOf 中嵌套 oneOf

以下是 JSON 架构和下面链接中提供的 JSON,用于说明目的。

JSON 架构和 JSON

格式:数组中的单个 JSON 对象(及其附加属性,可能会因数组中的其他对象而异)可以属于任意 3 个区域:“美洲”、“亚洲”和“欧洲”,并且至少在区域类型上对象应该在那里。这可以通过数组 minItems 属性来实现)

问题陈述:

  1. 数组中的单个 JSON 对象可以属于任意 3 个区域:“美国”、“亚洲”和“欧洲”,并且至少应该存在区域对象的类型

    ==> 我可以通过将所有区域对象放入 anyOf 数组中来解决此问题,因为我想匹配至少一个有效区域对象。

  2. JSON 对象“亚洲”或“欧洲”可以与其他区域类型一起存在。两者不能共存。

    ==> 我尝试使用“oneOf”,但它通过了 ajv 验证。其实应该会失败。任何人都可以帮忙。谢谢

JSON 模式

{
    "type": "object",
    "properties": {
        "stat_data": {
            "type": "array",
            "minItems": 1,
            "items": {
                "type": "object",
                "properties": {},
                "anyOf": [{
                        "required": ["region"],
                        "properties": {
                            "region": {
                                "enum": ["america"]
                            },
                            "country": {
                                "type": "string"
                            },
                            "population": {
                                "type": "string"
                            }
                        }
                    },
                    {
                        "oneOf": [
                            {
                                "required": ["region"],
                                "properties": { …
Run Code Online (Sandbox Code Playgroud)

jsonschema ajv

4
推荐指数
1
解决办法
4198
查看次数