Skip to content
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,8 @@ import { registerSchema, validate } from "@hyperjump/json-schema/draft-2020-12";
import { BASIC } from "@hyperjump/json-schema/experimental.js";

class EvaluatedKeywordsPlugin {
id = "https://example.com/plugins/evaluated-keywords";

constructor() {
this.schemaLocations = new Set();
}
Expand Down Expand Up @@ -772,6 +774,7 @@ These are available from the `@hyperjump/json-schema/experimental` export.
processed to create human readable error messages as needed.

* **EvaluationPlugin**: object
* id?: string
* beforeSchema?(url: string, instance: JsonNode, context: Context): void
* beforeKeyword?(keywordNode: CompiledSchemaNode, instance: JsonNode, context: Context, schemaContext: Context, keyword: Keyword): void
* afterKeyword?(keywordNode: CompiledSchemaNode, instance: JsonNode, context: Context, valid: boolean, schemaContext: Context, keyword: Keyword): void
Expand Down
1 change: 1 addition & 0 deletions draft-2020-12/dynamicRef.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const interpret = ([id, fragment, ref], instance, context) => {
const simpleApplicator = true;

const plugin = {
id: `${id}#plugin`,
beforeSchema(url, _instance, context) {
context.dynamicAnchors = {
...context.ast.metaData[toAbsoluteUri(url)].dynamicAnchors,
Expand Down
2 changes: 2 additions & 0 deletions lib/evaluation-plugins/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import * as Instance from "../instance.js";


export class AnnotationsPlugin {
id = "https://json-schema.hyperjump.io/plugins/annotations";

beforeSchema(_url, _instance, context) {
context.annotations ??= [];
context.schemaAnnotations = [];
Expand Down
2 changes: 2 additions & 0 deletions lib/evaluation-plugins/basic-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import * as Instance from "../instance.js";


export class BasicOutputPlugin {
id = "https://json-schema.hyperjump.io/plugins/basic-output";

beforeSchema(_url, _intance, context) {
context.errors ??= [];
}
Expand Down
2 changes: 2 additions & 0 deletions lib/evaluation-plugins/detailed-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import * as Instance from "../instance.js";


export class DetailedOutputPlugin {
id = "https://json-schema.hyperjump.io/plugins/detailed-output";

beforeSchema(_url, _instance, context) {
context.errors ??= [];
}
Expand Down
4 changes: 4 additions & 0 deletions lib/experimental.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,15 @@ export type ValidationContext = {

// Evaluation Plugins
export type EvaluationPlugin<Context extends ValidationContext = ValidationContext> = {
id?: string;
beforeSchema?(url: string, instance: JsonNode, context: Context): void;
beforeKeyword?(keywordNode: Node<unknown>, instance: JsonNode, context: Context, schemaContext: Context, keyword: Keyword<unknown>): void;
afterKeyword?(keywordNode: Node<unknown>, instance: JsonNode, context: Context, valid: boolean, schemaContext: Context, keyword: Keyword<unknown>): void;
afterSchema?(url: string, instance: JsonNode, context: Context, valid: boolean): void;
};

export class BasicOutputPlugin implements EvaluationPlugin<ErrorsContext> {
id: string;
errors: OutputUnit[];

beforeSchema(url: string, instance: JsonNode, context: ErrorsContext): void;
Expand All @@ -104,6 +106,7 @@ export class BasicOutputPlugin implements EvaluationPlugin<ErrorsContext> {
}

export class DetailedOutputPlugin implements EvaluationPlugin<ErrorsContext> {
id: string;
errors: OutputUnit[];

beforeSchema(url: string, instance: JsonNode, context: ErrorsContext): void;
Expand All @@ -117,6 +120,7 @@ export type ErrorsContext = ValidationContext & {
};

export class AnnotationsPlugin implements EvaluationPlugin<AnnotationsContext> {
id: string;
annotations: OutputUnit[];

beforeSchema(url: string, instance: JsonNode, context: AnnotationsContext): void;
Expand Down
1 change: 1 addition & 0 deletions lib/keywords/dynamicRef.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const interpret = (fragment, instance, context) => {
const simpleApplicator = true;

const plugin = {
id: `${id}#plugin`,
beforeSchema(url, _instance, context) {
context.dynamicAnchors = {
...context.ast.metaData[toAbsoluteUri(url)].dynamicAnchors,
Expand Down
1 change: 1 addition & 0 deletions lib/keywords/unevaluatedItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const interpret = (unevaluatedItems, instance, context) => {
const simpleApplicator = true;

const plugin = {
id: `${id}#plugin`,
beforeSchema(_url, instance, context) {
context.evaluatedItems ??= new Set();
context.schemaEvaluatedItems = new Set();
Expand Down
1 change: 1 addition & 0 deletions lib/keywords/unevaluatedProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const interpret = (unevaluatedProperties, instance, context) => {
const simpleApplicator = true;

const plugin = {
id: `${id}#plugin`,
beforeSchema(_url, instance, context) {
context.evaluatedProperties ??= new Set();
context.schemaEvaluatedProperties = new Set();
Expand Down
Loading