Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new transform DSL, with rules and test for draft1 to draft 2 transformation #46

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
}
]
Loading