diff --git a/lib/index.d.ts b/lib/index.d.ts index ad2af71..3dbc3ec 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -2,51 +2,51 @@ This is type definition for typescript. This is for library users. Thus, properties and methods for internal use is omitted. */ -export declare class Validator { +export declare class Validator> { constructor(); customFormats: CustomFormat[]; - schemas: {[id:string]: Schema}; + schemas: {[id:string]: Schema}; unresolvedRefs: string[]; - attributes: {[property:string]: CustomProperty}; + attributes: {[property:string]: CustomProperty}; - addSchema(schema?: Schema, uri?: string): Schema|void; - validate(instance: any, schema: Schema, options?: Options, ctx?: SchemaContext): ValidatorResult; + addSchema(schema?: S, uri?: string): S | void; + validate(instance: any, schema: S | string, options?: Options, ctx?: SchemaContext): ValidatorResult; } -export declare class ValidatorResult { - constructor(instance: any, schema: Schema, options: Options, ctx: SchemaContext) +export declare class ValidatorResult> { + constructor(instance: any, schema: S, options: Options, ctx: SchemaContext) instance: any; - schema: Schema; + schema: S; propertyPath: string; - errors: ValidationError[]; + errors: ValidationError[]; throwError: boolean; disableFormat: boolean; valid: boolean; - addError(detail:string|ErrorDetail): ValidationError; + addError(detail:string | ErrorDetail): ValidationError; toString(): string; } -export declare class ValidationError { - constructor(message?: string, instance?: any, schema?: Schema, propertyPath?: any, name?: string, argument?: any); +export declare class ValidationError> { + constructor(message?: string, instance?: any, schema?: S, propertyPath?: any, name?: string, argument?: any); property: string; message: string; - schema: string|Schema; + schema: string | S; instance: any; name: string; argument: any; toString(): string; } -export declare class SchemaError extends Error{ - constructor(msg: string, schema: Schema); - schema: Schema; +export declare class SchemaError> extends Error{ + constructor(msg: string, schema: S); + schema: S; message: string; } -export declare function validate(instance: any, schema: any, options?: Options): ValidatorResult +export declare function validate>(instance: any, schema: any, options?: Options): ValidatorResult -export interface Schema { +export interface Schema> { id?: string $schema?: string title?: string @@ -59,61 +59,62 @@ export interface Schema { maxLength?: number minLength?: number pattern?: string - additionalItems?: boolean | Schema - items?: Schema | Schema[] + additionalItems?: boolean | Schema + items?: Schema | Schema[] maxItems?: number minItems?: number uniqueItems?: boolean maxProperties?: number minProperties?: number required?: string[] - additionalProperties?: boolean | Schema + additionalProperties?: boolean | Schema definitions?: { - [name: string]: Schema + [name: string]: Schema } properties?: { - [name: string]: Schema + [name: string]: Schema } patternProperties?: { - [name: string]: Schema + [name: string]: Schema } dependencies?: { - [name: string]: Schema | string[] + [name: string]: Schema | string[] } 'enum'?: any[] type?: string | string[] - allOf?: Schema[] - anyOf?: Schema[] - oneOf?: Schema[] - not?: Schema + allOf?: Schema[] + anyOf?: Schema[] + oneOf?: Schema[] + not?: Schema } -export interface Options { +export interface Options> { skipAttributes?: string[]; allowUnknownAttributes?: boolean; - rewrite?: RewriteFunction; + rewrite?: RewriteFunction propertyName?: string; base?: string; + [option: string]: any; } -export interface RewriteFunction { - (instance: any, schema: Schema, options: Options, ctx: SchemaContext): any; +export interface RewriteFunction> { + (instance: any, schema?: S, options?: Options, ctx?: SchemaContext): any; } -export interface SchemaContext { - schema: Schema; - options: Options; +export interface SchemaContext> { + schema: S; + options: Options; propertyPath: string; base: string; - schemas: {[base:string]: Schema}; + schemas: {[base:string]: S}; } export interface CustomFormat { (input: any): boolean; } -export interface CustomProperty { - (instance: any, schema: Schema, options: Options, ctx: SchemaContext): string|ValidatorResult; +export interface CustomProperty> { + (instance: any, schema: S, options: Options, ctx: SchemaContext): string | ValidatorResult; } export interface ErrorDetail {