Skip to content

Commit

Permalink
Add a new transform DSL, with rules and test for draft1 to draft 2 tr…
Browse files Browse the repository at this point in the history
…ansformation (#46)
  • Loading branch information
suprith-hub authored Aug 9, 2024
1 parent 1481536 commit 66b5302
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 0 deletions.
35 changes: 35 additions & 0 deletions DSL/transform.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,41 @@ Replaces the value at the given path with an absolute value.
}
```

### `replace-with-1-by-ten-power-value`

Replaces the value at the given path with the result of 1 divided by 10 raised to the power of the current value.

- **Takes**: `path`

**Before**:

```json
{
"$schema": "http://json-schema.org/draft-01/schema#",
"exponent": 2,
"rate": 3
}
```

**Transform**:

```json
[
{ "operation": "replace-with-1-by-ten-power-value", "path": [ "exponent" ] },
{ "operation": "replace-with-1-by-ten-power-value", "path": [ "rate" ] }
]
```

**After**:

```json
{
"$schema": "http://json-schema.org/draft-02/schema#",
"exponent": 0.01,
"rate": 0.001
}
```

### `remove`

Removes the key and its respective value at the given path.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"vocabulary": "none",
"condition": [
{ "operation": "has-key", "path": [], "value": "uniqueItems" }
],
"transform": [
{ "operation": "prefix-until-unique", "path": [ "uniqueItems" ], "value": "x-" }
]
}
9 changes: 9 additions & 0 deletions rules/from-draft1/to-draft2/002-maxDecimal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"vocabulary": "validation",
"condition": [
{ "operation": "has-key", "path": [], "value": "maxDecimal" }
],
"transform": [
{ "operation": "replace-with-1-by-ten-power-value", "path": [ "maxDecimal" ] }
]
}
11 changes: 11 additions & 0 deletions test/from-draft1/to-draft2/maxDecimal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"title": "maxDecimal present in the schema",
"from": {
"maxDecimal": 2
},
"to": {
"maxDecimal": 0.01
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
{
"title": "uniqueItems present in the schema",
"from": {
"uniqueItems": "newbie"
},
"to": {
"x-uniqueItems": "newbie"
}
},
{
"title": "uniqueItems with uniqueItems having `x-` as prefix",
"from": {
"x-uniqueItems": "expert",
"x-x-uniqueItems": "master",
"uniqueItems": "newbie"
},
"to": {
"x-uniqueItems": "expert",
"x-x-uniqueItems": "master",
"x-x-x-uniqueItems": "newbie"
}
}
]

0 comments on commit 66b5302

Please sign in to comment.