UNPKG

data-to-jsonschema-to-ts

Version:

Convert plain javascript objects to JSON Schema and TypeScript typings

22 lines 1.3 kB
import { JsonSchema, ObjectType } from "./types.js"; export type JsonSchemaOptions = { /** Allow properties beyond those observed in the samples. Defaults to `false`. */ additionalProperties?: boolean; /** Fold a previously-generated schema into the merge as if it were another sample. Useful when widening a schema across runs. */ existingSchema?: JsonSchema & ObjectType; }; /** * Infer a JSON Schema (Draft-07) from an array of sample objects. * * Every sample is converted to an object type, then all samples are merged: * differing types for the same key become `oneOf`, array item types are * combined via `anyOf`, and `required` is the **intersection** of keys — * a property is only required if it appears in every sample. * * @param data - Sample objects to infer the schema from. Pass an empty array to get an empty object schema. * @param title - Title for the generated schema. Defaults to `"MySchema"`. * @param opts - Options controlling `additionalProperties` and an `existingSchema` to merge in. * @returns A JSON Schema describing the union of shapes seen across `data`. */ export declare function generateJsonSchemaFromData(data: Array<object>, title?: string, opts?: JsonSchemaOptions): JsonSchema & ObjectType; //# sourceMappingURL=schema.d.ts.map