@fajarnugraha37/validator
Version:
A typed façade over [AJV](https://ajv.js.org/) that brings schema builders, caching, and loader pipelines to the `nope` workspace
72 lines (70 loc) • 2.76 kB
text/typescript
type JsonSchema = Record<string, any>;
type SchemaLike = JsonSchema | SchemaBuilder;
declare class SchemaBuilder<TSchema extends JsonSchema = JsonSchema> {
protected schema: JsonSchema;
protected constructor(initialSchema?: JsonSchema);
static create(schema?: JsonSchema): SchemaBuilder;
static object(): SchemaBuilder;
static array(): SchemaBuilder;
static string(): SchemaBuilder;
static number(): SchemaBuilder;
static integer(): SchemaBuilder;
static boolean(): SchemaBuilder;
static nil(): SchemaBuilder;
clone(): SchemaBuilder<TSchema>;
extend(schema: SchemaLike): this;
title(value: string): this;
description(value: string): this;
default(value: unknown): this;
examples(...values: unknown[]): this;
example(value: unknown): this;
const(value: unknown): this;
enum(values: unknown[]): this;
format(name: string): this;
$id(value: string): this;
$schema(value: string): this;
ref(pointer: string): this;
readOnly(value?: boolean): this;
writeOnly(value?: boolean): this;
nullable(value?: boolean): this;
type(value: string | string[]): this;
property(name: string, schema: SchemaLike, options?: {
required?: boolean;
}): this;
properties(entries: Record<string, SchemaLike>, options?: {
required?: (keyof typeof entries)[];
}): this;
required(...fields: string[]): this;
additionalProperties(value: boolean | SchemaLike): this;
patternProperty(pattern: string, schema: SchemaLike): this;
propertyNames(schema: SchemaLike): this;
minProperties(count: number): this;
maxProperties(count: number): this;
items(schema: SchemaLike): this;
prefixItems(...schemas: SchemaLike[]): this;
contains(schema: SchemaLike): this;
minItems(count: number): this;
maxItems(count: number): this;
uniqueItems(value?: boolean): this;
minLength(length: number): this;
maxLength(length: number): this;
pattern(regex: string): this;
minimum(value: number): this;
maximum(value: number): this;
exclusiveMinimum(value: number): this;
exclusiveMaximum(value: number): this;
multipleOf(value: number): this;
allOf(...schemas: SchemaLike[]): this;
anyOf(...schemas: SchemaLike[]): this;
oneOf(...schemas: SchemaLike[]): this;
not(schema: SchemaLike): this;
ifSchema(schema: SchemaLike): this;
thenSchema(schema: SchemaLike): this;
elseSchema(schema: SchemaLike): this;
definition(name: string, schema: SchemaLike): this;
definitions(entries: Record<string, SchemaLike>): this;
meta(key: string, value: unknown): this;
build(): TSchema;
toJSON(): TSchema;
}
export { type JsonSchema, SchemaBuilder, type SchemaLike };