Skip to content

Commit 4bec034

Browse files
Add JSON schema
1 parent efdf0d8 commit 4bec034

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

Document.md

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ type Condition = {
5959
}
6060
```
6161
62+
[JSON Schema](validation-rules-schema.json)
63+
6264
For example:
6365
```json
6466
[

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ type Condition = {
2828
}
2929
```
3030
31+
[JSON Schema](validation-rules-schema.json)
32+
3133
For example:
3234
```json
3335
[

validation-rules-schema.json

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema",
3+
"title": "Rules",
4+
"description": "A list of validation rules",
5+
"type": "array",
6+
"items": {
7+
"type": "object",
8+
"properties": {
9+
"condition": {
10+
"description": "The condition to be met for the rule to pass",
11+
"type": "object",
12+
"properties": {
13+
"type": {
14+
"description": "The type of the condition",
15+
"enum": [
16+
"and", "or", "null", "in", "blank", "regex", "bytes", "length", "contains", "range", "true",
17+
"!and", "!or", "!null", "!in", "!blank", "!regex", "!bytes", "!length", "!contains", "!range", "!true"
18+
]
19+
},
20+
"field": {
21+
"description": "The field to be checked",
22+
"type": "string"
23+
},
24+
"arg": {
25+
"description": "The argument of the condition",
26+
"type": "string"
27+
},
28+
"args": {
29+
"description": "The arguments of the condition",
30+
"type": "array",
31+
"items": {
32+
"type": "string",
33+
"minItems": 1,
34+
"uniqueItems": true
35+
}
36+
},
37+
"conditions": {
38+
"description": "The sub-conditions of the condition",
39+
"type": "array",
40+
"items": {
41+
"$ref": "#/items/properties/condition"
42+
}
43+
}
44+
},
45+
"required": ["type"],
46+
"anyOf": [
47+
{
48+
"properties": {
49+
"type": { "enum": [
50+
"regex", "bytes", "length", "contains", "range",
51+
"!regex", "!bytes", "!length", "!contains", "!range"
52+
] }
53+
},
54+
"required": ["arg"]
55+
},
56+
{
57+
"properties": {
58+
"type": { "enum": ["in", "!in"] }
59+
},
60+
"required": ["args"]
61+
},
62+
{
63+
"properties": {
64+
"type": { "enum": ["and", "or", "!and", "!or"] }
65+
},
66+
"required": ["conditions"]
67+
}
68+
],
69+
"defaultSnippets": [
70+
{ "label": "Condition", "body": { "type": "" } },
71+
{ "label": "Condition with an argument", "body": { "type": "", "arg": "" } },
72+
{ "label": "Condition with multiple arguments", "body": { "type": "", "args": [] } },
73+
{ "label": "Condition with sub-conditions", "body": { "type": "", "conditions": [{ "type": "" }] } }
74+
]
75+
},
76+
"id": {
77+
"description": "The unique identifier for the rule",
78+
"type": "integer"
79+
},
80+
"errorMessage": {
81+
"description": "The error message to be returned if the rule fails",
82+
"type": "string"
83+
}
84+
},
85+
"required": ["condition"]
86+
}
87+
}

0 commit comments

Comments
 (0)