1

私は AJV (JS JSON Schema Validator) を使用しており、それがサポートする型を拡張する方法を見つけようとしています。

スキーマにカスタムタイプがあるため、このエラーが発生します(Pythonで検証しているDocumentReference-jsonschemaも)

Error: schema is invalid: data.properties['allow'].properties['custom_signature'].type should be equal to one of the allowed values, data.properties['allow'].properties['custom_signature'].type[0] should be equal to one of the allowed values, data.properties['allow'].properties['custom_signature'].type should match some schema in anyOf
    at Ajv.validateSchema (ajv.js?ea76:183)
    at Ajv._addSchema (ajv.js?ea76:312)
    at Ajv.compile (ajv.js?ea76:112)
    at eval (configs.js?76ed:66)

これはスキーマの小さなサンプルです。

"custom_signature": {
    "type": [
        "DocumentReference",
        "object",
        "null"
    ]
},

python jsonschema には、型を拡張し、それらを検証する方法を定義する方法があります.AJVに同等のものはありますか?

var json = {
  "type": "object",
  "properties": {
    "custom_signature": {
      "type": [
        "DocumentReference",
        "null",
        "object"
      ]
    }
  }
};

const ajv = new Ajv({
  allErrors: true
});
console.log(ajv);
const validate = ajv.compile(json);
console.log(validate({'custom_signature': {}}));
<script src="https://cdnjs.cloudflare.com/ajax/libs/ajv/6.4.0/ajv.min.js"></script>

JSFiddle

4

1 に答える 1