ポリシー言語を検証するためのスキーマを作成しようとしています。短い:JsonスキーマoneOf with additionalProperties draft-04
ポリシーはアサーションに関連付けられています。このアサーションは、演算子(または、またはそうでない)のいずれかであり、他のアサーションのリストを含みます。アサーションはプリミティブ(リーフノード)でもかまいません。
私は理解し、物事を容易にするためにUMLの設計をした:
{
"policy": {
"name": "test",
"expression": {
"operator": "all",
"value": [
{
"primitive": "encrypt",
"preference": 12345,
"usage": "required"
},
{
"primitive": "sign",
"preference": 12345,
"usage": "required"
}
],
"preference": 12345,
"usage": "required"
}
}
}
そして、ここでは、私が作っcurrentyスキームである:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"minProperties": 1,
"additionalProperties": {
"$ref": "#/definitions/policy"
},
"definitions": {
"policy": {
"title": "Policy",
"type": "object",
"required": [
"name",
"expression"
],
"additionalProperties": false,
"properties": {
"name": {
"type": "string"
},
"expression": {
"$ref": "#/definitions/assertion"
}
}
},
"operator": {
"properties": {
"value": {
"type": "array",
"items": {
"$ref": "#/definitions/assertion"
}
},
"operator": {
"enum": [
"allOne",
"all"
]
}
}
},
"primitive": {
"properties": {
"primitive": {
"enum": [
"encrypt",
"sign"
]
}
}
},
"assertion": {
"type": "object",
"additionalProperties": false,
"oneOf": [
{
"$ref": "#/definitions/operator"
},
{
"$ref": "#/definitions/primitive"
}
],
"properties": {
"preference": {
"type": "integer",
"minimum": 0,
"exclusiveMinimum": true
},
"usage": {
"enum": [
"required",
"rejected",
"optional",
"observed",
"ignored"
]
}
}
}
}
}
"oneOf"
を使用するとI演算子またはプリミティブの指定を使用しようとしています。エラーメッセージが(理由"additionalProperties": false
の)定義されていない余分な性質文句
"message" : "object instance has properties which are not allowed by the schema: [\"operator\",\"value\"]"
:しかし、私は次のエラーを受信したため、これが移動するための方法であるか分かりません。ただし、これらは定義に定義されています...
これを参照してください:私の例では、次のようになるでしょうhttps://github.com/epoberezkin/ajv/blob/master/FAQ.md#additional-properties-inside-compound-keywords-anyof-oneof- etc これはhttps://github.com/epoberezkin/ajv/issues/134#issuecomment-242989744 – esp
です。情報のおかげで。 – freskimo