-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add before/after hooks and definitions options (#52)
- Loading branch information
Showing
10 changed files
with
1,997 additions
and
1,326 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,6 @@ jobs: | |
strategy: | ||
matrix: | ||
node-version: | ||
- 14 | ||
- 16 | ||
- 18 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import convert from "../src"; | ||
|
||
it("handles conversion in keywords specified in additionalKeywords", function ({ expect }) { | ||
const schema = { | ||
definitions: { | ||
sharedDefinition: { | ||
type: "object", | ||
properties: { | ||
foo: { | ||
type: "string", | ||
nullable: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const result = convert(schema, { | ||
definitionKeywords: ["definitions"], | ||
}); | ||
|
||
const expected = { | ||
$schema: "http://json-schema.org/draft-04/schema#", | ||
definitions: { | ||
sharedDefinition: { | ||
type: "object", | ||
properties: { | ||
foo: { | ||
type: ["string", "null"], | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
expect(result).toEqual(expected); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import convert from "../src"; | ||
|
||
it("handles conversion in keywords specified in additionalKeywords", function ({ expect }) { | ||
const schema = { | ||
type: "boolean", | ||
}; | ||
|
||
const result = convert(schema, { | ||
beforeTransform: function (schema) { | ||
schema.type = "string"; | ||
return schema; | ||
}, | ||
afterTransform: function (schema) { | ||
schema.examples = ["foo", "bar"]; | ||
return schema; | ||
}, | ||
}); | ||
|
||
const expected = { | ||
$schema: "http://json-schema.org/draft-04/schema#", | ||
type: "string", | ||
examples: ["foo", "bar"], | ||
}; | ||
|
||
expect(result).toEqual(expected); | ||
}); |
Oops, something went wrong.