Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Commit 3380d9a

Browse files
authored
Create schema.json (#248)
Import json schema validation for constraintset
1 parent b65bbfb commit 3380d9a

File tree

1 file changed

+166
-0
lines changed

1 file changed

+166
-0
lines changed
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"definitions": {
4+
"value": {
5+
"description": "number or reference",
6+
"$id": "#value",
7+
"type": ["number", "string"]
8+
},
9+
"color": {
10+
"$id": "#color",
11+
"type": "string",
12+
"pattern": "(^#[0-9a-fA-f]{3,4}$)|(^#[0-9a-fA-f]{6}$)|(^#[0-9a-fA-f]{8}$)"
13+
},
14+
"reference": {
15+
"$id": "#reference",
16+
"type": "string"
17+
},
18+
"dimension-constraint": {
19+
"$id": "#dimension-constraint",
20+
"anyOf": [
21+
{
22+
"type": "number"
23+
},
24+
{
25+
"type": "string"
26+
}
27+
]
28+
},
29+
"horizontal-constraint": {
30+
"$id": "#horizontal-constraint",
31+
"type": "array",
32+
"additionalItems": false,
33+
"minItems": 2,
34+
"maxItems": 3,
35+
"items": [
36+
{
37+
"description": "target reference",
38+
"$ref": "#reference"
39+
},
40+
{
41+
"title": "target reference",
42+
"enum": [
43+
"start",
44+
"end"
45+
]
46+
},
47+
{
48+
"description": "margin",
49+
"$ref": "#value"
50+
}
51+
]
52+
},
53+
"vertical-constraint": {
54+
"$id": "#vertical-constraint",
55+
"type": "array",
56+
"additionalItems": false,
57+
"minItems": 2,
58+
"maxItems": 3,
59+
"items": [
60+
{
61+
"description": "target reference",
62+
"$ref": "#reference"
63+
},
64+
{
65+
"description": "target reference",
66+
"enum": [ "top", "bottom", "baseline" ]
67+
},
68+
{
69+
"description": "margin",
70+
"$ref": "#value"
71+
}
72+
]
73+
},
74+
"circular-constraint": {
75+
"$id": "#circular-constraint",
76+
"type": "array",
77+
"additionalItems": false,
78+
"minItems": 3,
79+
"maxItems": 3,
80+
"items": [
81+
{
82+
"description": "target reference",
83+
"$ref": "#reference"
84+
},
85+
{
86+
"description": "angle",
87+
"$ref": "#value"
88+
},
89+
{
90+
"description": "distance",
91+
"$ref": "#value"
92+
}
93+
]
94+
}
95+
},
96+
"title": "ConstraintSet",
97+
"description": "A set of rules to apply to ConstraintLayout elements",
98+
"type": "object",
99+
"properties": {
100+
"Variables": {
101+
"description": "Define variables that can be used in the rest of the file",
102+
"type": "object",
103+
"patternProperties": {
104+
"^[a-z_][a-z0-9_]*$": {
105+
"description": "Variable",
106+
"anyOf": [
107+
{
108+
"type": "object",
109+
"additionalProperties": false,
110+
"properties": {
111+
"start": {
112+
"description": "Generator starting value",
113+
"$ref": "#value"
114+
},
115+
"increment": {
116+
"description": "Generator increment value",
117+
"$ref": "#value"
118+
}
119+
},
120+
"required": [
121+
"start",
122+
"increment"
123+
]
124+
},
125+
{
126+
"type": "number"
127+
}
128+
]
129+
}
130+
}
131+
},
132+
"Generate": {
133+
"type": "object"
134+
},
135+
"Helpers": {
136+
"type": "object"
137+
}
138+
},
139+
"patternProperties": {
140+
"^[a-z_][a-z0-9_]*$": {
141+
"type": "object",
142+
"additionalProperties": false,
143+
"properties": {
144+
"width": { "$ref": "#dimension-constraint", "description": "horizontal dimension constraint" },
145+
"height": { "$ref": "#dimension-constraint", "description": "vertical dimension constraint" },
146+
"start": { "$ref": "#horizontal-constraint", "description": "start constraint to a target" },
147+
"end": { "$ref": "#horizontal-constraint", "description": "end constraint to a target" },
148+
"top": { "$ref": "#vertical-constraint", "description": "top constraint to a target" },
149+
"bottom": { "$ref": "#vertical-constraint", "description": "bottom constraint to a target" },
150+
"baseline": { "$ref": "#vertical-constraint", "description": "baseline constraint to a target" },
151+
"circular": { "$ref": "#circular-constraint", "description": "circular constraint to a target" },
152+
"center": { "$ref": "#reference", "description": "center the widget relative to the target" },
153+
"centerHorizontally": { "$ref": "#reference", "description": "center the widget horizontally relative to the target" },
154+
"centerVertically": { "$ref": "#reference", "description": "center the widget vertically relative to the target" },
155+
"alpha": { "$ref": "#value", "description": "alpha value (transparency) from 0-1" },
156+
"translationX": { "$ref": "#value", "description": "translation in X" },
157+
"translationY": { "$ref": "#value", "description": "translation in Y" },
158+
"scaleX": { "$ref": "#value", "description": "scale in X" },
159+
"scaleY": { "$ref": "#value", "description": "scale in Y" },
160+
"rotationX": { "$ref": "#value", "description": "rotation in X "},
161+
"rotationY": { "$ref": "#value", "description": "rotation in Y" },
162+
"rotationZ": { "$ref": "#value", "description": "rotation in Z" }
163+
}
164+
}
165+
}
166+
}

0 commit comments

Comments
 (0)