Skip to content

How to compile multiple schemas into a single AST? #116

@x0k

Description

@x0k

I am currently using the following approach, but it has several typing issues:

for (const schema of schemas) {
  registerSchema(
    Object.assign(
      { $schema: "http://json-schema.org/draft-07/schema" },
      schema as SchemaObject,
    ),
  );
}
// AST declares `plugins` as an array, but the property is used as a `Set`
// https://github.com/hyperjump-io/json-schema/blob/50dd7df599011bcd1df3283b2073507e9fc02bf9/lib/keywords/validation.js#L39
const ast = { metaData: {}, plugins: new Set() } as unknown as AST;
for (const schema of schemas) {
  const s = await getSchema(schema.$id!);
  // `Validation.compile` does not use the third argument
  // https://github.com/hyperjump-io/json-schema/blob/50dd7df599011bcd1df3283b2073507e9fc02bf9/lib/keywords/validation.js#L10
  await Validation.compile(s, ast, s);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions