Skip to content

Commit 66b5302

Browse files
authored
Add a new transform DSL, with rules and test for draft1 to draft 2 transformation (#46)
1 parent 1481536 commit 66b5302

File tree

5 files changed

+88
-0
lines changed

5 files changed

+88
-0
lines changed

DSL/transform.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,41 @@ Replaces the value at the given path with an absolute value.
156156
}
157157
```
158158

159+
### `replace-with-1-by-ten-power-value`
160+
161+
Replaces the value at the given path with the result of 1 divided by 10 raised to the power of the current value.
162+
163+
- **Takes**: `path`
164+
165+
**Before**:
166+
167+
```json
168+
{
169+
"$schema": "http://json-schema.org/draft-01/schema#",
170+
"exponent": 2,
171+
"rate": 3
172+
}
173+
```
174+
175+
**Transform**:
176+
177+
```json
178+
[
179+
{ "operation": "replace-with-1-by-ten-power-value", "path": [ "exponent" ] },
180+
{ "operation": "replace-with-1-by-ten-power-value", "path": [ "rate" ] }
181+
]
182+
```
183+
184+
**After**:
185+
186+
```json
187+
{
188+
"$schema": "http://json-schema.org/draft-02/schema#",
189+
"exponent": 0.01,
190+
"rate": 0.001
191+
}
192+
```
193+
159194
### `remove`
160195

161196
Removes the key and its respective value at the given path.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"vocabulary": "none",
3+
"condition": [
4+
{ "operation": "has-key", "path": [], "value": "uniqueItems" }
5+
],
6+
"transform": [
7+
{ "operation": "prefix-until-unique", "path": [ "uniqueItems" ], "value": "x-" }
8+
]
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"vocabulary": "validation",
3+
"condition": [
4+
{ "operation": "has-key", "path": [], "value": "maxDecimal" }
5+
],
6+
"transform": [
7+
{ "operation": "replace-with-1-by-ten-power-value", "path": [ "maxDecimal" ] }
8+
]
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[
2+
{
3+
"title": "maxDecimal present in the schema",
4+
"from": {
5+
"maxDecimal": 2
6+
},
7+
"to": {
8+
"maxDecimal": 0.01
9+
}
10+
}
11+
]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[
2+
{
3+
"title": "uniqueItems present in the schema",
4+
"from": {
5+
"uniqueItems": "newbie"
6+
},
7+
"to": {
8+
"x-uniqueItems": "newbie"
9+
}
10+
},
11+
{
12+
"title": "uniqueItems with uniqueItems having `x-` as prefix",
13+
"from": {
14+
"x-uniqueItems": "expert",
15+
"x-x-uniqueItems": "master",
16+
"uniqueItems": "newbie"
17+
},
18+
"to": {
19+
"x-uniqueItems": "expert",
20+
"x-x-uniqueItems": "master",
21+
"x-x-x-uniqueItems": "newbie"
22+
}
23+
}
24+
]

0 commit comments

Comments
 (0)