IF Commons GitHub

integrations/pure/import-json-schema

The generic importer of a JSON Schema (commons 0019-mizan-integrations FR-022, FR-023, FR-005, FR-006, FR-009): a slice of the $defs of a pinned schema (draft 2020-12), written as a generated TypeScript module in which each enum is a typed code list and each object's properties are a typed union of field names, so that a requirement names a value or a field of a schema we do not own and the compiler knows it exists in the pinned version.

The slice names definitions (Severity, Event), never the whole schema. A definition that is an enum, a const, or a oneOf or anyOf of consts becomes a code list: a const tuple and the union type of its members, named as the definition. A definition with properties becomes NameFields, an object keyed by field name whose entry says the field's type, whether it is required, the definition it refers to ($ref to #/$defs/...), its enum, its items, and NameField, the union of the field names; an enum or a nested object inside a property is lifted to a code list or fields of its own, named after the definition and the property. The checks are those of the other importers: a pin that differs, no license and no right to copy are refused, a definition the schema lacks is named, the same input gives the same text, and the module's header names the source, schema, hash and slice.

import { importJsonSchema } from "./import-json-schema.ts";
// importJsonSchema({ standard, sourceText, slice: ["Severity", "Event"] })

Source: commons/mizan/src/integrations/pure/import-json-schema.ts

1 of 6 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

integrations.importJsonSchemafunctionno test imports it
function importJsonSchema(i: JsonSchemaImportInput): Promise<Result<ImportOutput, readonly IntegrationFinding[]>>

A slice of the $defs of a JSON Schema as a generated module of typed code lists and field-name unions, or what stops it.

integrations.JSON_SCHEMA_GENERATORconstno test imports it
const JSON_SCHEMA_GENERATOR: "commons/mizan/src/integrations/pure/import-json-schema.ts"

The generator's name, as the provenance and the header of a generated module give it.

integrations.JsonSchemaImportInputtypeno test imports it
type JsonSchemaImportInput = {
  readonly standard: StandardRecord;
  /** The schema's JSON, as the pinned bytes read as UTF-8 text. */
  readonly sourceText: string;
  /** The names of the `$defs` to take, never the whole schema. */
  readonly slice: readonly string[];
};

What a JSON Schema import needs.

importJsonSchemafunction
function importJsonSchema(i: JsonSchemaImportInput): Promise<Result<ImportOutput, readonly IntegrationFinding[]>>

A slice of the $defs of a JSON Schema as a generated module of typed code lists and field-name unions, or what stops it.

Imported by 10 tests of the run (10 passed, 0 failed): the library's results

JSON_SCHEMA_GENERATORconstno test imports it
const JSON_SCHEMA_GENERATOR: "commons/mizan/src/integrations/pure/import-json-schema.ts"

The generator's name, as the provenance and the header of a generated module give it.

JsonSchemaImportInputtypeno test imports it
type JsonSchemaImportInput = {
  readonly standard: StandardRecord;
  /** The schema's JSON, as the pinned bytes read as UTF-8 text. */
  readonly sourceText: string;
  /** The names of the `$defs` to take, never the whole schema. */
  readonly slice: readonly string[];
};

What a JSON Schema import needs.

Titles, headings, exports, tables, columns and requirements. Esc closes.