JSON Schema Draft-07, если требуется, проверка полей, обязательных для заполнения, кажется неправильной - PullRequest
0 голосов
/ 02 июля 2018

Использование Draft-07

То, что я получил, было действительный JSON

Какую ошибку я ожидал от объекта аудита каталог: длина строки должна быть больше или равна 2

Пробовал два разных валидатора с одинаковыми результатами

  1. https://www.jsonschemavalidator.net/
  2. GoLang https://github.com/xeipuuv/gojsonschema

Это моя схема

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "ISAM-Wrapper",
  "description": "Validate isam wrapper json",
  "type": "object",
  "properties": {
    "directory": {
      "description": "path to location of isam file",
      "type": "string",
      "minLength": 2
    },
    "isamFile": {
      "description": "isam database file",
      "type": "string",
      "minLength": 4
    },
    "isamIndex": {
      "description": "isam index file",
      "type": "string",
      "minLength": 4
    },
    "port": {
      "description": "port number for REST listener",
      "type": "integer",
      "minimum": 60410,
      "maximum": 69999
    },
    "actions": {
      "description": "Which operations are supported",
      "type": "object",
      "items": {
        "properties": {
          "create": {
            "type": "boolean"
          },
          "read": {
            "type": "boolean"
          },
          "update": {
            "type": "boolean"
          },
          "delete": {
            "type": "boolean"
          }
        }
      },
      "required": [
        "create",
        "read",
        "update",
        "delete"
      ]
    },
    "fields": {
      "description": "each object describes one field of the isam file",
      "type": "array",
      "minItems": 1,
      "items": {
        "title": "field",
        "description": "field schema",
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1
          },
          "ordinal": {
            "type": "integer",
            "minimum": 0
          },
          "offset": {
            "type": "integer",
            "minimum": 0
          },
          "length": {
            "type": "integer",
            "minimum": 1
          },
          "dataType": {
            "enum": [
              "uchar",
              "ulong",
              "long",
              "uint",
              "int",
              "ushort",
              "short"
            ]
          }
        },
        "required": [
          "name",
          "ordinal",
          "offset",
          "length",
          "dataType"
        ]
      }
    },
    "audit": {
      "description": "input needed to enable and configure isam auditing",
      "type": "object",
      "items": {
        "properties": {
          "enable": {
            "enum": [
              true,
              false
            ]
          },
          "directory": {
            "type": "string",
            "minLength": 2
          },
          "fileName": {
            "type": "string",
            "minLength": 4
          },
          "workDirectory": {
            "type": "string",
            "minLength": 2
          },
          "archiveDirectory": {
            "type": "string",
            "minLength": 2
          },
          "interval": {
            "type": "integer",
            "minimum": 1
          },
          "byteThreshold": {
            "type": "integer",
            "minimum": 1048576,
            "maximum": 1073741824
          }
        }
      },
      "required": [
        "enable"
      ],
      "if": {
        "not": {
          "properties": {
            "enable": {
              "enum": [
                false
              ]
            }
          }
        }
      },
      "then": {
        "required": [
          "directory",
          "fileName",
          "workDirectory",
          "archiveDirectory",
          "interval",
          "byteThreshold"
        ]
      }
    }
  },
  "required": [
    "directory",
    "isamFile",
    "isamIndex",
    "port",
    "actions",
    "fields",
    "audit"
  ]
}

Это мой JSON

{
  "directory": "./",
  "isamFile": "isam.dat",
  "isamIndex": "isam.idx",
  "port": 60410,
  "actions": {
    "create": true,
    "read": true,
    "update": true,
    "delete": true
  },
  "fields": [
    {
      "name": "F1",
      "ordinal": 0,
      "offset": 0,
      "length": 4,
      "dataType": "ulong"
    },
    {
      "name": "F2",
      "ordinal": 1,
      "offset": 4,
      "length": 4,
      "dataType": "ulong"
    }
  ],
  "audit": {
    "enable": true,
    "directory": "",
    "fileName": "file",
    "workDirectory": "./work",
    "archiveDirectory": "./archive",
    "interval": 5,
      "byteThreshold": 1500000
  }
}

1 Ответ

0 голосов
/ 01 ноября 2018

Эта проблема заключается в том, что ваша схема недействительна. Для actions и audit вы указываете их как object s, но не предоставляете properties. Однако, что вы делаете , это указываете ключ items (который здесь ничего не делает - это ключ для array), который содержит свойства.

Как только вы исправите эту ошибку, схема будет работать так, как вам нужно, см. https://repl.it/repls/BlankWellmadeFrontpage

...