-
-
Notifications
You must be signed in to change notification settings - Fork 11
Add Support for JSON Schema Draft-04 Keywords #130
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7d9c840
feat(draft-04): add support for JSON Schema Draft-04 keywords
srivastava-diya 5ea3dbb
draft-04 support
srivastava-diya 9f4fb1d
refactor dependencies error-handler
srivastava-diya b28cc1b
add correct compatibility for dependencies test
srivastava-diya a0329f0
fix formatting
srivastava-diya b8990cb
refactor draft-04 max and min error handler
srivastava-diya 48616c0
code cleanup
srivastava-diya aca810b
use expanded form for messageParams in min/max test
srivastava-diya 842fdf4
remove redundant imports after conflict resolution
srivastava-diya 1372fc9
Final cleanup
jdesrosiers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,49 @@ | ||
| import { getSchema } from "@hyperjump/json-schema/experimental"; | ||
| import * as Schema from "@hyperjump/browser"; | ||
| import * as Instance from "@hyperjump/json-schema/instance/experimental"; | ||
| import { getErrors } from "../../json-schema-errors.js"; | ||
|
|
||
| /** | ||
| * @import { ErrorHandler, ErrorObject } from "../../index.d.ts" | ||
| */ | ||
|
|
||
| /** @type ErrorHandler */ | ||
| const dependenciesErrorHandler = async (normalizedErrors, instance, localization) => { | ||
| /** @type ErrorObject[] */ | ||
| const errors = []; | ||
|
|
||
| for (const schemaLocation in normalizedErrors["https://json-schema.org/keyword/draft-04/dependencies"]) { | ||
| if (typeof normalizedErrors["https://json-schema.org/keyword/draft-04/dependencies"][schemaLocation] === "boolean") { | ||
| continue; | ||
| } | ||
|
|
||
| const dependentSchemaOutputs = normalizedErrors["https://json-schema.org/keyword/draft-04/dependencies"][schemaLocation]; | ||
| for (const dependentSchemaOutput of dependentSchemaOutputs) { | ||
| const dependentSchemaErrors = await getErrors(dependentSchemaOutput, instance, localization); | ||
| errors.push(...dependentSchemaErrors); | ||
| } | ||
|
|
||
| const dependencies = await getSchema(schemaLocation); | ||
| for await (const [propertyName, dependency] of Schema.entries(dependencies)) { | ||
| if (!Instance.has(propertyName, instance)) { | ||
| continue; | ||
| } | ||
|
|
||
| if (Schema.typeOf(dependency) !== "array") { | ||
| continue; | ||
| } | ||
|
|
||
| const dependentRequired = /** @type {string[]} */ (Schema.value(dependency)); | ||
| const missing = dependentRequired.filter((required) => !Instance.has(required, instance)); | ||
| errors.push({ | ||
| message: localization.getRequiredErrorMessage(missing), | ||
| instanceLocation: Instance.uri(instance), | ||
| schemaLocations: [schemaLocation] | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| return errors; | ||
| }; | ||
|
|
||
| export default dependenciesErrorHandler; |
This file contains hidden or 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,55 @@ | ||
| import { getSchema } from "@hyperjump/json-schema/experimental"; | ||
| import * as Schema from "@hyperjump/browser"; | ||
| import * as Instance from "@hyperjump/json-schema/instance/experimental"; | ||
|
|
||
| /** | ||
| * @import { ErrorHandler, ErrorObject } from "../../index.d.ts" | ||
| */ | ||
|
|
||
| /** @type ErrorHandler */ | ||
| const maximumErrorHandler = async (normalizedErrors, instance, localization) => { | ||
| /** @type ErrorObject[] */ | ||
| const errors = []; | ||
|
|
||
| for (const schemaLocation in normalizedErrors["https://json-schema.org/keyword/draft-04/maximum"]) { | ||
| if (normalizedErrors["https://json-schema.org/keyword/draft-04/maximum"][schemaLocation]) { | ||
| continue; | ||
| } | ||
|
|
||
| const parentLocation = pointerPop(schemaLocation); | ||
|
|
||
| let exclusive = false; | ||
| for (const exclusiveLocation in normalizedErrors["https://json-schema.org/keyword/draft-04/exclusiveMaximum"]) { | ||
| const exclusiveParentLocation = pointerPop(exclusiveLocation); | ||
| if (exclusiveParentLocation === parentLocation) { | ||
| const exclusiveNode = await getSchema(exclusiveLocation); | ||
| exclusive = /** @type boolean */ (Schema.value(exclusiveNode)); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| const keywordNode = await getSchema(schemaLocation); | ||
| const maximum = /** @type number */ (Schema.value(keywordNode)); | ||
|
|
||
| if (exclusive) { | ||
| errors.push({ | ||
| message: localization.getExclusiveMaximumErrorMessage(maximum), | ||
| instanceLocation: Instance.uri(instance), | ||
| schemaLocations: [schemaLocation] | ||
| }); | ||
| } else { | ||
| errors.push({ | ||
| message: localization.getMaximumErrorMessage(maximum), | ||
| instanceLocation: Instance.uri(instance), | ||
| schemaLocations: [schemaLocation] | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| return errors; | ||
| }; | ||
|
|
||
| /** @type (pointer: string) => string */ | ||
| const pointerPop = (pointer) => pointer.replace(/\/[^/]+$/, ""); | ||
|
|
||
| export default maximumErrorHandler; | ||
This file contains hidden or 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,55 @@ | ||
| import { getSchema } from "@hyperjump/json-schema/experimental"; | ||
| import * as Schema from "@hyperjump/browser"; | ||
| import * as Instance from "@hyperjump/json-schema/instance/experimental"; | ||
|
|
||
| /** | ||
| * @import { ErrorHandler, ErrorObject } from "../../index.d.ts" | ||
| */ | ||
|
|
||
| /** @type ErrorHandler */ | ||
| const minimumErrorHandler = async (normalizedErrors, instance, localization) => { | ||
| /** @type ErrorObject[] */ | ||
| const errors = []; | ||
|
|
||
| for (const schemaLocation in normalizedErrors["https://json-schema.org/keyword/draft-04/minimum"]) { | ||
| if (normalizedErrors["https://json-schema.org/keyword/draft-04/minimum"][schemaLocation]) { | ||
| continue; | ||
| } | ||
|
|
||
| const parentLocation = pointerPop(schemaLocation); | ||
|
|
||
| let exclusive = false; | ||
| for (const exclusiveLocation in normalizedErrors["https://json-schema.org/keyword/draft-04/exclusiveMinimum"]) { | ||
| const exclusiveParentLocation = pointerPop(exclusiveLocation); | ||
| if (exclusiveParentLocation === parentLocation) { | ||
| const exclusiveNode = await getSchema(exclusiveLocation); | ||
| exclusive = /** @type boolean */ (Schema.value(exclusiveNode)); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| const keywordNode = await getSchema(schemaLocation); | ||
| const minimum = /** @type number */ (Schema.value(keywordNode)); | ||
|
|
||
| if (exclusive) { | ||
| errors.push({ | ||
| message: localization.getExclusiveMinimumErrorMessage(minimum), | ||
| instanceLocation: Instance.uri(instance), | ||
| schemaLocations: [schemaLocation] | ||
| }); | ||
| } else { | ||
| errors.push({ | ||
| message: localization.getMinimumErrorMessage(minimum), | ||
| instanceLocation: Instance.uri(instance), | ||
| schemaLocations: [schemaLocation] | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| return errors; | ||
| }; | ||
|
|
||
| /** @type (pointer: string) => string */ | ||
| const pointerPop = (pointer) => pointer.replace(/\/[^/]+$/, ""); | ||
|
|
||
| export default minimumErrorHandler; |
This file contains hidden or 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 hidden or 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 hidden or 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,30 @@ | ||
| import { evaluateSchema } from "../../json-schema-errors.js"; | ||
| import * as Instance from "@hyperjump/json-schema/instance/experimental"; | ||
|
|
||
| /** | ||
| * @import { NormalizationHandler, NormalizedOutput } from "../../index.d.ts" | ||
| */ | ||
|
|
||
| /** @type NormalizationHandler<[string, string | string[]][]> */ | ||
| const dependenciesNormalizationHandler = { | ||
| evaluate(dependencies, instance, context) { | ||
| /** @type NormalizedOutput[] */ | ||
| const outputs = []; | ||
|
|
||
| if (Instance.typeOf(instance) !== "object") { | ||
| return outputs; | ||
| } | ||
|
|
||
| for (const [propertyName, dependency] of dependencies) { | ||
| if (!Instance.has(propertyName, instance) || typeof dependency !== "string") { | ||
| continue; | ||
| } | ||
|
|
||
| outputs.push(evaluateSchema(dependency, instance, context)); | ||
| } | ||
|
|
||
| return outputs; | ||
| } | ||
| }; | ||
|
|
||
| export default dependenciesNormalizationHandler; |
This file contains hidden or 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,11 @@ | ||
| /** | ||
| * @import { NormalizationHandler } from "../../index.d.ts" | ||
| */ | ||
|
|
||
| /** @type NormalizationHandler */ | ||
| const exclusiveMaximumNormalizationHandler = { | ||
| evaluate() { | ||
| } | ||
| }; | ||
|
|
||
| export default exclusiveMaximumNormalizationHandler; |
This file contains hidden or 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,11 @@ | ||
| /** | ||
| * @import { NormalizationHandler } from "../../index.d.ts" | ||
| */ | ||
|
|
||
| /** @type NormalizationHandler */ | ||
| const exclusiveMinimumNormalizationHandler = { | ||
| evaluate() { | ||
| } | ||
| }; | ||
|
|
||
| export default exclusiveMinimumNormalizationHandler; |
This file contains hidden or 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,11 @@ | ||
| /** | ||
| * @import { NormalizationHandler } from "../../index.d.ts" | ||
| */ | ||
|
|
||
| /** @type NormalizationHandler */ | ||
| const maximumNormalizationHandler = { | ||
| evaluate() { | ||
| } | ||
| }; | ||
|
|
||
| export default maximumNormalizationHandler; |
This file contains hidden or 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,11 @@ | ||
| /** | ||
| * @import { NormalizationHandler } from "../../index.d.ts" | ||
| */ | ||
|
|
||
| /** @type NormalizationHandler */ | ||
| const minimumNormalizationHandler = { | ||
| evaluate() { | ||
| } | ||
| }; | ||
|
|
||
| export default minimumNormalizationHandler; |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.