Table of Contents generated with DocToc
- yup to swagger mapping (under each method, the effect of
yuptoswagger.js
is listed)yup
reach(schema: Schema, path: string, value?: object, context?: object): Schema
addMethod(schemaType: Schema, name: string, method: ()=> Schema): void
ref(path: string, options: { contextPrefix: string }): Ref
lazy((value: any) => Schema): Lazy
ValidationError(errors: string | Array<string>, value: any, path: string)
Schema
Schema.clone(): Schema
Schema.label(label: string): Schema
Schema.meta(metadata: object): Schema
Schema.describe(options?: ResolveOptions): SchemaDescription
Schema.concat(schema: Schema): Schema
Schema.validate(value: any, options?: object): Promise<InferType<Schema>, ValidationError>
Schema.validateSync(value: any, options?: object): InferType<Schema>
Schema.validateAt(path: string, value: any, options?: object): Promise<InferType<Schema>, ValidationError>
Schema.validateSyncAt(path: string, value: any, options?: object): InferType<Schema>
Schema.isValid(value: any, options?: object): Promise<boolean>
Schema.isValidSync(value: any, options?: object): boolean
Schema.cast(value: any, options = {}): InferType<Schema>
Schema.isType(value: any): value is InferType<Schema>
Schema.strict(enabled: boolean = false): Schema
Schema.strip(enabled: boolean = true): Schema
Schema.withMutation(builder: (current: Schema) => void): void
Schema.default(value: any): Schema
{ type: '..', default: value, ... }
Schema.getDefault(options?: object): Any
Schema.nullable(): Schema
{ type: '..', nullable: true, ... }
Schema.nonNullable(): Schema
removes nullable field
Schema.defined(): Schema
Schema.optional(): Schema
removes required field
Schema.required(message?: string | function): Schema
add's the field to 'required' array property if type is object
Schema.notRequired(): Schema
Alias:optional()
effectively reverses the above operation
Schema.typeError(message: string): Schema
Schema.oneOf(arrayOfValues: Array<any>, message?: string | function): Schema
Alias:equals
{ type: '..', enum: arrayOfValues, ... }
Schema.notOneOf(arrayOfValues: Array<any>, message?: string | function)
{ type: '..', not: { enum: arrayOfValues }, ... }
Schema.when(keys: string | string[], builder: object | (values: any[], schema) => Schema): Schema
Schema.test(name: string, message: string | function | any, test: function): Schema
Schema.test(options: object): Schema
Schema.transform((currentValue: any, originalValue: any) => any): Schema
- mixed
- string
string.required(message?: string | function): Schema
add's the field to 'required' array property if the string property is inside an object
string.length(limit: number | Ref, message?: string | function): Schema
{ type: '..', minLength: limit, maxLength: limit, ... }
string.min(limit: number | Ref, message?: string | function): Schema
{ type: '..', minLength: number, ... }
string.max(limit: number | Ref, message?: string | function): Schema
{ type: '..', maxLength: number, ... }
string.matches(regex: Regex, message?: string | function): Schema
{ type: '..', matches: regex, ... }
string.matches(regex: Regex, options: { message: string, excludeEmptyString: bool }): Schema
{ type: '..', matches: regex, ... }
string.email(message?: string | function): Schema
{ type: '..', format: 'email', ... }
string.url(message?: string | function): Schema
{ type: '..', format: 'url', ... }
string.uuid(message?: string | function): Schema
{ type: '..', format: 'uuid', ... }
string.ensure(): Schema
{ type: '..', default: '', ... }
string.trim(message?: string | function): Schema
string.lowercase(message?: string | function): Schema
string.uppercase(message?: string | function): Schema
- number
number.min(limit: number | Ref, message?: string | function): Schema
{ type: 'number', minimum: number, ... }
number.max(limit: number | Ref, message?: string | function): Schema
{ type: 'number', maximum: number, ... }
number.lessThan(max: number | Ref, message?: string | function): Schema
{ type: 'number', maximum: (number - 1), ... }
number.moreThan(min: number | Ref, message?: string | function): Schema
{ type: 'number', minimum: (number + 1), ... }
number.positive(message?: string | function): Schema
{ type: 'number', minimum: 1, ... }
number.negative(message?: string | function): Schema
{ type: 'number', maximum: -1, ... }
number.integer(message?: string | function): Schema
{ type: 'integer', maximum: -1, ... }
(type is changed)
number.truncate(): Schema
number.round(type: 'floor' | 'ceil' | 'trunc' | 'round' = 'round'): Schema
- boolean (inherits from Schema)
- date
date.min(limit: Date | string | Ref, message?: string | function): Schema
{ type: 'string', format: 'date', minLength: Date, ... }
- eg.
{"type":"string","format":"date","minLength":"1970-01-01T00:00:00.000Z"}
date.max(limit: Date | string | Ref, message?: string | function): Schema
{ type: 'string', format: 'date', maxLength: Date, ... }
- eg.
{"type":"string","format":"date","maxLength":"1970-01-01T00:00:00.000Z"}
- array
array.of(type: Schema): this
-> adds items property
array.json(): this
array.length(length: number | Ref, message?: string | function): this
{ type: 'array', minItems: number, maxItems: number }
array.min(limit: number | Ref, message?: string | function): this
{ type: 'array', minItems: number }
array.max(limit: number | Ref, message?: string | function): this
{ type: 'array', maxItems: number }
array.ensure(): this
{ type: 'array', default: [] }
- if on validation/cast a single non-array value is given, it wraps it in an array and is passed to default [ref]
array.compact(rejector: (value) => boolean): Schema
- tuple
yup.tuple()
->{"type":"array","items":{"oneOf":[{"type":"string"}]}}
yup.tuple([ yup.string(), yup.number() ])
->{"type":"array","items":{"oneOf":[{"type":"string"},{"type":"number"}]}}
- object
- Object schema defaults
object.shape(fields: object, noSortEdges?: Array<[string, string]>): Schema
object.json(): this
object.concat(schemaB: ObjectSchema): ObjectSchema
object.pick(keys: string[]): Schema
object.omit(keys: string[]): Schema
object.from(fromKey: string, toKey: string, alias: boolean = false): this
object.noUnknown(onlyKnownKeys: boolean = true, message?: string | function): Schema
object.camelCase(): Schema
object.constantCase(): Schema