Skip to content

Commit 4d36215

Browse files
committed
doc: Add ruleset schema
1 parent dfb9859 commit 4d36215

File tree

6 files changed

+121
-2
lines changed

6 files changed

+121
-2
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
.vscode
21
rules

.vscode/settings.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"json.schemas": [
3+
{
4+
"fileMatch": [
5+
"/scripts/test-rules.json"
6+
],
7+
"url": "/ruleset.schema.json"
8+
}
9+
]
10+
}

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ Community-contributed rulesets are hosted on GitHub, and you can find them at [p
121121
}
122122
```
123123

124+
Formal definition of the format can be found at [`ruleset.schema.json`](./ruleset.schema.json).
125+
124126
### ✅ Path Matching
125127

126128
`<domain>`, `<path>`: The domain and a part of path, such as `example.com/`, `/^.+\.example\.com$`, `path/` and `page`. Here's an explanation of them:

README_zh.md

+2
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ new Purlfy({
121121
}
122122
```
123123

124+
此格式的形式化定义可以参考 [`ruleset.schema.json`](./ruleset.schema.json)
125+
124126
### ✅ 路径匹配
125127

126128
`<domain>`, `<path>`: 域名和一部分路径,例如 `example.com/`, `/^.+\.example\.com$`, `path/``page`。以下是对它们的解释:

ruleset.schema.json

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"title": "Ruleset Schema",
4+
"type": "object",
5+
"patternProperties": {
6+
"^[^/]+/$": {
7+
"$ref": "#/definitions/recurse"
8+
},
9+
"^[^/]+$": {
10+
"$ref": "#/definitions/rule"
11+
},
12+
"^/.+/$": {
13+
"$ref": "#/definitions/recurse"
14+
},
15+
"^/.+[^/]$": {
16+
"$ref": "#/definitions/rule"
17+
}
18+
},
19+
"definitions": {
20+
"rule": {
21+
"type": "object",
22+
"properties": {
23+
"description": {
24+
"type": "string"
25+
},
26+
"mode": {
27+
"type": "string",
28+
"enum": [
29+
"white",
30+
"black",
31+
"param",
32+
"regex",
33+
"redirect",
34+
"visit",
35+
"lambda",
36+
"headers",
37+
"continue"
38+
]
39+
},
40+
"params": {
41+
"type": "array",
42+
"items": {
43+
"type": "string"
44+
}
45+
},
46+
"author": {
47+
"type": "string"
48+
},
49+
"acts": {
50+
"type": "array",
51+
"items": {
52+
"type": "string"
53+
}
54+
},
55+
"lambda": {
56+
"type": "string"
57+
},
58+
"regex": {
59+
"type": "array",
60+
"items": {
61+
"type": "string"
62+
}
63+
},
64+
"replace": {
65+
"type": "array",
66+
"items": {
67+
"type": "string"
68+
}
69+
},
70+
"headers": {
71+
"type": "object",
72+
"additionalProperties": {
73+
"type": "string"
74+
}
75+
},
76+
"continue": {
77+
"type": "boolean"
78+
}
79+
},
80+
"required": [
81+
"mode",
82+
"description",
83+
"author"
84+
],
85+
"additionalProperties": false
86+
},
87+
"recurse": {
88+
"type": "object",
89+
"patternProperties": {
90+
"^[^/]+/$": {
91+
"$ref": "#/definitions/recurse"
92+
},
93+
"^[^/]+$": {
94+
"$ref": "#/definitions/rule"
95+
},
96+
"^/.+/$": {
97+
"$ref": "#/definitions/recurse"
98+
},
99+
"^/.+[^/]$": {
100+
"$ref": "#/definitions/rule"
101+
}
102+
}
103+
}
104+
},
105+
"additionalProperties": false
106+
}

scripts/test-rules.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@
6464
"author": "PRO-2684"
6565
}
6666
}
67-
}
67+
}

0 commit comments

Comments
 (0)