dilswer
Version:
Blazingly fast data validation library with TypeScript integration.
45 lines (44 loc) • 2.24 kB
TypeScript
import type { AnyType, BasicType } from "../data-types/type-types";
import type { CustomType } from "../data-types/types/custom";
import type { InstanceOfType } from "../data-types/types/instance";
import type { JSONSchema6 } from "json-schema";
export type ParseToJsonSchemaOptions = {
/**
* Defines how to handle DataTypes that do not have an
* equivalent type in JSON Schema. (Set's, undefined, Symbols,
* etc.)
*
* - `throw` (default): Throw an error if an incompatible type is
* encountered.
* - `omit`: Omits incompatible properties from the JSON Schema.
* - `set-as-any`: Adds the type to the schema without a "type"
* property but with a name equivalent to the given
* DataType.
*
* @default "throw"
*/
incompatibleTypes?: "throw" | "omit" | "set-as-any";
/**
* Determines if the schemas generated for Record's should have
* additional properties set to `true` or `false`.
*/
additionalProperties?: boolean;
/**
* Custom Parser's are methods used to parse incompatible
* DataTypes to JSON Schema's.
*
* By default a strategy defined in `incompatibleTypes` is
* used, if a method is defined, that method will be used
* instead.
*/
customParser?: {
Set?: (setItemsSchemas: JSONSchema6[], original: Set<AnyType[]>, options: ParseToJsonSchemaOptions) => JSONSchema6 | undefined;
Custom?: (validateFunction: CustomType["custom"], original: CustomType, options: ParseToJsonSchemaOptions) => JSONSchema6 | undefined;
Undefined?: (dataType: BasicType, options: ParseToJsonSchemaOptions) => JSONSchema6 | undefined;
Symbol?: (dataType: BasicType, options: ParseToJsonSchemaOptions) => JSONSchema6 | undefined;
Function?: (dataType: BasicType, options: ParseToJsonSchemaOptions) => JSONSchema6 | undefined;
InstanceOf?: (original: InstanceOfType<new (...args: any[]) => any>, options: ParseToJsonSchemaOptions) => JSONSchema6 | undefined;
};
};
/** Translates given DataType into a JSON Schema. */
export declare const toJsonSchema: (type: AnyType, options?: ParseToJsonSchemaOptions, include$schemaProperty?: boolean) => JSONSchema6 | undefined;